Jump to content
  • 0

Analog Discovery Continuous Run


mabernico

Question

I am trying to utilize the Analog discovery (via Python) to generate a square wave that will sweep up from 1 to 1590Hz over 30 seconds, then hold for 10 seconds at 1590, and then sweep down to 1 again.  

I have been able to mangle some code together to make this happen, but it seems that the implementation I am using is allowing the DAD unit to turn off and turn back on to generate these piecewise.

The problem with that is (understandably) there is a ~3ms gap between signals when the unit is done with one segment and moves to the next.  I assume it has more to do with using sleep commands and using dwf.FDwfAnalogOutConfigure() to start the next segment.

 

Is there something I should be using instead of sleep that may allow a continuous signal? 

RPM = c_int(0)

hzStart = float(1)
hzStop = float(1590)
secSweep = float(10)
holdTime=int(5)

#Calculations for sweep up setup
HzDiff=float(hzStop-hzStart)
HzSum=float(hzStart+hzStop)
halfHzSum=float(HzSum/2)
fmAmp=float(100.0*(HzDiff)/(HzSum))
fmOs=float(1/secSweep)

#Calculations for sweep down setup
HzDiff2=float(hzStart-hzStop)
HzSum2=float(hzStart+hzStop)
halfHzSum2=float(HzSum2/2)
fmAmp2=float(100.0*(HzDiff2)/(HzSum2))
fmOs2=float(1/secSweep)

#Digital Output Setup
# set output enable, mask on 2 LSB IOs, DIO 1 and 0
dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x0003))
# set output value, D1: 3.3V, D0: 0V
dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x0002)) 

print "Generating square wave..."
dwf.FDwfAnalogOutNodeEnableSet(hdwf, RPM, AnalogOutNodeCarrier, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, RPM, AnalogOutNodeCarrier, funcSquare)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeCarrier, c_double(halfHzSum))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeCarrier, c_double(1.65))
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, RPM, AnalogOutNodeCarrier, c_double(1.65))

dwf.FDwfAnalogOutNodeEnableSet(hdwf, RPM, AnalogOutNodeFM, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, RPM, AnalogOutNodeFM, funcRampUp)
dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, RPM, AnalogOutNodeFM, c_double(100))
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeFM, c_double(fmOs))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeFM, c_double(fmAmp))

#turn on RPM signal and run entire ramp up
dwf.FDwfAnalogOutConfigure(hdwf, RPM, c_bool(True))
time.sleep(secSweep) #wait until rampup is done

#switch RPM signal to hold at max frequency
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeCarrier, c_double(795))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeFM, c_double(1.65))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, RPM, AnalogOutNodeFM, funcSquare)
dwf.FDwfAnalogOutConfigure(hdwf, RPM, c_bool(True))
time.sleep(holdTime) #wait until hold is done

dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeCarrier, c_double(halfHzSum2))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeCarrier, c_double(1.65))
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeFM, c_double(fmOs2))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeFM, c_double(fmAmp2))

dwf.FDwfAnalogOutConfigure(hdwf, RPM, c_bool(True))
time.sleep(secSweep) #wait until rampdown is done
  
   
print "done."
dwf.FDwfDeviceClose(hdwf)

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

To eliminate the gaps, to sweep continuously you can use custom (rise, hold and decay) FM waveform.

The AM/FM samples are stored in the device as 9bit values, so the FM resolution will be 0.2%, for 1590Hz about 3Hz.

See the full script attached.

 

#create custom FM waveform, normalized to +-1
cFMSamples = c_int(0)
dwf.FDwfAnalogOutNodeDataInfo(hdwf, RPM, AnalogOutNodeFM, 0, byref(cFMSamples))
# rise from -1 to 1, hold at 1, decay from 1 to -1
# rise, hold and decay lengths are proportional
customFM = np.concatenate((np.linspace(-1., 1., cFMSamples.value*secSweep/secRun), np.linspace(1., 1., cFMSamples.value*holdTime/secRun), np.linspace(1., -1., cFMSamples.value*secSweep/secRun)))

print "Generating square wave..."
dwf.FDwfAnalogOutNodeEnableSet(hdwf, RPM, AnalogOutNodeCarrier, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, RPM, AnalogOutNodeCarrier, funcSquare)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeCarrier, c_double(halfHzSum))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeCarrier, c_double(1.65))
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, RPM, AnalogOutNodeCarrier, c_double(1.65)) 
dwf.FDwfAnalogOutNodeEnableSet(hdwf, RPM, AnalogOutNodeFM, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, RPM, AnalogOutNodeFM, funcCustom)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, RPM, AnalogOutNodeFM, c_double(1./secRun))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, RPM, AnalogOutNodeFM, c_double(fmAmp)) 
dwf.FDwfAnalogOutNodeDataSet(hdwf, RPM, AnalogOutNodeFM, customFM.ctypes.data, cFMSamples)
dwf.FDwfAnalogOutRunSet(hdwf, RPM, c_double(secRun))

 

sweep.py

Link to comment
Share on other sites

Thank you!  That was very helpful.  I now need to work on toggling the DI0 and DI1 lines when certain frequencies are reached.  Will it be possible to toggle DI0 for example when 700Hz is reached using this method.

 

Also this method seems to introduce some high-frequency noise for the first few ms.  I can probably filter this out, but it is triggering my input device (not the Analog Discovery) prematurely.

 

I really appreciate your time looking into this and what you have provided thus far.  Just bought 2 more DADs to do some more work!

 

Link to comment
Share on other sites

There should be no noise.
To test the sweep I added the shift screen acquisition at high rate. While the data is fetched to the computer the shift continues, so the first samples might be overwritten. This is why you see noise in the beginning.

Attached you have the test with normal acquisition.

sweep.py

Link to comment
Share on other sites

Since the time of reaching the 700Hz can be calculated we can generate such pulses with the digital out (pattern generator), triggered by analog out.
Don't forget to remove the digital-io settings because these override the digital-out.

# digital signals
dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcAnalogOut1)
hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1))
# scale down the 100Mhz system clock to 100Hz, because counter max is 32768, at 100Hz count max is 327sec
hzDio = 100.
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(int(hzSys.value/hzDio)))
# time of 700Hz
secDio0 = secSweep*(700.-hzStart)/(hzStop-hzStart)
# start low and stay for the specified time
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(0), c_uint(0), c_uint(int(secDio0*hzDio)))
# then high while analog out is above 700Hz, 2x remaining sweep + hold
# then long low time, while running
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_uint(10000), c_uint(int((2.*(secSweep-secDio0)+holdTime)*hzDio)))

dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
dwf.FDwfAnalogOutConfigure(hdwf, RPM, c_int(1))

sweep.py

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...