09-05-2023 03:42 AM
@Kevin_Price wrote:
Counters to the rescue! An intermediary counter task will let you generate a delayed 1000 Hz output in response to the 1000 Hz input, with a sub-microsec delay resolution!
I'll assume all active high signals for the discussion, you can adjust if needed.
1. Configure a counter task with both low time *and* initial delay set to the delay time you want -- let's say 170 microsec.
2. Set high time to be less than the remaining time per msec. In this case, definitely less than 830 microsec. But frankly, I'd make it as short as necessary for whatever the external device needs. Maybe that's 10 microsec or less.
3. Set the counter task to be retriggerable, using the external 1000 Hz signal as the trigger.
4. Configure AO to use the counter output as its sample clock, active on rising edge.
5. Start the AO task *before* you start the counter task.
Delay resolution will be 1 cycle of the device's timebase -- which will likely be either 10 or 12.5 nanosec depending on the specific device. Very old ones might be 50 nanosec.instead.
-Kevin P
You sir are a hero!
Just for #5, did you mean start the counter before the AO? Otherwise the AO task would not have an available clock? So, something like the picture attached. First time using counters :). Never understood their use. They do open a new realm of possibilities. Thank you!
(I am not sure the control task [set to commit] is needed in the counter).
PFI0 is my HW trigger signal
PFI12 is the counter (ctr0)
09-05-2023 06:56 AM
No, in #5 I really did mean to start AO *before* the counter. Yes it leaves the AO task without a clock (at first), but that's actually *intentional*. Tasks that receive or react to timing signals (such as sample clocks or triggers) should be started before the task that's going to generate them.
The commit action is actually a somewhat more subtle good practice. When a counter output task is committed, it is forced to go into its idle state. In general this might create a digital edge that downstream tasks & equipment want to react to. So the overall best sequence is to:
1. Commit the counter task
2. Start the AO task (after the possible "extra" edge as the counter is forced into idle state)
3. Start the counter task (after the AO task is started, thus ready and waiting for its clock)
-Kevin P