Jump to content
  • 0

frame perform once time without repetition in script python


guis06

Question

Hello 

i m trying to generate specific pulse generator with custom mode with my analog discovery 2 device.

I would like to generate only one sequence of frame but i dont succeed to manage it. I have allways infinite loop repetition(during the waiting sleep of my python script).

I did not understand how to manage launching only one sequence without trigger.

my code in python following. I m trying to manage on Pin 1 my ouput frame:

/////////////////////////////////////////////////////

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



 

version = create_string_buffer(16)

dwf.FDwfGetVersion(version)

print("DWF Version: "+str(version.value))

 

print("Opening first device")

hdwf = c_int()

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.FDwfParamSet(c_int(4), c_int(0)) # DwfParamOnClose 0 = run, 1 = stop, 2 = shutdown

 

Precharge_py = []

for i in range(2): # 2 times

    for i in range(110): #110µs : 1

        Precharge_py.append(1)

    for i in range(110): #110µs : 0

        Precharge_py.append(1)

 

for i in range(5): # 5 times

    for i in range(55): #55µs : 1

        Precharge_py.append(1)

    for i in range(20): #20µs : 0

        Precharge_py.append(0)

 

rgbPrecharge=(c_ubyte*((len(Precharge_py)+7)>>3))(0) 

# array to bits in byte array

for i in range(len(Precharge_py)):

    if Precharge_py[i] != 0:

        rgbPrecharge[i>>3] |= 1<<(i&7)

 

pin=0

hzSys = c_double()

dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))

# generate pattern

dwf.FDwfDigitalOutEnableSet(hdwf, c_int(pin), c_int(1))

dwf.FDwfDigitalOutTypeSet(hdwf, c_int(pin), DwfDigitalOutTypeCustom)

# 1000kHz sample rate

dwf.FDwfDigitalOutDividerSet(hdwf, c_int(pin), c_int(int(hzSys.value/1000e3))) # set sample rate

dwf.FDwfDigitalOutDataSet(hdwf, c_int(pin), byref(rgbPrecharge), c_int(len(Precharge_py)))

dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(1)) # repeat once

 

dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

 

time.sleep(1)


 

dwf.FDwfDeviceCloseAll()

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...