11-19-2023 04:43 AM
It's pretty much what I already described in the comment. Pulse generation starts with the idle state followed by the active. When you "commit" a counter output task, it is forced to go into its idle state at that time so that when you subsequently start it, you can be sure there won't be a digital transition at the output. If you don't do it explicitly ahead of time, the "commit" will happen implicitly as part of the DAQmx Task State Model when you go to start the task, which might cause an extra unwanted transition at that time.
In the posted example, it's important to start the trigger filter last so that the other 2 counter tasks are armed and ready before it generates any transitions. Hence, it's also important to do the commit *before* starting the other tasks, so you can get that extra possible transition out of the way before the other 2 counter tasks are waiting to react.
It isn't always *strictly* necessary to do this -- there can be situations where you know for certain that the counter output pin will already be in idle state or that the transition into idle state won't have any side effects on other tasks. But I find it to be a better general habit to take control over such things rather than rely on things that might "change behind my back" in the future.
Amongst the things that someone might easily change later: chosen polarity of counter output in question, polarity of edges other tasks react to, power-up idle state of output pin due to MAX config, power-up idle state of output pin due to device change.
-Kevin P
11-23-2023 06:57 AM
Hello
and thank you for these explanations. I now understand the interest of this function.
The last program you suggested with the synchronization of the output signal every other period works very well.
I don't know if I can ask my question in this exchange, tell me if it's good...
Now I'd like the two output signals, red and blue, to be generated only in relation to a gate .... cf the attached diagram.
To explain in detail: I have the source signal (yellow signal), external and stable at 10kHz or 5kHz depending on the desired mode of use. At each rising edge of this signal, 2 pulse signals are emitted. One is a pulse signal of the same frequency and duty 30%, the blue one. The other is a falling pulse signal, red. See the attached oscilloscope images.
To this we now add a gate, a trigger signal from an external source. This could be a switch, for example. It turns on and off at random, independent of the other signals. Depending on its level, high or low, I'd like it to activate or deactivate the 2 outputs while the program is running ....
Keeping in mind that the signals generated must always be in phase with the input signal, the yellow one...
Do you have any ideas on how to do this? I can't keep the red and blue output signals synchronized with the rising edges of the input signal ....
11-29-2023 04:25 PM
Seems to me that it'd probably be simplest to add an external digital AND circuit. In your diagram, it looks like it'd be enough to trigger the red and blue counters from the output of (Source Counter 0 AND Source Counter 1).
Alternately, using a chip with multiple AND gates, you could AND the red and blue outputs with Source Counter 1, and send *those* outputs along to wherever they're going.
-Kevin P