When trying to play a pattern in an infinite loop with a sample frequency of 8MHz and 6,000,000 samples a corrupted signal appears at the beginning of every period. My pattern is still visible but before the rising edge there are some signals which seem to be random. Additionally what is the format for the data for example to have one line be constant 0 while the other lines are doing some clock signals
Question
RRahul
When trying to play a pattern in an infinite loop with a sample frequency of 8MHz and 6,000,000 samples a corrupted signal appears at the beginning of every period. My pattern is still visible but before the rising edge there are some signals which seem to be random. Additionally what is the format for the data for example to have one line be constant 0 while the other lines are doing some clock signals
CODE:
"""
DWF Python Example
Author: Digilent, Inc.
Revision: 2022-02-11
Requires:
Python 2.7, 3
"""
from ctypes import *
from dwfconstants import *
import sys
import time
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, c_int(1)) # 0 = run, 1 = stop, 2 = shutdown
print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-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, c_int(0))# 0 = the device will be configured only when calling FDwf###Configure
print("Configuring Digital Out...")
hzPlay = 10e6
# for infinite playback fill the entire 256MiByte memory
nSamples = 6000000
rgbSamples= (c_ubyte*int(nSamples))()
for i in range(len(rgbSamples)):
if i < 3000000:
rgbSamples[i]=1
else:
rgbSamples[i] = 0
dwf.FDwfDigitalOutRunSet(hdwf, c_double(nSamples / float(hzPlay)))
dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(0)) # infinite repeats
# enable play mode for the wanted signals
for i in range(8):
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(i), c_int(1)) # enable
dwf.FDwfDigitalOutTypeSet(hdwf, c_int(i), DwfDigitalOutTypePlay)
dwf.FDwfDigitalOutIdleSet(hdwf, c_int(i), DwfDigitalOutIdleLow)
print("Samples:"+str(nSamples)+" Rate:"+str(hzPlay)+"Hz "+" Period:"+str(nSamples/hzPlay)+"s")
dwf.FDwfDigitalOutPlayRateSet(hdwf, c_double(hzPlay)) # play sample rate
# set play data array of 8 bit samples
dwf.FDwfDigitalOutPlayDataSet(hdwf, byref(rgbSamples), c_int(8), c_int(int(nSamples)))
print("Arming Digital Out...")
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
time.sleep(100)
dwf.FDwfDeviceCloseAll()
test.py
Edited by RRahulLink to comment
Share on other sites
32 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