I've been experimenting with a Analog Discovery system controlled via Python and have determined how to generate a digital signal out, however I have not been able to have the signal change frequency or duty cycle mid run. I have tried just use the function that controls duty cycle a second time however that just seems to overwrite the first. Below is the python code I have been using, any guidance would be much appreciated.
-ZG
"""
DWF Python Example
Edit ZG
Requires:
Python 2.7, numpy
python-dateutil, pyparsing
"""
from ctypes import *
from dwfconstants import *
import math
import time
import sys
Question
ZGWSU
I've been experimenting with a Analog Discovery system controlled via Python and have determined how to generate a digital signal out, however I have not been able to have the signal change frequency or duty cycle mid run. I have tried just use the function that controls duty cycle a second time however that just seems to overwrite the first. Below is the python code I have been using, any guidance would be much appreciated.
-ZG
"""
DWF Python Example
Edit ZG
Requires:
Python 2.7, numpy
python-dateutil, pyparsing
"""
from ctypes import *
from dwfconstants import *
import math
import time
import sys
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")
#declare ctype variables
hdwf = c_int()
sts = c_byte()
#print DWF version
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print "DWF Version: "+version.value
#open device
print "Opening first device"
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
if hdwf.value == hdwfNone.value:
print "failed to open device"
quit()
hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
# 1kHz pulse on IO pin 1
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1))
# prescaler to 2kHz, SystemFrequency/1kHz
print "hzSys", hzSys.value
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(int(hzSys.value/1e3)))
print "frequency:", hzSys.value/1e3/2/100
# 1 tick low, 1 tick high
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_int(4), c_int(6))
# 1kHz pulse on IO pin 1
# prescaler to 2kHz, SystemFrequency/1kHz
print "hzSys", hzSys.value
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(int(hzSys.value/1e3)))
print "frequency:", hzSys.value/1e3/2/100
# 1 tick low, 1 tick high
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_int(6), c_int(4))
# rgdSamples = (c_byte*4)(*[0x00,0xAA,0x66,0xFF])
# # 1kHz sample rate custom on IO pin 3
# dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), 1)
# dwf.FDwfDigitalOutTypeSet(hdwf, c_int(3), DwfDigitalOutTypeCustom)
# dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(int(hzSys.value/1e3)))
# dwf.FDwfDigitalOutDataSet(hdwf, c_int(3), byref(rgdSamples), c_int(4*8))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
sleepTime = 10
print "Generating output counter for %s seconds..."%sleepTime
time.sleep(sleepTime)
dwf.FDwfDigitalOutReset(hdwf);
dwf.FDwfDeviceCloseAll()
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.