Solution
This error occurs when the duty cycle is changed to another value using property nodes before the previous value has completed a whole cycle. If
t is the time since the last change of duty cycle and
T is the period of the signal, trying to apply a new duty cycle when
t < T will disrupt the task, leading to the application stopping unexpectedly. The following image shows the code that causes this issue.
There are several solutions that can be followed in order avoid disrupting the task when changing the value on the fly:
-
Using DAQmx Write VI instead of property nodes
Instead of using property nodes to update the value of the duty cycle, use DAQmx Write VI. Unlike a property node, which updates the value of the DAQmx task indiscriminately, Write VI will buffer the new written value until the hardware is ready to be updated. Note that the frequency will have to be written alongside the Duty Cycle.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
-
Using Ready for New Value property
If you want to keep the property nodes to update the values, you can actively check if the hardware is ready to accept a new value by using the Ready for New Value property. Read from this property and add the proper logic to update the duty cycle only when the device is ready for it.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
-
Calculate period (T) dynamically
You can calculate the period of one complete cycle using the formula T = 1/f , where f is the signal's frequency. To avoid the application stopping with an error, ensure that the time elapsed since the last duty cycle update, t, satisfies the condition t ≥ T before making another update. This allows the current cycle to complete before any other changes are applied to the hardware. This can be implemented using any of LabVIEW’s timing solutions (e.g. Wait (ms) Function or a timer FGV).
This solution is much less reliable, as the timer is not deterministically tied to the hardware’s actual cycle. Reaching or surpassing the dynamically calculated value of t does not guarantee that the hardware has completed the full cycle yet.