Jump to content
  • 0

When using FDwfDigitalOutPlayDataSet with large sample values results in corrupted signals


RRahul

Question

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()

 

Corrupted Signal in Oscope.jpg

test.py

Edited by RRahul
Link to comment
Share on other sites

Recommended Posts

  • 0

"""
   DWF Python Example
   Author:  Digilent, Inc.
   Revision:  2024-08-21

   Requires:                       
       Python 2.7, 3
   Description:
   Generates a custom pattern
"""

from ctypes import *
from dwfconstants import *
import sys
import time
import numpy
import matplotlib.pyplot as plt


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()

version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print("DWF Version: "+str(version.value))

# continue running after device close
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()

# the device will only be configured when FDwf###Configure is called
dwf.FDwfDeviceAutoConfigureSet(hdwf, 0) 
dwf.FDwfParamSet(hdwf,DwfParamDigitalVoltage,1800)

PIXEL_TIME =12
LINE_TIME = 128*PIXEL_TIME
FRAME_TIME=4096*LINE_TIME

pin = 0
hzRate = 8e6
data_py = [0]*32000
for i in range(12000):
    data_py[i] =1
cBits = len(data_py)
print(cBits)
# digital-in
hzDI = c_double()



hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
print("DigitanOut base freq: "+str(hzSys.value/1e6)+"MHz")
# how many bytes we need to fit this many bits, (+7)/8
rgbdata = (c_ubyte*((cBits+7)>>3))(0) 
# array to bits in byte array
for i in range(cBits):
    if data_py[i] != 0:
        rgbdata[i>>3] |= 1<<(i&7)
        
# generate pattern
dwf.FDwfParamSet(hdwf, DwfParamDigitalVoltage, 1800)
dwf.FDwfDigitalOutEnableSet(hdwf, pin, 1)
dwf.FDwfDigitalOutIdleSet(hdwf, pin, DwfDigitalOutIdleLow)
dwf.FDwfDigitalOutTypeSet(hdwf, pin, DwfDigitalOutTypeCustom)
# 100kHz sample rate
dwf.FDwfDigitalOutDividerSet(hdwf, pin, int(hzSys.value/hzRate))
 # set sample rate
dwf.FDwfDigitalOutDataSet(hdwf, pin, byref(rgbdata), cBits)
dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(0))
dwf.FDwfDigitalOutRunSet(hdwf, c_double(cBits/hzRate)) 
dwf.FDwfDigitalOutConfigure(hdwf, 1)

Lastly, why is this code not producing an maximum output of around 1.8 V instead of 3.3 V

 

Link to comment
Share on other sites

  • 0

@attila Using the SDK, how do you trigger an output from a raspberry pi Pico producing an clock signal connected to high speed input 1 on the rising edge. For clarification when the input reads a clock edge it should produce the desired output and hold the last value until the next clock edge 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...