07-17-2009 04:13 PM
Hi,
I am trying to use the DAQmxWriteAnalogScalarF64 function to output a constant steady voltage of say 3V. The program will be in a loop and after every iteration I would like the output voltage to be increased by say 0.1V.
So a shortened version of my program looks like this
float64 value = 3;
DAQmxCreateTask
DAQmxCreateVoltageChan
DAQmxWriteAnalogScalarF64(TaskHandle taskHandle, bool32 autoStart, float64 timeout, float64 value, bool32 *reserved);
Loop
{
DAQmxStartTask
DAQmxStopTask
}
Now obviously that doesn't help me update the output voltage after every loop. So I tried something like this:
Loop
{
DAQmxWriteAnalogScalarF64(TaskHandle taskHandle, bool32 autoStart, float64 timeout, float64 value, bool32 *reserved);
DAQmxStartTask
DAQmxStopTask
value = value + 0.1;
}
My computer would crash when I try to run the program. Would I need to clear and create the task in every iteration too?
I am trying to avoid using the DAQmxWriteAnalogF64 function since I would need to use a sample clock to time it and my sample clock is used for the other analog output channel.
Thank you for any input.
Howard
Solved! Go to Solution.
07-20-2009 05:45 PM
Hi HT,
I have a few questions for you: What piece of hardware are you using? Have you tried using one of the analog output example programs? Have you tried sharing your sample clock between your analog output tasks? You won't need to create and clear your tasks in every iteration (that will drastically slow down your program). Thanks for that additional information!
08-07-2009 05:38 PM
Hi aNItaB,
Thank you for replying to my question and sorry for the late reply as I didn't see the e-mail notification and assumed everyone ignored my question haha.
I am currently using a PCI-6115 DAQ board. I have looked through the C++ samples that comes with the install package but none of them seem to fit my problem. Maybe there is an example that I overlooked which you could refer me to?
As for your last question, this part of the project is just a small part of a larger project I am currently working on. I understand that both channels are timed by the same analog output clock. However I only want the first channel to be hardware timed (ie. using the AO clock) and the second channel would be software timed (after every iteration of my program). That is why I wish to implement an updated version of constant voltage output after every iteration. Is calling the DAQmxWriteAnalogScalarF64 for the same task twice in a program illegal? Or is there another reason why it would lead my computer to crash?
Thank you very much for your input.
Howard
08-11-2009 07:12 AM
Hi Howard,
Calling the read function multiple times in the same task shouldn't cause any problems. However, additionally, I would recommend taking the start and stop commands out of the loop as well. Something I would try would be to create, start, and then within the while loop write and update, then once you exit the loop, stop and clear. That shouldn't crash your computer at all, so please let me know if it does!
08-11-2009 04:17 PM
aNItaB,
I have tried calling the DAQmxWriteAnalogScalarF64 in a loop and my computer would just completely freeze and I have to restart it by pressing the start button.
Then I tried using the DAQmxWriteAnalogF64 in a loop, specifying the output array as an one element array, then update that one element at the begining of each loop. This seemed to have solved my problem for now without any computer crashes.
One weird thing happened was when I took your suggestion and took the StartTask and StopTask out of the loop, the computer crash problem appeared again.
Anyways I think my problem has been solved, thank you very much for your timely replies and sincere help.
Howard