Adam1973
-
Posts
30 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Gallery
Posts posted by Adam1973
-
-
-
Hope everyone is well. I need some help getting my I/O to work when using SPI. Here is what I am trying to do.
I have 10 SPI controlled 8 channel switches, each of which has a chip select line which is active low. I also have three relays which need to be switched on at the start of the programme.
So my chip select lines are using I/O channels 1-10, SPI data is on I/O 0, Clock is on I/O 11 and relays are using I/O 12, 13 and 14.
I want to set all CS lines high at power on and set all relays on. I have a routine called set_io where I set all CS lines and relay lines high, I then thought when running the SPI routine, it would just use the relevant DIN, CLK, and CS mapped out in this routine. Well it stops the SPI working? Anyone know how to get over this issue?
Note: The SPI works fine when the set_io routine is not used.
Many thanks
Adam
-
-
Thanks Attila. Let me try that and I will report back with any issues.
Thanks
Adam
-
Hi all. Hope you are all well and having a nice weekend. Can someone please help me?
I am trying to loop through a list which has different hex value and then send them to the SPI routine. The routine works fine if I add the data manually as hex 0x80 for example. When I try and send SPI from the list it is not working, the data output on a scope stays the same. If I print the list values they are printed as decimals. I want to change the hex value to be sent from the list and not enter it manually. I have tried converting the variable HEX_VAL to hex but not sure if I am doing this correctly as it then complains about being a str. Everything is setup as an int as far as I can see and I have declared HEX_VAL at the top of the code as an int.
Any help will be much appreciated. I have attached a screen shot so you can see the code.
Thanks
Adam
-
-
Hello Attila. Ah that might be the issue :) I did download waveforms only the other day but cannot see the FFT py. Let me download the version above.
Thanks
Adam
-
Thanks Jeffrey :)
-
Hi Attila. Thanks for the link to the thread about frequency measurements. I thought I would have a look but it won't run, I get this error:
Traceback (most recent call last): File "C:\Users\450362\Documents\AnalogIn_FFT.py", line 99, in <module> dwf.FDwfSpectrumWindow(byref(rgdWindow), c_int(nSamples), DwfWindowFlatTop, vBeta, byref(vNEBW)) File "C:\Users\450362\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 387, in __getattr__ func = self.__getitem__(name) File "C:\Users\450362\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 392, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'FDwfSpectrumWindow' not found
-
Hi all. Does anyone know if Digilent or any other company offer an annual calibration service for the Digilent ADP5250?
Many thanks Adam
-
Hi Sidney. Yes I want to power up the device and set it's power supplies and switch a few IO on for some relay control first. I'll give that a go :)
Thanks
Adam
-
Hi Sidney
It's brilliant :) One question if I may. I want to power on the device at the start of my code because I want to set up other parts before I measure the frequency. I see in the code you have
dwf = DwfLibrary()
with openDwfDevice(dwf) as device:
The code uses with statement with reference to device.analogIn. How do I get to power the device up at the start without messing up the code?
Cheers
Adam
-
The printing to file works a treat.... you are amazing :)
Thanks
Adam
-
Thanks Sidney. I still get the error but it's OK as all I want is the frequency.
Thanks ever so much for your help
Adam
-
Hi Sidney. The code starts to run but I am getting some errors. I have installed matplotlib but something is not working. Any ideas?
Thanks
Adam
Traceback (most recent call last): File "C:\Users\arous\AppData\Local\Programs\Python\frequency_estimation.py", line 102, in <module> main() File "C:\Users\arous\AppData\Local\Programs\Python\frequency_estimation.py", line 77, in main plt.subplots_adjust(hspace=0.5) File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 2253, in subplots_adjust return gcf().subplots_adjust( File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 832, in gcf return figure() File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper return func(*args, **kwargs) File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 773, in figure manager = new_figure_manager( File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 348, in new_figure_manager _warn_if_gui_out_of_main_thread() File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 338, in _warn_if_gui_out_of_main_thread if (_get_required_interactive_framework(_get_backend_mod()) and File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 207, in _get_backend_mod switch_backend(dict.__getitem__(rcParams, "backend")) File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 252, in switch_backend switch_backend(candidate) File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 265, in switch_backend backend_mod = importlib.import_module( File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in <module> from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\backends\backend_qt.py", line 72, in <module> _MODIFIER_KEYS = [ File "C:\Users\arous\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\backends\backend_qt.py", line 73, in <listcomp> (_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)), TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'
-
Hi Sidney. Just looking at the code now and I have a noob question. If I want to write the measured frequency to a file to display it as say 50 Hz, where do I get this information from?
Thanks
Adam
-
Bloody hell Sidney :) That looks amazing. I am just about to finish for the day so will look at this later this evening.
Thanks again for your help.
Adam
-
You are a star Sidney.
Thanks Adam
-
50 Hz ish
-
Hi Sidney
Possibly a tad over complicated :) I just need to measure the frequency to within +/- 1 Hz. I was thinking of zero crossing detection but not sure how to interrogate the sample file which would hold all the data.
Thanks
Adam
-
Hi all. Hope you are all well.
Has anyone measured the frequency of a sine wave using the scope function of the AD2? Any help and guidance would be much appreciated. I have also looked at the impedance analyser option but I cannot see how to get a frequency measurement from the functions.
Many thanks Adam
-
Thanks Sidney. I like pydwf so I think I am going to use that from now on. I started using the Digilent way because I didn't know much better at the time.
Thanks again for the help
Adam
-
Ah I just found it :) The voltage is on W1 of the analog discovery 2. It works :) Another question please. Do you have examples of controlling the power supplies and static IO. I have functions which work but when I call them from within the class It does not seem to work.
def set_psu(v1,v2):
# set up analog IO channel nodes # enable positive supply
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # set voltage to 5 V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(v1)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True)) # set voltage to -5 V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(v2)) # master enable
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))
print ("Setting PSU")
return
def set_io(): # Turn on IO pins
# Open device
# enable output/mask on 4 LSB IO pins, from DIO 0 to 3
dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x000F)) # set value on enabled IO pins
#dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x20)) # IO 5 on
time.sleep(2)
dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x04)) # IO 2 on
time.sleep(2)
#dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x08)) # IO 3 on
#time.sleep(2)
#dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x00)) # all IO Off
print ("Setting IO")
time.sleep(2)
#dwf.FDwfDeviceCloseAll()
return
-
Hi Sidney. Hope all is well. I have had a look at the code you sent and it runs but when I get measurement I am expecting 1.5 V yes? I get pretty much 0 V. Also you talk about first analog in and out channels. Are these the power supplies and scope channels respectively?
Thanks
Adam
AD2 setting digital I/O and using SPI
in Test and Measurement
Posted
Hi again. Using the SPIselect as relay control worked :) Thanks a lot Adam.