I am interfacing with the USB-CTR04 board using the uldaq Python library. I have two desired outcomes:
To drive two timers in sync with identical pulse waveforms
To time the start of these pulses with microsecond accuracy
Here's an example of what I mean: every 100 us, I would like TMR0 and TMR1 to both generate 50 pulses at 100 kHz with 50% duty cycle.
However, I face difficulties with executing this level of control using the Python library. Specifically, in order of the objectives:
1. Driving Timers In Sync
pulse_out_start method only accepts one timer ID. I have to call it separately, once for each timer, like this:
for id in TIMER_IDS:
timer.pulse_out_start(id,...)
This results in a delay of about 5-7 ms between when the two timers start their pulse waveforms. I was able to work around this by using the initial_delay argument for the first timer. I gave it a value of 0.007 s, which caused the waveforms to align within 1 us.
This works, but I'm wondering if there's a better, more correct way to do this i.e. a way that I can command the board to drive both timers simultaneously.
2. Timing Commands With Microsecond Accuracy
Python's time.sleep() method does not work at resolutions of microseconds. I tried the following:
whileTrue:
start_both_timers()
time.sleep(0.0001)# Sleep for 100 us
But the measured spacing between consecutive waveforms is around 14 ms, not 100 us. This has to do with how time.sleep() works and the accuracy of the clock that drives it.
I'm wondering what's the correct way to do this. Maybe I can use a third timer, say TMR2, to run at 10 kHz (100 us) and somehow use its rising edge as a trigger for the other two timers?
I see there is a set_trigger method for timers, however the linked API reference only says to specify the trigger type e.g. POS_EDGE and to use RETRIGGER (for my case) in pulse_out_start. It does not say how to specify TMR2 as the trigger source.
I'd love to know how to use triggers with timers, since there are no examples for this in the library.
Thank you for your time. If I can get help with only one thing, I would say the second issue is more important. I have an acceptable workaround for the first one.
Question
Oswin
Hi,
I am interfacing with the USB-CTR04 board using the uldaq Python library. I have two desired outcomes:
Here's an example of what I mean: every 100 us, I would like TMR0 and TMR1 to both generate 50 pulses at 100 kHz with 50% duty cycle.
However, I face difficulties with executing this level of control using the Python library. Specifically, in order of the objectives:
1. Driving Timers In Sync
pulse_out_start method only accepts one timer ID. I have to call it separately, once for each timer, like this:
This results in a delay of about 5-7 ms between when the two timers start their pulse waveforms. I was able to work around this by using the initial_delay argument for the first timer. I gave it a value of 0.007 s, which caused the waveforms to align within 1 us.
This works, but I'm wondering if there's a better, more correct way to do this i.e. a way that I can command the board to drive both timers simultaneously.
2. Timing Commands With Microsecond Accuracy
Python's time.sleep() method does not work at resolutions of microseconds. I tried the following:
But the measured spacing between consecutive waveforms is around 14 ms, not 100 us. This has to do with how time.sleep() works and the accuracy of the clock that drives it.
I'm wondering what's the correct way to do this. Maybe I can use a third timer, say TMR2, to run at 10 kHz (100 us) and somehow use its rising edge as a trigger for the other two timers?
I see there is a set_trigger method for timers, however the linked API reference only says to specify the trigger type e.g. POS_EDGE and to use RETRIGGER (for my case) in pulse_out_start. It does not say how to specify TMR2 as the trigger source.
I'd love to know how to use triggers with timers, since there are no examples for this in the library.
Thank you for your time. If I can get help with only one thing, I would say the second issue is more important. I have an acceptable workaround for the first one.
Cheers,
Edited by OswinOswin Rodrigues
Simplify body text
Link to comment
Share on other sites
3 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