RRahul Posted yesterday at 12:53 PM Share Posted yesterday at 12:53 PM """ DWF Python Example Author: Digilent, Inc. Revision: 2024-09-13 Requires: Python 2.7, 3 """ import csv import numpy as np import pandas as pd from ctypes import * from dwfconstants import * import sys df = pd.read_csv('rst_clk.csv') #CONSTANTS: TICKS = 40 LINE_TIME = TICKS*128 FRAME_TIME = LINE_TIME*4096 for i in range(len(df.index)): print(df['Repeat'].loc[df.index[i]]) pattern1 = np.genfromtxt(df['Pattern'].loc[df.index[0]], delimiter=',') new_pattern1 = np.tile(pattern1,4096) 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() sts = c_ubyte() version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("DWF Version: "+str(version.value)) dwf.FDwfParamSet(DwfParamOnClose, 0) # 0 = run, 1 = stop, 2 = shutdown print("Opening first device") dwf.FDwfDeviceOpen(-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() dwf.FDwfDeviceAutoConfigureSet(hdwf, 0)# 0 = the device will be configured only when calling FDwf###Configure # dwf.FDwfDigitalIODriveSet(hdwf, 0, c_double(0.008), 2) # 8mA, 2=Fast print("Generating pattern...") hzPlay = 2e6 # for infinite playback fill the entire 256MiByte memory #nPlay = 256*1024*1024 #rgbPlay = (c_uint8*int(nPlay))() #for i in range(len(rgbPlay)): # rgbPlay[i] = c_uint8(i) nPlay = len(pattern1) rgbPlay = (c_uint8 * FRAME_TIME)() for i in range(len(new_pattern1)): rgbPlay[i] = int(new_pattern1[i]) print("Configuring Digital Out...") print("Samples:"+str(nPlay)+" Rate:"+str(hzPlay)+"Hz "+" Period:"+str(nPlay/hzPlay)+"s") dwf.FDwfDigitalOutPlayRateSet(hdwf, c_double(hzPlay)) # play sample rate if nPlay < 256*1024*1024 : # use wait if length is less than the 256MiB dwf.FDwfDigitalOutRunSet(hdwf, c_double(nPlay/hzPlay)) dwf.FDwfDigitalOutWaitSet(hdwf, c_double(1e-6)) dwf.FDwfDigitalOutRepeatSet(hdwf, 0) for i in range(8): dwf.FDwfDigitalOutEnableSet(hdwf, i, 1) # enable dwf.FDwfDigitalOutTypeSet(hdwf, i, DwfDigitalOutTypePlay) dwf.FDwfDigitalOutIdleSet(hdwf, i, DwfDigitalOutIdleLow) dwf.FDwfDigitalOutConfigure(hdwf, 0) # stop earlier run # set play data array of 8 bit samples if dwf.FDwfDigitalOutPlayDataSet(hdwf, byref(rgbPlay), c_uint(8), int(nPlay)) == 0: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() print("Starting Digital Out...") if dwf.FDwfDigitalOutConfigure(hdwf, 1) == 0: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() dwf.FDwfDeviceCloseAll() print("done") Why when I change the hzPlay variable to 8 MHz a corrupted signal is produced. Link to comment Share on other sites More sharing options...
0 attila Posted 9 hours ago Share Posted 9 hours ago Hi @RRahul Integer divisions of system frequency are supported. To generate 8 MHz from 100 MHz you would need /12.5, so set it to 96 MHz for example. dwf.FDwfDeviceParamSet(hdwf, DwfParamFrequency, 96000000) Link to comment Share on other sites More sharing options...
0 RRahul Posted 8 hours ago Author Share Posted 8 hours ago (edited) Thanks for the Info Edited 8 hours ago by RRahul attila 1 Link to comment Share on other sites More sharing options...
Question
RRahul
""" DWF Python Example Author: Digilent, Inc. Revision: 2024-09-13 Requires: Python 2.7, 3 """ import csv import numpy as np import pandas as pd from ctypes import * from dwfconstants import * import sys df = pd.read_csv('rst_clk.csv') #CONSTANTS: TICKS = 40 LINE_TIME = TICKS*128 FRAME_TIME = LINE_TIME*4096 for i in range(len(df.index)): print(df['Repeat'].loc[df.index[i]]) pattern1 = np.genfromtxt(df['Pattern'].loc[df.index[0]], delimiter=',') new_pattern1 = np.tile(pattern1,4096) 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() sts = c_ubyte() version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("DWF Version: "+str(version.value)) dwf.FDwfParamSet(DwfParamOnClose, 0) # 0 = run, 1 = stop, 2 = shutdown print("Opening first device") dwf.FDwfDeviceOpen(-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() dwf.FDwfDeviceAutoConfigureSet(hdwf, 0)# 0 = the device will be configured only when calling FDwf###Configure # dwf.FDwfDigitalIODriveSet(hdwf, 0, c_double(0.008), 2) # 8mA, 2=Fast print("Generating pattern...") hzPlay = 2e6 # for infinite playback fill the entire 256MiByte memory #nPlay = 256*1024*1024 #rgbPlay = (c_uint8*int(nPlay))() #for i in range(len(rgbPlay)): # rgbPlay[i] = c_uint8(i) nPlay = len(pattern1) rgbPlay = (c_uint8 * FRAME_TIME)() for i in range(len(new_pattern1)): rgbPlay[i] = int(new_pattern1[i]) print("Configuring Digital Out...") print("Samples:"+str(nPlay)+" Rate:"+str(hzPlay)+"Hz "+" Period:"+str(nPlay/hzPlay)+"s") dwf.FDwfDigitalOutPlayRateSet(hdwf, c_double(hzPlay)) # play sample rate if nPlay < 256*1024*1024 : # use wait if length is less than the 256MiB dwf.FDwfDigitalOutRunSet(hdwf, c_double(nPlay/hzPlay)) dwf.FDwfDigitalOutWaitSet(hdwf, c_double(1e-6)) dwf.FDwfDigitalOutRepeatSet(hdwf, 0) for i in range(8): dwf.FDwfDigitalOutEnableSet(hdwf, i, 1) # enable dwf.FDwfDigitalOutTypeSet(hdwf, i, DwfDigitalOutTypePlay) dwf.FDwfDigitalOutIdleSet(hdwf, i, DwfDigitalOutIdleLow) dwf.FDwfDigitalOutConfigure(hdwf, 0) # stop earlier run # set play data array of 8 bit samples if dwf.FDwfDigitalOutPlayDataSet(hdwf, byref(rgbPlay), c_uint(8), int(nPlay)) == 0: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() print("Starting Digital Out...") if dwf.FDwfDigitalOutConfigure(hdwf, 1) == 0: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) quit() dwf.FDwfDeviceCloseAll() print("done")
Why when I change the hzPlay variable to 8 MHz a corrupted signal is produced.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now