Search the Community

Showing results for tags 'python'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News
    • New Users Introduction
    • Announcements
  • Digilent Technical Forums
    • FPGA
    • Test and Measurement
    • Measurement Computing (MCC)
    • Add-on Boards
    • Digilent Microcontroller Boards
    • Non-Digilent Microcontrollers
    • LabVIEW
    • FRC
    • Other
  • General Discussion
    • Project Vault
    • Learn
    • Suggestions & Feedback
    • Buy, Sell, Trade
    • Sales Questions
    • Off Topic
    • Educators
    • Technical Based Off-Topic Discussions
    • Archived

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 20 results

  1. Hey, @attila and anyone who can help me. I'm using Analog Discovery 2 to perform data acquisition through the two Oscilloscope channels and the 16 digital channels, using the AnalogIn_Record1.py and DigitalIn_Sync.py codes available in the SDK as a base. When executing the code most of the time I correctly get the number of samples I want according to the sampling rate and time, being the same for both digital and analog channels. In the code, I check the acquisition status and the program only exits the acquisition when the status of both (analog and digital) is completed. However, there are cases in which the acquisition is terminated, but there is a divergence between the number of samples obtained for analog and digital reading. Is this the correct and expected behavior? How should I go about solving this problem? Thanks for the help. For the tests I used the default acquisition configuration. As well as configuration 8. Below are some results: For the first setup: 1) cSamples Analog: 2000000 | cSamples Digital: 1967193 NO LOST ANALOG SAMPLES! Corrupted Analogs: 2210 NO LOST DIGITAL SAMPLES! Corrupted Digital: 4559 2) cSamples Analog: 12000000 | cSamples Digital: 11999912 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 3) cSamples Analog: 18000000| cSamples Digital: 18000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 4) cSamples Analog : 17991808 | cSamples Digital : 17987713 NO LOST ANALOG SAMPLES! Corrupted Analogs: 1074 NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 5) cSamples Analog : 17991808 | cSamples Digital : 17991809 NO LOST ANALOG SAMPLES! Corrupted Analogs: 120 NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 6) cSamples Analog : 35901696 | cSamples Digital : 35897601 NO LOST ANALOG SAMPLES! Corrupted Analogs: 10187 NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! For configuration 8: 1) cSamples Analog : 36000000 | cSamples Digital : 36000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 2) cSamples Analog : 4000000| cSamples Digital : 3999984 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 3) cSamples Analog : 71860736 | cSamples Digital : 72000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 4) cSamples Analog : 36000000 | cSamples Digital : 36000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! Corrupted Digital : 500 5) cSamples Analog : 71860736 | cSamples Digital : 72000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 6) cSamples Analog : 71967232 | cSamples Digital : 72000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! NOT CORRUPT DIGITAL SAMPLES! 7) cSamples Analog : 71983616 | cSamples Digital : 72000000 NO LOST ANALOG SAMPLES! NOT CORRUPT ANALOG SAMPLES! NO LOST DIGITAL SAMPLES! Corrupted Digital : 660 8) cSamples Analog: 3967232 | cSamples Digital: 4000000 NO LOST ANALOG SAMPLES! Corrupted Analogs: 9166 NO LOST DIGITAL SAMPLES! Corrupted Digital : 9716
  2. Hi, I'm using Analog Discovery 2 to perform data acquisition through the two channels of the Oscilloscope, using the AnalogIn_Record.py code available in the SDK as a base. I want to configure Oscilloscope channels with 2x16k buffers. And this way I want to get the Scope (2 x 16k) and Wavegen (2 x 1k) configuration, presented in the second line of the Waveforms Device Manager. By default the configuration is the one shown in the first line, Scope (2 x 8k) and Wavegen (2 x 4k). Studying the Waveforms SDK Reference Manual: the function FDwfAnalogOutDataInfo ( HDWF hdwf, int idxChannel, int *pnSamplesMin, double *pnSamplesMax) gives me the maximum buffer size information at 4096 samples for the output channels. The function FDwfAnalogInBufferSizeInfo (HDWF hdwf, int *pnSizeMin, int *pnSizeMax) tells me the maximum buffer size at 8192 samples for the Oscilloscope's input channels. The function FDwfAnalogInBufferSizeSet (HDWF hdwf, int nSize) should set the buffer size of the device's analog inputs. However, the function is ineffective, as any buffer value passed through this function is ignored and the device's default buffer size is used as the maximum buffer size. The function FDwfAnalogOutDataSet (HDWF hdwf, int idxChannel, double *rgdData, int cdData) should set the device's prefill buffer. However, the function is ineffective, as any buffer value passed through this function is ignored and the device's default size is used. How to properly configure device buffer sizes using the Python API? I want to configure Oscilloscope channels with 2x16k buffers. And this way I want to get the Scope (2 x 16k) and Wavegen (2 x 1k) configuration? Thanks in advance for your help.
  3. I've searched past content and I've been unable to find a complete answer on how to handle a "Device is busy" error message on an Analog Discover 2's. Setup: Raspberry Pi 4B 8GB RAM Raspberry Pi OS 32-bit (full version -- not headless, but without monitor) 128 GB fast SD-Card AD2 with USB connection to Raspberry Pi USB port (USB 3) AD2 powered separately There are three of these setups (Pi+AD2+Power+Network) operating remotely on the same network, with all communicating back to a central monitoring PC Hardware runs 24 hours/day, 7 days a week. AD2 is being used for: Waveform generation for an RF emitter ADC for incoming signals.Real-time operation. Real-time operation 100% Python3 script running AD2, network, and processing tasks Autostart (.desktop) launches script on bootup (due to chmod -x) The remote locations will occasionally and unexpectedly power cycle. There is no graceful closing of software or any devices when this happens. When this occurs, the application script will autostart when power is restored and the program tries to reconnect to all devices. (This includes re-establishing network connection back at the central command station PC.) The AD2 gives the device is busy error message on all 3 setups every time -- without exception. The script that launches the AD2 is the only script initiated at startup. I tried the attached script segment to capture errors and to attempt to timeout the condition. But it doesn't work. It will just keep looping and supply a continuous device is busy message. My patience only permitted me to watch this for 5 minutes, but I would assume it will be indefinite. You can see that much of this code comes straight out of the sample scripts that comes with installation of of the Waveform API. Currently the fix is to just restart the program. Doing so will automatically free up the device and the script will run properly Having the customer to kill the application and restart it is not ideal. Is there a solution for this? I suspect that perhaps this might be a previous state that is somehow stored or that the device is busy still booting itself while the script is launched. Unsure as to what may actually be happening, can someone help me? My apologizes for the novella, but I wanted to supply as much detail as possible. AD2 Startup Python Script
  4. Hello there, I need to log the 2 analog Channels simultaniously with a high Samplerate of ~6MS, everything triggered off the falling edge of DIO pin 6. (IQ channels of FMCW radar, triggered of the PLLs Chirp Start signal) I already managed to log Data on one channel using the 16k Buffer. Also Triggering on the second Channel as well as on the external Trigger worked. But I can not manage to trigger of an specific DIO pin. Everything in Python. 1. If I got the SDK right, I only need one hdwf device handle for the AD2, not one for the analog and one for the digital instrument? 2. Also with the Trigger Bus I should be able to trigger the Analog Instrument off the DigitalTriggerDetector? 3. So my understandig is that I set the AnalogIn Trigger Source to DetectorDigitalIn (Trigger Bus connection). All the settings for the Trigger itself condition/pin/PositionShift/... have then to be done under: FDwfDigitalInTrigger...() in the DigitalDtriggerDetectior, right? 4. If so I can not really see from the SDK and the Examples, what Fuctions I have to call to arm the DigitalTriggerDetector in Order to Trigger on the Falling Edge of DIO6. Please tell me the necessary functionsto do so!:) 5. And one more additional question: Does every Analog Channel have its own 16k buffer or is the buffer shared for both or even the Digial pins as well? And is there a more in depth documentation then the SDK and examples? Thanks in advance! I added the code below: from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy ####### Load the DWF, which forms the API between Python ond the C based Waveforms SDK ####### if sys.platform.startswith("win"): dwf = cdll.dwf elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") ######################################################################################### ########################## user definable parameters #################################### ######################################################################################### AcqHz = 100e6 # acquisitionHz / samplerate of ADC, max. 100MHz Samples = 2**14 # samples to collect after triggering, max. 2^14 samples ChlRange = 3.3 # set the +- Voltage range of AnalogIN Channel TrgPin = 6 # set the DIO Pin for the Trigger TrgLvl = 1.1 # set the voltage for the Trigger ######################################################################################### ######################################################################################### hdwf = c_int() # create datatype for hardware handle of AD2 sts = c_byte() # create datatype for later status request of acquisition nSamples = (c_double * Samples)() # create array for samples to be stored in ####### get the DWF Version provided by Digilent as an API between Python and the C based Waveforms SDK ####### version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("Digilent DWF (API) Version: " + str(version.value)) ####### opening the device ####### print("Opening first device") #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # 2nd configuration for Analog Discovery with 16k analog-in buffer dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1), byref(hdwf)) # open the AD2 and retrieve the handle if hdwf.value == hdwfNone.value: # if no device is found or the device is already in use szError = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szError); print("failed to open device\n" + str(szError.value)) quit() ####### set up acquisition ####### dwf.FDwfAnalogInFrequencySet(hdwf, c_double(AcqHz)) # set acquisition frequency dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(len(nSamples))) # set the buffer size for AnalogIn dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(ChlRange)) # set the Voltage range of AnalogIN Channel ####### set up trigger for the analog channel to be the DigitalInDetector ####### dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) # disable auto trigger at analog channel dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn) # set the triggger source for the analog channels to be the DigitalInTriggerDetector #dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcExternal1) # ExtTrg1 as Trigger Source ### settings for analogIn Trigger Detector ### ''' dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge) dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondFallingNegative) # <----------------- warum geht das nicht?? dwf.FDwfAnalogInTriggerChannelSet(hdwf, c_int(0)) # first channel dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(TrgLvl)) # trigger level 0.5V dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) # move trigger to left boundary, otherwise the signal will start in the middle #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(Samples/(2*AcqHz)))# Configures the horizontal trigger position in seconds. #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(4000/(2*AcqHz)))# Configures the horizontal trigger position in seconds. print("Trigger horizontal Position Set to: " +str(-Samples/(2*AcqHz)) + "sec. Left boundary of Buffer.") ''' ####### settings for the trigger on digital channel ####### #dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn - Sets the trigger source for the instrument. #dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(int(cSamples/2-1))) # Sets the number of samples to acquire after trigger. ## Configures the digital in trigger detector. ## #The logic for the trigger bits is: Low and High and (Rise or Fall). Setting a bit in both rise and fall will trigger on any #edge, any transition. For instance FDwfDigitalInTriggerInfo(hdwf, 0b0001, 2, 4, 8) will generate trigger when DIO-0 is low #and DIO-1 is high and DIO-2 is rising or DIO-3 is falling. The bits of the arguments represent pins. # FDwfDigitalInTriggerSet(HDWF hdwf, uint fsLevelLow, uint fsLevelHigh, uint fsEdgeRise, uint fsEdgeFall) dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<6)) # DIO6 falling edge - The bits of the arguments represent pins. ####### set up power supply ####### dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(3.3)) # set voltage to ... V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(-3.3)) # set voltage to -... V dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable ###### wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change ##### time.sleep(2) ####### get AnalogIN instrument in Ready state ####### print("Starting AnalogIN instrument. Waiting for trigger...") # FDwfAnalogInConfigure(hdwf, int fReconfigure, int fStart) dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, setfReconfigure to TRUE. ####### repeatedly check if acquisition has been made ####### while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value: # if so: acquisition completed, break while loop break time.sleep(0.001) # else: wait 1ms and check again ####### get the nSamples from the desired channel ####### dwf.FDwfAnalogInStatusData(hdwf, 0, nSamples, len(nSamples)) # get channel 1 data from buffer # dwf.FDwfAnalogInStatusData(hdwf, 1, nSamples, len(nSamples)) # get channel 2 data print("Data collected from AnalogIN buffer.") ####### close device and free handle ####### dwf.FDwfDeviceCloseAll() print("Device released.") ####### store data to .csv file ####### f = open("TriggeredRecord.csv", "w+") for value in nSamples: f.write("%s\n" % value) f.close() print("Data saved to .csv file.") ####### display data ####### plt.plot(numpy.fromiter(nSamples, dtype=numpy.double), 'bo-') # plot(x,y,style) plt.show()
  5. Dear Attila Please find enclosed the following . This took more than 4 hours to prepare all the documentation please treat as such. I am using the latest version of Digilent Waveforms and the latest Waveforms SDK. - Master Javascript driver for Digilent Analogue Discover AD2 which can be used inside Waveforms - SPI Setup , read & write & Initialise (1) . Status NOT Working . Needs Digilent Help to fix (%%) - I2C Setup , read & write & Initialise (2) . Status NOT Working . Needs Digilent Help to fix - UART Setup , read & write & Initialise(3) . ** - GPIO Setup, Set individual GPIO Pin Output States (4) Working - PSU Control, Set PSU voltage , turn on and off (5) Working - Python driver directly to control ON-SEMI CAT9532 using Digilent Analogue Discover AD2 & Digilent Waveforms ## Enclosed are all the attached scripts . ** Mostly likely works as driver details taken from working examples . See driver for while for web links reference. (%%) See previous efforts here to get it working &nbsp; &nbsp;https://forum.digilentinc.com/topic/21997-waveforms-with-accelerometer-digilent-analog-discovery-2-with-pmod-acl2-java-script-spi/#comment-63633 https://forum.digilentinc.com/topic/19237-waveforms-with-accelerometer/page/2/#comment-52495 I am trying to get the I2C driver function of the AD2 to work to drive a ON-SEMI CAT9532 LED driver. Set up , I have two Digilent Analogue Discover AD2 - Device 1 : Digilent AD2 (Device A) I2C driver source . A) Device is programed using Digilent Waveforms Javascript B) Direct control though Digilent Waveforms I2C Master interface C) Direct control though Digilent Waveforms I2C Master script interface D) Direct control Waveforms SDK & Python - Device 2 : Dilenet AD2 (Device B) as I2C spy device - Device 3 : TotalPhase Advark I2C/SPI professional I2C development tool Direct control & Programming by XML program script. https://www.totalphase.com/products/aardvark-i2cspi/ I own (2) two Analogue Discovery devices. What worked Device 2 : It could work perfectly as a I2C spy mode device Device 3: Worked perfectly straight out of the box using the GUI interface. Took 20 mins to have working solution. This is professional I2C product that has been in the market for 10 years plus. What failed Device 1: Did not output the correct I2C packet no mater how it was programmed. Device 1 : Had 10K pull up resistor attached to the VCC 3V3 rail on the I2C: SDA & I2C:SCL & I2C:/RESET. Conclusion There seems to be general issue with the AD2 and getting it to work as driver for I2C and SPI . Which is a long term issue. I have spent a long time searching for all the small details to build up the driver set so that should work with Digilent Analogue Discover AD2 & Digilent Waveforms but if the hardware of the AD2 is not co-operative or the staff in Digilent not being supportive there is only so much I can do . Requested Help 1. Fix the Waveforms AD2 Javascript and Python Waveforms SDK so it works for SPI & I2C . There is something missing here, where it would be good to fix to improved your AD2 products for the whole community of AD2 users 2. Have a Digilent published AD2 drivers that work for SPI & I2C & UART & GPIO & PSU control for waveforms and waveforms SDK. So Attila the case is in your lap now .. Please put some effort in to fix it or show me how to fix it . I have the feeling your quite a skilled person. The result should be posted here as a product example : https://projects.digilentinc.com/products/waveforms?sort=updated Background I am a electronic engineer with 20+ years development experience , I have have successfully used Digilent AD2 to design 3 products end to end and have been using it for quite a few years. I can program in Python , Microsoft VB.net and Javascript. I have personally purchased two pieces of AD2 out of my own money as feel they are such a good tool. I am committed to using the AD2 as I can see and experience that it is a super swiss army knife for use in a development of embedded electronics. I have also purchased a full profesional copy of National instruments Labview for use with AD2 but , have suspended learning to use labview until this I2C & SPI issue is resolved with the AD2 Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.py Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.js Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.dwf3work Digilent_AD2_Script_master.js
  6. Hi all, I am happy to announce version 1.0 of pydwf, a comprehensive Python package for using Digilent Waveforms devices from Python. The pydwf package is fully open source and released under an MIT license. On GitHub: https://github.com/sidneycadot/pydwf On PyPI: https://pypi.org/project/pydwf/ On Read The Docs: https://pydwf.readthedocs.io/en/latest/ (HTML and PDF) The package works from Python 3.6 onwards, on any platform supported by Digilent (Windows, Linux, macOS). Install it using pip3 like this: $ pip3 install pydwf The next step would be to look at the documentation, and perhaps run an example or two. Some features An easy-to-use, class-based API; Pretty comprehensive documentation (with improvements planned); Quite a few examples on how to use pydwf for some real-life applications; A cool logo :-) Alternatives Alternatives to pydwf exist, such as using Python's ctypes module directly (which is what the Python examples provided by Digilent do), and the older "dwf" package (https://pypi.org/project/dwf/). I think pydwf is a lot nicer to use than either of these, and I hope you will agree. Future work Most importantly, I want to keep up with new releases of the DWF C library as they come along. Next, I'd like to further improve the documentation, to include more information about what all the settings mean. The Digilent SDK is great, but its documentation does not go down to the nitty-gritty detail of explaining what each setting does precisely, which is something I miss. Through a combination of experimentation and asking on this forum, I hope to tackle this in the pydwf documentation. Lastly, I'd like to provide more examples, e.g. to clearly explain the correct way to use the different acquisition modes of the AnalogIn and DigitalIn instruments, to demonstrate the powerful but complex possibilities of analog and digital triggering, and so on. Feedback Please let me know if you use the pydwf package, if you're happy with it (or not), and if there's anything you want to see improved. To report specific issues, please use the GitHub issue tracker. I spent quite a bit of time on all of this over the past few years; three months ago I decided to bite the bullet and aim for a proper public release with documentation, examples, and all that. There are certainly areas where improvement is still possible, but as of now I think the package is of sufficient quality to be useful to people other than myself. I hope the work will prove useful to some of you! Best, Sidney
  7. Are there any differences between Python and C++ version of WaveForms SDK API functions with respect to execution time of the functions?
  8. What is the good method transfering the eight bits via SPI to DPOT using a raspberry pi? spi.writebytes accepts int arrays only. many thnaks
  9. I am programming a Digital Discovery with WaveForms SDK (in Python) to communicate via SPI with an FPGA. The SPI comunication has 16 bit words. First, I have to send the address to read or write (the first bit of the 16 bit word indicates whether it is a read 0 or a write 1). Then, in the second 16 bit word, I read the data if it was a read operation, or I send the data if it was a write operation. I have the following code: # Imports from ctypes import * from dwfconstants import * import sys import time # Load dwf library if sys.platform.startswith("win"): dwf = cdll.LoadLibrary("dwf.dll") elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") # Open the Digital Discovery device hdwfDD = c_int() dwf.FDwfDeviceOpen(c_int(-1), byref(hdwfDD)) # Configure digital voltage to 1.8 V and system frequency to 100 MHz dwf.FDwfAnalogIOChannelNodeSet(hdwfDD, c_int(0), c_int(0), c_double(1.8)) dwf.FDwfAnalogIOChannelNodeSet(hdwfDD, c_int(0), c_int(6), c_double(100e6)) dwf.FDwfAnalogIOEnableSet(hdwfDD, c_int(True)) # Configure SPI dwf.FDwfDigitalSpiFrequencySet(hdwfDD, c_double(1e6)) # 1 MHz dwf.FDwfDigitalSpiClockSet(hdwfDD, c_int(4)) dwf.FDwfDigitalSpiDataSet(hdwfDD, c_int(0), c_int(6)) # MOSI dwf.FDwfDigitalSpiDataSet(hdwfDD, c_int(1), c_int(15)) # MISO dwf.FDwfDigitalSpiModeSet(hdwfDD, c_int(0 | (0 << 1))) # Polarity 0; Phase 0 dwf.FDwfDigitalSpiOrderSet(hdwfDD, c_int(0)) # LSB # Configure the address 1 to value 5000 time.sleep(200e-6) dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(0x8000 | 1)) time.sleep(200e-6) dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(5000)) # Read the value in address 1 to check if data has been set correctly time.sleep(200e-6) dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(1)) time.sleep(200e-6) rxData = c_int() dwf.FDwfDigitalSpiReadOne(hdwfDD, c_int(1), c_int(16), byref(rxData)) All the dwf functions return 1 (including dwf.FDwfDigitalSpiWriteOne). I have also checked that the SPI writes are working with an oscilloscope. The problem is with the function dwf.FDwfDigitalSpiReadOne, that returns 0. What does this mean? Besides, when this function is executed, the Digital Discovery turns on a blue LED. What is the meaning of this blue LED? I have run the following code after the unsuccessful DigitalSpiReadOne trying to obtain an error message: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) # Prints: b'' But nothing is printed. I want to add that the same SPI configuration works perfectly in an Analog Discovery 2. The problem is I want the SPI to work at 1.8 V, and as far as I know, the Analog Discovery 2 only works at 3.3 V.
  10. Hi, I'm running into an issue when using Python3 with Analog Discovery 2 on Ubuntu 20.04 LTS box. Platform: AD2 on Ubuntu 20.04 LTS. Here is a dump for a small 'enumerate' script used to identify the device and software, let me know if you need anything else. FTDI Version: 0x10408 Devices: 1 1: SN: b'210321A36017' : b'Digilent USB Device' Flags: 0x2 Type: 0x8 ID: 0x4036014 Loc ID: 0x10c DMGR Version: b'2.9.3' Devices: 1 1: SN: b'SN:210321A36017' : b'Analog Discovery 2' PDID: 0x40300360 DWF Version: b'3.14.3' Devices: 1 1: SN: b'SN:210321A36017' : b'Analog Discovery 2' Goal: I am using the AD2 to interface with an IMU. The IMU has a 'Data Ready' signal. The desired outcome would be that I can initiate a SPI read when the 'Data Ready' signal goes low. Perhaps this isn't the right way to do this but I configured the logic analyzer tool to tell me when the 'Data Ready' line goes low. To exercise this I use the pattern generate to toggle a pin and then trigger off of that signal in the logic analyzer, much like the example script does. Problem: If I perform the steps above (configure and run a pattern generator with a toggling waveform and use the logic analyzer to capture it) everything works fine and I get a status of '2' (Done) If I then configure the SPI tool, specifically the chip select signal, the logic analyzer doesn't work anymore, I keep getting a status of '1' (Arm) after the SPI device is running. Here is the output I get >$ ./digital_in_strange_test.py Opening first device Waiting for acquisition... Status: 2 done Configuring SPI Device Waiting for acquisition... Status: 1 Status: 1 Status: 1 Status: 1 Error I've played around with it for a bit but I haven't figured it out, sometimes instead of showing state '1' (Arm) it shows state '3' (Trig). I'm not sure but I think this might happen when I actually toggle the select signal. Here is the script that will demonstrate the issue: #! /usr/bin/env python3 from ctypes import * from dwfconstants import * import math import sys import time import numpy if sys.platform.startswith("win"): dwf = cdll.LoadLibrary("dwf.dll") elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") hdwf = c_int() sts = c_byte() print("Opening first device") #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # device configuration of index 3 (4th) for Analog Discovery has 16kS digital-in/out buffer TEST_OUT = 7 if __name__ == "__main__": #dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(3), byref(hdwf)) dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == 0: print("failed to open device") szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() ''' Use the Pattern Generator to toggle pin 7''' # generate counter dwf.FDwfDigitalOutEnableSet(hdwf, c_int(TEST_OUT), c_int(1)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(TEST_OUT), c_int(1<<2)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(TEST_OUT), c_int(1), c_int(1)) dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) ''' Configure the Logic Analyzer to capture Pin 7''' cSamples = 8 rgbSamples = (c_ubyte*cSamples)() dwf.FDwfDigitalInReset(hdwf) dwf.FDwfDigitalInInputOrderSet(hdwf, c_int(1)) # with 8 bits DIO-0:7 dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(8)) # set number of sample to acquire dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples)) dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn #dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn) #dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(int(cSamples/2-1))) dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(0)) dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(1<<TEST_OUT), c_int(0)) # DIO7 falling edge # begin acquisition dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) print("Waiting for acquisition...") count = 0 while count < 4: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) print("Status:", str(sts.value)) if sts.value == 2 : # done break time.sleep(1) count += 1 if sts.value != 2: print ("Error") else: print(" done") ''' Enable SPI Device ''' print ("Configuring SPI Device") SPI_FREQ = 1e6 #SPI_FREQ = 1e3 SPI_SEL = 1 SPI_SCLK = 0 SPI_MOSI = 3 SPI_MISO = 2 SPI_MODE = 3 SPI_MSB_FIRST = 1 dwf.FDwfDigitalSpiReset(hdwf) dwf.FDwfDigitalSpiFrequencySet(hdwf, c_double(SPI_FREQ)) dwf.FDwfDigitalSpiClockSet(hdwf, c_int(SPI_SCLK)) dwf.FDwfDigitalSpiDataSet(hdwf, c_int(0), c_int(SPI_MOSI)) # 0 DQ0_MOSI_SISO = DIO-2 (SPI_MOSI) dwf.FDwfDigitalSpiDataSet(hdwf, c_int(1), c_int(SPI_MISO)) # 1 DQ1_MISO = DIO-3 (SPI_MISO) dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(2), c_int(3)) # 0 DQ0_MOSI_SISO = DwfDigitalOutIdleZet dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(3), c_int(3)) # 1 DQ1_MISO = DwfDigitalOutIdleZet dwf.FDwfDigitalSpiModeSet(hdwf, c_int(SPI_MODE)) dwf.FDwfDigitalSpiOrderSet(hdwf, c_int(SPI_MSB_FIRST)) # 1 MSB first dwf.FDwfDigitalSpiSelect(hdwf, c_int(SPI_SEL), c_int(1)) # CS DIO-1 high (SPI_SEL) # begin acquisition dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) print("Waiting for acquisition...") count = 0 while count < 4: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) print("Status:", str(sts.value)) if sts.value == 2 : # done break time.sleep(1) count += 1 if sts.value != 2: print ("Error") else: print(" done") dwf.FDwfDeviceCloseAll() Perhaps I'm missing something. Thanks for any help. Dave
  11. I'm trying to output a custom digital waveform that is a frequency modulated bit stream. The basic scheme is as follows: 1. Preamble: frequency starts out at 10KHz for 400 cycles After 2. for a 1 bit, send 20 13KHz cycles, followed by 20 10KHz cycles 3. for a 0 bit, send 10 6KHz cycles, followed by 20 10KHz cycles 4. Postable: frequency runs at 10KHz for 400 Cycles. I can generate the signal with python but I seem to be running into bitstream length issue. The moment the data gets over 1024 "bits" (actual bits, not the frequency modulated ones), the signal is not generated. My code is below but it's modified to only send 1024 bits. My second issue is that when this pattern works, it repeats. I would like it to run only once. I tried a few things found in forums but there's no documentation for the python interface. from ctypes import * from dwfconstants import * import sys import time if sys.platform.startswith("win"): dwf = cdll.dwf elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") hdwf = c_int() version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("DWF Version: "+str(version.value)) print("Opening first device") dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == 0: print("failed to open device") szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() print("Configuring Digital Out") hzSys = c_double() dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys)) data_one_wave = [1,1,1,0,0,0] data_zero_wave = [1,1,1,1,1,1,0,0,0,0,0,0] data_amble_wave = [1,1,1,1,0,0,0,0] data_preamble = data_amble_wave * 4 data_zero_bit = (data_zero_wave * 2) + (data_amble_wave * 3) data_one_bit = (data_one_wave * 4) + (data_amble_wave * 3) data_postamble = data_preamble # Message with short preamble, 07, 1000, 07, short postamble data_to_send = data_preamble \ + data_zero_bit + data_zero_bit + data_zero_bit + data_one_bit \ \ + data_zero_bit + data_zero_bit + data_one_bit + data_one_bit \ + data_one_bit + data_one_bit + data_one_bit + data_zero_bit \ + data_one_bit + data_zero_bit + data_zero_bit + data_zero_bit \ \ + data_zero_bit + data_zero_bit + data_zero_bit + data_one_bit \ + data_postamble time_to_sleep = 5 # Message with just preamble - 10KHz # data_to_send = data_preamble # time_to_sleep = 3 print("Sending " + str(len(data_to_send)) + " bit of data") data_py = data_to_send # how many bytes we need to fit this many bits, (+7)/8 rgbdata=(c_ubyte*((len(data_py)+7)>>3))(0) # array to bits in byte array for i in range(len(data_py)): if data_py[i] != 0: rgbdata[i>>3] |= 1<<(i&7) pin=0 # generate pattern dwf.FDwfDigitalOutEnableSet(hdwf, c_int(pin), c_int(1)) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(0), DwfDigitalOutIdleHigh) dwf.FDwfDigitalOutTypeSet(hdwf, c_int(pin), DwfDigitalOutTypeCustom) # 80kHz sample rate dwf.FDwfDigitalOutDividerSet(hdwf, c_int(pin), c_int(int(hzSys.value/80e3))) # set sample rate dwf.FDwfDigitalOutDataSet(hdwf, c_int(pin), byref(rgbdata), c_int(len(data_py))) # This doesn't seem to work. dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(1)) # repeat once print("Generating pattern...") dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) time.sleep(time_to_sleep) dwf.FDwfDigitalOutReset(hdwf) dwf.FDwfDeviceCloseAll() If I bump any of the "multipliers on the data_preamble or similar variables to make a longer stream, the output doesn't get generated. I'm basically using a "common denominator" clock that can handle all 3 frequencies and mapping the 1s and 0s as needed. If there's a better way to do this, I'm all ears. The only requirement is that the control of the number of cycles must be exact. Can you help?
  12. Hi , Does it possible to implement Python code on ARTY 7 board using Vivado HLS? If it is not, why it is possible with PYNQ board? Thanks
  13. Hi, I am writing a python script to output patterns on my digital discovery. I need to have a reset at 0 during 100ns on DIO24=channel 0, then 20000pattern that are repeated. But I do not want to repeat the reset. I have tried many commands of the SDK ref manual, including Reset = 0 dwf.FDwfDigitalOutRepeatTriggerSet(hdwf, c_int(Resetn), c_int(1)) # repeat = false But, no way the reset is always repeated. How to proceed ? BRgds, Laurent
  14. Hi,guys! I'm currently working on how to send character"hello" to FPGA and then transmit "hello" back to my PC. But it seems I only can send some characters to my board and cannot receive the chracters back to PC. I wonder how to build my code in python to get the characters back to my PC. The attachment is my code(PYTHON) and result of runing. import serial ser = serial.Serial("com9",9600,timeout=0.25) print(ser.name) print(ser.port) #ser.open() c=input("hello") b=ser.isOpen() s=ser.read(10) ser.write(c.encode()) print(s) print(b) ser.close() Thanks, Dehao
  15. Hi there, Until here, I've done quite a few things, with the magnificient help of attila. I've done a lot a threads that can use the AD2 to record the analog inputs, or the digital inputs, that can configure the analog outputs or the digital outputs. When I run all of those threads together, it works perfectly fine (except for the tick of my PC, that doesn't allow me to be really fast with the digital outputs, but it's not a big problem for the moment). And then, the UART appeared. I have to say, it works great. The problem is with the UART and the digital outputs. When both are asked (for example logic '1' to DIO 0 and send "This is just a simple test to know if everything works fine" on the Tx at the <<same>> time, the DIO will wait for the end of the UART Transmit). I've tested with with another configuration for the digital output (pulse at 1kHz), and the AD2 stops the pulse when the UART appears. Is it normal or do I do something wrong? Thanks for your help Marc
  16. Hello Digilent Forums, I have an Analog Discovery 2 + Impedance Analyzer board, and have been programmatically manipulating the board via the DWF library. I am now trying to plot Input Phase (∠) programmatically. The SDK for Python comes with a `dwfconstants.py`, which houses values of `c_int()`, corresponding with various measurement types. For example, `DwfAnalogImpedanceImpedance` measurement type corresponds to `c_int(0)`. I do not see a constant for Input Phase inside `dwfconstants.py`. Is it possible to get Input Phase? Thank you in advance for your help!
  17. Greetings, Forgive me, but I'm not that knowledgeable in python and I'm having trouble understanding the "create_string_buffer" argument in the Digital_UART.py sample code. How do you declare this "create_string_buffer" statement into its VB6 equivalent? Sincerely yours, Lesiastas
  18. Hello Digilent Forums, I am trying to write a Python script for the impedance analyzer. I am reading the WaveForms SDK and following examples. I noticed all methods in the examples that use the dwf (Ex: `dwf.FDwfDeviceOpen`) use positional arguments. In the SDK, it lists the parameter names/types for the method (Ex: `FDwfDeviceOpen(int idxDevice, HDWF *phdwf)`). I have tried and failed to figure out how to specify them using keyword arguments instead. Is it possible? Thank you in advance for your help!
  19. Hello, I'm using the AD2 and would like to use Python to play an imported signal of arbitrary length (like in the function AnalogOut_Play) while at the same time acquiring data (like in the function AnalogIn_Record). Is there a straightforward way of combining these two functions?
  20. Hi, I combined a few python scripts from the SDK (AnalogIn_Acquisition, AnalogOut_Play and AnalogOut_Sine) to write a script which is intended to run during the night and save the scope's data into a WAV file. All looks somewhat okay, but there are a few things that don't look perfect. For this test, I connected CH1 and W1 and started both the Scope and Signal generator in the script. I'm intending to generate a 80 Hz sine wave and record it with the scope running at 8 kHz. I attach the whole script, and here are the important parts: # set up signal generation channel = c_int(0) # use W1 dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_bool(True)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcSine) # ! this looks like a square wave dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(signalgenhz)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.41)) # ! this doesn't really do anything dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.41)) I played around with the parameters and after some investigation with Audacity it seems like the funcSine parameter generates a square wave and the amplitude is always 1.0 no matter what I set. The other problem I have is with the FDwfAnalogInStatusData function, it looks like it doesn't just get the raw data from the scope, is contains something else. So in order to get the scope's CH1 data, I need to have a 2-channel WAV file, and discard its first channel. The second is the data I'm looking for. waveWrite = wave.open(startfilename, "wb"); waveWrite.setnchannels(2); # 2 channels for the testing (1 channel would be enough if FDwfAnalogInStatusData returned only 1 channel's data waveWrite.setsampwidth(4); # 32 bit / sample waveWrite.setframerate(samplerate); waveWrite.setcomptype("NONE","No compression"); dwf.FDwfAnalogInStatusData(hdwf, 0, rgdSamples, buffersize) # get channel 1 data CH1 - ! it looks like 2 channels get read here and only the second is the data of CH1 waveWrite.writeframes(rgdSamples); I would expect that if I only need the CH1 of the Scope, I could save it into a mono WAV file. AnalogIn_AcquisitionSaveToWAV.py