02-19-2013 04:49 AM
I'm using NI 9474 DO module in a cDAQ-9184 chassis to generate five PWM signals. They all have the same frequency and duty cycle. I just need to select which lines should be active or not.
I need to pragmatically start and stop the pulse generation. The problem is that after stopping the task with DAQmx Stop Task.vi the outputs state remains the same as it was at the moment the task stopped. Sometimes the outputs stay in high state which will destroy my DUTs. I know this is an expected behavior, but I want the outputs always go into the low state after stopping the task.
There is still data in the output buffer, so writing zero to the output just before stopping the task doesn't help. Is there a way I can flush the output buffer?
I tried writing zero to the output after stopping, then started and stopped the task. This puts the outputs into low state, but still leaves the outputs in high state for a short period, which isn't acceptable.
This is a part of a bigger application and is programmed in a QMH, but the attached VI snippet shows the behavior.
Thanks, Bogomir
02-20-2013 04:07 AM
Dear Bogomir!
A simple DAQmx Write (Digital U8 1Chan 1Samp) to low before stopping the task should take care of the issue. You can have it outside of the loop (since it executes only once), then Stop and Clear the task. Resetting the device programmatically also sets all outputs to their default state.
Hope this helps.
Regards:
Andrew Valko
NI Hungary
02-20-2013 05:54 AM
Thanks Andrew,
I don't have hardware in the office to try that. I'll try tomorrow when, I will be at the customer's site. But I think, I tried that already. Writing a zero with the DAQmx Write (Digital U8 1Chan 1Samp) just before stopping the task didn't help. I guess because there is still old data in the buffer that was not generated. This is a test station that continuously calls the Start Task and Stop Task. I keep the task configured as long as the application runs. Would clearing the task also set the outputs to their default state?
Regards, Bogomir
02-20-2013 09:47 AM - edited 02-20-2013 09:49 AM
Dear Bogomir!
Yes, as stopping a task releases all associated resources, it also clears the buffer, but creating and clearing DAQmx tasks continuously is usually discouraged.
I would have some suggestions though. One of my colleagues suggested for you to use a state machine architecture, and I agree with him. Basically, if I understand you would like to have a PWM signal that you can turn on and off at runtime. For this alone, there's no need to stop the task, Setting the output to a constant 0 is enough to stop, then setting it back to PWM will restart. If you use regenerating outputs, you only need to write once for every start/stop. Here's some example code I whipped up:
The Timeout on the event structure and the Wait(ms) on exit ensures that we always wait for the new data to be set (5000 samples with 20k sample rate is 250ms worth of data).
Please tell me what you think about this approach.
Best regards:
Andrew Valko
NI Hungary