Solution
Generating the same data more than once is referred to as regeneration. NI-DAQmx allows you to control this behavior using the Regeneration Mode attribute/property. By default:
- Regeneration is enabled for sample clock timing, meaning the device will continuously repeat the data in the buffer.
- Regeneration is disabled for handshaking or burst handshaking timing, requiring new data to be written continuously.
In the attached example, regeneration is explicitly disabled, allowing the buffer data and the sample clock rate to be updated dynamically. This enables on the fly changes to the PWM signal, such as modifying its frequency and duty cycle, without stopping the task.
However, this method comes with important considerations:
-
Pattern Size Consistency: All digital patterns (data sets) must have the same number of samples, otherwise we may face erratic behaviors, more details are explained in the article .
-
Buffer Consumption Time: Larger data patterns take longer to transmit, which can delay the loading of new data, particularly in non-deterministic OS such as Windows.
-
Sample Rate Management: Care must be taken when setting the sample rate. If the buffer is consumed faster than new data is written, it can lead to a buffer underflow error.
This approach is particularly useful when you need flexible, on the fly control over digital output signals, similar to what you might achieve with counter output tasks.