Rohit_Verma Posted January 7, 2022 Share Posted January 7, 2022 I need to capture a pulse (High to low), which stays for appx 600us, then goes back high. I need to capture for a given interval of time, the no. of pulses triggered. time interval maybe : 1ms, 1 s, 5s etc. Been using the DigitalIn_PulseTrigger.py & DigitalIn_trigger.py, but couldn't understand if it is behaving as expected: -------------- while True: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) print("Status:", str(sts.value)) if sts.value == 2 : # done break ------------ Not sure about the value to be compared here, as for 1 sec or for 5 sec, i am seeing the break in appx same time here. => Also tried with AnalogIn_sample.py but i think it is not able to detect the drop in voltage for such short duration. Any help will be appreciated. Thanks, Rohit Link to comment Share on other sites More sharing options...
0 attila Posted January 7, 2022 Share Posted January 7, 2022 Hi @Rohit_Verma You could perform recording either on analog or digital-in and count the edges/pulses in software. Link to comment Share on other sites More sharing options...
0 Rohit_Verma Posted January 7, 2022 Author Share Posted January 7, 2022 2 minutes ago, attila said: Hi @Rohit_Verma You could perform recording either on analog or digital-in and count the edges/pulses in software. Hi @attila, Thanks for quick response, Actually i need the count in the file itself, need for some automation project work.. Checking with DigitalIn_PulseTrigger.py as of now, but not sure about the value "2" below: print("Status:", str(sts.value)) if sts.value == 2 : # done <------------ What does this 2 signify, what else can we write here??? What does this signify ? => Also, please confirm if my understanding about these functions is right : dwf.FDwfDigitalInTriggerResetSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<7)) <---- Reset at Falling edge on pin DIO7 dwf.FDwfDigitalInTriggerSet(hdwf, c_int(1<<7), c_int(0), c_int(0), c_int(0)) <------- generate trigger at low state of Pin DIO7(in my case it around 600 us) attach snippet of negative pulse. => what value should be placed here to count number of negative pulse for some interval ?? Thanks, Link to comment Share on other sites More sharing options...
0 attila Posted January 7, 2022 Share Posted January 7, 2022 Hi @Rohit_Verma 1. The following lines are to wait for the capture to finish. while True: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone : # 2 break 2. If you want to trigger on DIO-7 negative pulse length use: dwf.FDwfDigitalInTriggerResetSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<7)) # low, high, rise, fall dwf.FDwfDigitalInTriggerSet(hdwf, c_int(1<<7), c_int(0), c_int(0), c_int(0)) # low, high, rise, fall dwf.FDwfDigitalInTriggerLengthSet(hdwf, c_double(5e-4), c_double(7e-4), c_int(0)) # 500-700us dwf.FDwfDigitalInTriggerCountSet(hdwf, c_int(1), c_int(0)) 3. If you want to precisely count the pulse rate use the record to collect a fixed number of samples and count the pulses in you script. You could use the sync capture mode and rely on the available samples, see DigitalIn_Sync.py and the following post. This will be software controlled start/stop so it will have a uncertainty of milliseconds. Rohit_Verma 1 Link to comment Share on other sites More sharing options...
0 Rohit_Verma Posted January 7, 2022 Author Share Posted January 7, 2022 (edited) 50 minutes ago, attila said: Hi @Rohit_Verma 1. The following lines are to wait for the capture to finish. while True: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone : # 2 break 2. If you want to trigger on DIO-7 negative pulse length use: dwf.FDwfDigitalInTriggerResetSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<7)) # low, high, rise, fall dwf.FDwfDigitalInTriggerSet(hdwf, c_int(1<<7), c_int(0), c_int(0), c_int(0)) # low, high, rise, fall dwf.FDwfDigitalInTriggerLengthSet(hdwf, c_double(5e-4), c_double(7e-4), c_int(0)) # 500-700us dwf.FDwfDigitalInTriggerCountSet(hdwf, c_int(1), c_int(0)) 3. If you want to precisely count the pulse rate use the record to collect a fixed number of samples and count the pulses in you script. You could use the sync capture mode and rely on the available samples, see DigitalIn_Sync.py and the following post. This will be software controlled start/stop so it will have a uncertainty of milliseconds. Thanks @attila , I have copied the aboveset of commands and below is the output: --------------- DWF Version: b'3.17.1' Opening first device DigitanIn base freq: 100.0MHz Waiting for acquisition... Status: 5 Status: 5 Status: 5 Status: 5 Status: 5 Status: 3 Status: 3 Status: 3 Status: 3 Status: 2 done --------------- => Now my concern is the value that is being returned in status variable. ==> Because i need to validate this for different time intervals, that is: 1st case: Negative pulse at every 1 sec 2nd Case: Negative Pulse at every 100msec. 3rd Case: Negative Pulse at every 5 sec. Likewise, i need to store 6-7 cases, and need to validate the same in file only. I am attaching the full DigitalIn_PulseTrigger.py file here. Please let me know what should be the best way to validate the same (Without using the software). Thanks again, Rohit DigitalIn_PulseTrigger.py Edited January 7, 2022 by Rohit_Verma Link to comment Share on other sites More sharing options...
0 attila Posted January 7, 2022 Share Posted January 7, 2022 Hi @Rohit_Verma To measure time between captures you can use something like this. For quick captures also set the sample rate high, divider to low, like to 1. ... dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(1))) ... print("Waiting for acquisition...") dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) try: while True: start = time.time() while True: dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) if sts.value == 2 : # done break print("elapsed: "+str((time.time()-start)*1000)+"ms") except KeyboardInterrupt: # Ctrl+C pass ... Rohit_Verma 1 Link to comment Share on other sites More sharing options...
0 Rohit_Verma Posted January 17, 2022 Author Share Posted January 17, 2022 Hi @attila, Thanks so much for your valuable input, i am able to detect the Negative pulse now. However, just for one case i need some more input please? => I want to generate a pulse on 1 DIO pin and my code is such that, it's response i can check from another pin. Been using below logic: def GeneratingSignal(): #For GPIO1, generating 1ms pulse dwf.FDwfDigitalOutRunSet(hdwf, c_double(1)) # 1ms run dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(1)) # once dwf.FDwfDigitalOutIdleSet(hdwf, c_int(0), c_int(0)) # 1=DwfDigitalOutIdleLow, low when not running dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(0), c_int(1), c_int(0)) # initialize high on start dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_int(1), c_int(1)) # low/high count zero, no toggle during run dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1)) print("Generating 1s pulse") dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) #time.sleep(1) dwf.FDwfDigitalOutReset(hdwf) But i need to validate no. of pulses, lets say 5 pulses of 1ms, to validate the scenario. However i am getting some random values if i call this func, GenerateSignal(), is it because of some latency,? How can i rectify this ?? Link to comment Share on other sites More sharing options...
0 attila Posted January 19, 2022 Share Posted January 19, 2022 Hi @Rohit_Verma See the examples WF SDK / samples/ py/ DigitalOut_Pulse.py DigitalOut_Pins.py DigitalOut_Duty.py DigitalOut_Phase.py ... Link to comment Share on other sites More sharing options...
Question
Rohit_Verma
I need to capture a pulse (High to low), which stays for appx 600us, then goes back high.
I need to capture for a given interval of time, the no. of pulses triggered.
time interval maybe : 1ms, 1 s, 5s etc.
Been using the DigitalIn_PulseTrigger.py & DigitalIn_trigger.py, but couldn't understand if it is behaving as expected:
--------------
while True:
dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
print("Status:", str(sts.value))
if sts.value == 2 : # done
break
------------
Not sure about the value to be compared here, as for 1 sec or for 5 sec, i am seeing the break in appx same time here.
=> Also tried with AnalogIn_sample.py but i think it is not able to detect the drop in voltage for such short duration.
Any help will be appreciated.
Thanks,
Rohit
Link to comment
Share on other sites
7 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