• Content Count

  • Joined

  • Last visited

Everything posted by spri

  1. I have been using the AnalogDiscovery2 with a custom python application built with the SDK to provide synchronous control to several lab instruments. I recently discovered that at certain sample rates, my signals aren't actually synchronized. I've stared at the code for two days and can't find my error, so I'm reaching out for help! The Q-clock runs at frequency that is an integer multiple of the X-clock. In most cases, the two clocks remain synchronized indefinitely. However, at some frequencies, the Q-clock starts synchronized but begins to drift with respect to the X-clock, so after a few seconds they are no longer synchronized. I thought this might be due to a rounding issue when using a frequency by which the system clock isn't divisible (ie, at 30hz a remainder gets cut off and the clock gets 'off' by 1/3ms every cycle). However, I don't have this issue at other non-divisible frequencies (like 60, 150 and 300 hz). Here is the code in question: ##Qclock #normal low with high pulses at qrate = n*xrate where n is an int dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1)) # enable dIO pin 1 dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(int(hzSys.value/(100*qrate)))) # divider=internal clock/ (100counts*frequency) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(1), DwfDigitalOutIdleLow) #set idle to low dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_int(int(100-qcount)), c_int(qcount))) # set counts low, counts high dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(1), c_int(1), c_int(0)) #pin1, start HIGH, initial counter = 0 ##Xclock #normal low with high pulses at xrate dwf.FDwfDigitalOutEnableSet(hdwf, c_int(2), c_int(1)) # enable dIO pin 2 dwf.FDwfDigitalOutDividerSet(hdwf, c_int(2), c_int(int(hzSys.value/(100*xrate)))) # divider=internal clock/ (100counts*frequency) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(2), DwfDigitalOutIdleLow) #set idle to low dwf.FDwfDigitalOutCounterSet(hdwf, c_int(2), c_int(int(100-xcount)), c_int(xcount)) # set counts low, counts high from duty cycle dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(2), c_int(1), c_int(0)) #pin2, start high, initial counter = 0 Here is a picture of the external oscilloscope showing the 'drift' between the signals after running for a few seconds: (blue =Qclock at 60hz, yellow=Xclock at 30hz), the rising edges of every other blue pulse should line up with the yellow ones. Again, this only happens at certain frequencies. Most of the time (at nice, even numbers) everything lines up perfectly. Any help would be appreciated! Thanks!
  2. After spending more time digging around on this, I discovered that this is an issue with residual files in the pycache after a python version update, and has nothing to do with the WaveForms SDK. If anyone else encounters this error, clear the cache and see this post for more details: https://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error>
  3. I just updated Python from version to 3.7.3 (a big jump, I know... but it was time). Now, when I try to run an application I created using the WaveForms SDK, I get the error, from dwfconstants import * ImportError: bad magic number in 'dwfconstants': b'\x03\xf3\r\n' I just updated WaveForms, and the error persists. What does it mean? How do I fix it?
  4. Thank you, that worked perfectly! But, I'm a little confused still as to why my solution didn't work. When using -1 to configure the master run time, does that override individual channel settings on the wait time?
  5. Thanks for that pointer, but I had already tried that - when I replace the AnalogOutWaitSet with these two lines of code, both channels trigger at the same time using whatever delay period is specified for channel 0. Is there some additional argument (node?) which is required to make this work when using the SDK and not the Waveforms software?
  6. I am trying to create two square wave signals on the AD2 Analog instrument. Both signals should start at 5v, one should drop to 0v at the trigger, and the other should go to 0v after a certain delay time after the trigger (delay time = self.d/1000). Both signals should return to 5v at the same time (end of RunSet). I think I have to do this using the 'funcCustom' output, at least for the delayed signal. However, I am not able to get the funcCustom signal to give me the desired output. It just outputs 5v constantly after the trigger signal. (The funcSquare signal does what is expected). Is there an easier way to create this delay between two analog channels without using funcCustom? Or is there something wrong in my syntax for getting the funcCustom signal to work? Thank you!
  7. Thanks @attila. I did not think to use funcSquare to create a DC offset for a specified duration.
  8. I am trying to do something similar, with an idle offset value and then switch to a different DC offset value after a trigger. However, with the code below, I am getting the FuncDC/NodeOffset value immediately when I configure the channel, instead of the idle value prior to the trigger. It only goes to the idle value after the RunSet duration. Could you please explain how to get it to idle at a low value prior to the trigger?
  9. For the analog discovery 2 SDK, when using the AnalogOutWaitSet command, is there a function which will tell me how long until the trigger/device start? I am looking for something similar to AnalogOutRunStatus, but which will tell me the remaining wait time. Thank you.
  10. Thanks, this helps a lot with the pulsed outputs. Is it possible to also do this with the Constant output-type also? For example, in the setup below I want DIO-2 to switch from idle to constant at t=30ms (20ms delay after the 10ms wait-set), but there are obviously not options for the counter-init and divider-init for this output type. I am ultimately interested in doing this within the python sdk, not in waveforms (but waveforms is a good place to start to visualize what I'm doing). In the SDK and dwf.h file it is also not clear how to set the output type to PP+constant or control the FSM/value -- how do I do that?
  11. On the Discovery2, is it possible to set a different trigger wait-set (Analog/ DigitalOutWaitSet) for each individual channel index, rather than one trigger delay for the whole instrument?
  12. Apologies for asking dumb questions, but that table is definitely not in the version of the SDK reference manual I have been using. I'm using the May 8 2017 version -- is there an update, or is this from an older version and somehow got cut? My version doesn't even have a section 11.3...
  13. Waveforms allows the user to turn the power supplies on and off, and set the voltage for the Analog Discovery 2. How do you do this with the SDK? Also, what is the default setting? I cannot find anything in the documentation. Thanks!
  14. I am using an external trigger pulse to start outputs on AnalogOut and DigitalOut pins using the python SDK. The Trigger Pins on the AD2 are so sensitive that they interpret slight jostles of the wire as a trigger pulse -- so my outputs start unexpectedly. There are functions to qualify the trigger on AnalogIn (hysterisis, lengthcondition, etc) to wait for the right signal -- how do I do something similar for the Analog and Digital Out Triggers (because they seem to only have SlopeSet functions)? Also, is it possible to have the same external trigger line act as both a 'Start' and 'Stop' for a pin?
  15. Hi @jpeyron, I've been struggling to get my alternate implementation to do everything it needs to do. So, I am revisiting this idea. An answer to the original question would be most helpful! Thanks!
  16. One more question, for clarification: why do you use (1<<5) and not (0<<5) to disable the pin?
  17. Thank you for that clarification -- your solution works. You may want to emphasize the D-Out and D-IO prioritization and function in future versions the SDK reference manual -- since many of those commands take a channel index as an argument, it seemed logical that they would only apply to the specified channel(s).
  18. I have built a fairly involved GUI which allows user control of multiple analog and digital output signals on the AD2 with various triggers, timers, and on/off toggles controlling multiple systems. When I try to turn off pulses on a SINGLE digital pin using the DigitalOutOutputSet command, ALL the digital pins switch to zero. But, I need the rest of them to keep running. This section of my code is trivial -- there's not a lot I can do to troubleshoot with something so minimal. What am I missing? def Stop(self): if (self.State == 1 or self.State == 2): ### do some unrelated stuff else: self.StopX() ###reset output on pin5 to 0 self.dwf.FDwfDigitalOutOutputSet(hdwf, c_int(5), c_int(0)) ###(hdwf, idxChannel, v) def StopX(self): try: ###turn off/reset x-ray pulses to zero self.dwf.FDwfAnalogOutReset(hdwf, c_int(-1)) ###ANY CHANCE THIS IS THE CULPRIT?
  19. The AnalogDiscovery2 has functions AnalogOutRunSet and DigitalOutRunSet which set the run length for the entire instrument. Is it possible to set run-times for individual pins, instead of for the instrument as a whole? For example, to have certain pins turn off after an exact duration specified while the other pins continue running uninterrupted?
  20. I configured my program slightly differently so I don't need to do this anymore. Thanks for checking!
  21. Sorry for my confusion, but I think I'm hearing two different things from you on synchronizing the start of the scan acquisition. Trigger or no trigger?
  22. Thanks. I have tried this and things look better (the pulses are occuring around the same time), but I am still having a hard time getting it to work perfectly (they aren't totally synchronized). Over the course of a single 20-second acquisition, the relative position of my data samples seems to shift around some -- see the two snips about 5sec apart during the same trial. The blue pulse should by synchronized with the rising edge of the black pulse. I have verified with an external oscilliscope that the pulses are occurring simultaneously, so it must be the synchronization of the acquisition/plotting which is failing. Is this a problem with how I am configuring the scopes, or is it an artifact of how I am reading from the buffers and updating the plot? Either way, thoughts on how to fix it? Code: #configure digital in cSamples = 200 # set number of sample to acquire rgwSamples = (c_uint16*cSamples)() rg1 = (c_double*cSamples)() #rg = pointer to allocated buffer to copy the acquisition data rg2 = (c_double*cSamples)() #rg = pointer to allocated buffer to copy the acquisition data sts = c_int() self.dwf.FDwfDigitalInAcquisitionModeSet(hdwf, c_int(1)) self.dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcAnalogIn) self.dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.xRate)))) #sample rate at same freq as X-Ray self.dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16)) # 16bit per sample format self.dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples)) self.dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(cSamples/2)) # trigger position in middle of buffer #configure analog in self.dwf.FDwfAnalogInAcquisitionModeSet(hdwf, c_int(1)) self.dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(hzSys.value/(100*self.xRate)))) self.dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(cSamples)) self.dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(0)) # trigger position in middle of buffer self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5)) # begin acquisition on both analog and digital self.dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) self.dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) while True: self.dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) self.dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value : break #read data self.dwf.FDwfAnalogInStatusData(hdwf, c_int(0), rg1, len(rg1)) # get Analog channel 1 data from buffer self.dwf.FDwfAnalogInStatusData(hdwf, c_int(1), rg2, len(rg2)) # get Analog channel 2 data from buffer self.dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, 2*cSamples) # get Digital data #set up plots self.canvasQ.figure.clear() myplt = self.canvasQ.figure.add_subplot(111) myplt.set_ylabel('signal') myplt.set_xlabel('samples') myplt.set_xlim(0,cSamples) myplt.set_ylim(-0.05,1.05) rgpy=[0.0]*len(rgwSamples) rgpy1=[0.0]*len(rg1) rgpy2=[0.0]*len(rg2) for i in range(0,len(rgpy)): rgpy= 1 & rgwSamples for i in range(0,len(rgpy1)): rgpy1=rg1 rgpy2=rg2 myplt.plot(rgpy, 'k') myplt.plot(rgpy1, 'r') myplt.plot(rgpy2, 'b') plt.pause(0.1) self.canvasQ.draw()
  23. I am writing a custom GUI to send and monitor pulses. One system sends a constant background pulse (black) to one piece of hardware, meanwhile the user specify inputs for the pulses for the other systems. When a button is pressed, the configurations are set up and the device is set to wait for a trigger to begin generating the analog pulses. However, I get a single first pulse from the analog waveform generators (blue&red) when the configuration button is clicked, before the PC trigger line pulse is sent. How do I eliminate these initial configuration pulses? This is the code for the configuration. When this method is called I get the single analog pulse outputs. Everything works properly after that ie- the analog pulses start on the correct trigger signal. def ArmTrigger(self): # analog pulse control setup self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(True)) self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_int(True)) self.dwf.FDwfAnalogOutMasterSet(hdwf, c_int(1), c_int(0)); # for second channel set master the first channel, slave channel is controlled by the master self.dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(-1), AnalogOutNodeCarrier, funcSquare) self.dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(self.xRate)) self.dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(1)) self.dwf.FDwfAnalogOutOffsetSet(hdwf, c_int(-1), c_double(0)) self.dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(symm)) #pulse width self.dwf.FDwfAnalogOutNodePhaseSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_double(self.x2Phase)) #phase shift for second channel self.dwf.FDwfAnalogOutRunSet(hdwf, c_int(-1), c_double(self.xDuration)) #set run duration on all channels self.dwf.FDwfAnalogOutIdleSet(hdwf,c_int(-1), c_int(0)) #set up PC trigger to start pulse output AND acquisition self.dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(0), trigsrcPC) self.dwf.FDwfAnalogOutTriggerSlopeSet(hdwf, c_int(0), c_int(0)) # set master channel to trigger on rising edge #configure everything to wait for trigger self.dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) # start master, slave will follow self.StartButton.setEnabled(True) #start button click sends trigger line pulse with dwf.FDwfDeviceTriggerPC(hdwf)