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?
#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))
#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
Question
mabernico
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
Archived
This topic is now archived and is closed to further replies.