Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous analogue output with regeneration

Solved!
Go to solution

Hi,

 

I'm using LabWindows/CVI and am attempting to output a DC voltage (using regeneration)  to a PXI-6723 output.  The code (very cutdown version) I have written is as follows:

 

 

#define NUM_SAMPLES_TO_WRITE 2
#define ANALOGUE_SAMPLING_RATE = 200;

float64 data[NUM_SAMPLES_TO_WRITE] = {0.0};

DAQmxCreateTask("",&task_handle);
DAQmxCreateAOVoltageChan(task_handle,channel_id, >name,minimum,maximum,DAQmx_Val_Volts, NULL);
DAQmxSetWriteRegenMode(task_handle, DAQmx_Val_AllowRegen);
DAQmxCfgSampClkTiming(task_handle, NULL, ANALOGUE_SAMPLING_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, NUM_SAMPLES_TO_WRITE);
DAQmxWriteAnalogF64(task_handle,NUM_SAMPLES_TO_WRITE,1,10.0,DAQmx_Val_GroupByChannel,&data[0],&no_samples, NULL);

data[0] = 5.0;
data[1] = 5.0;

DAQmxStopTask(task_handle);
DAQmxWriteAnalogF64(task_handle,NUM_SAMPLES_TO_WRITE,1,10.0,DAQmx_Val_GroupByChannel,&data[0],&no_samples, NULL);




 The above code works fine but I am unsure as to why I have to stop the task before writing my new data using the DAQmxWriteAnalogF64 function.  If I don't stop the task, the write function completes successfully but the outputs don't change.  Am I missing something?

 

Thanks

Martin

 

0 Kudos
Message 1 of 5
(3,429 Views)

Hey Martin,

 

You must ensure that the DAQmxWriteAnalogueF64(...) is in a loop during execution, this will continually write data to your analogue output channel, also I wouls strongly reccomend that you use error handels within your code. The best approach would be to use the prebuilt examples as a template from which to build any new source file. The Multi Volt Updates-SW Timed is a good example of this.

Regards

Andrew George @ NI UK
0 Kudos
Message 2 of 5
(3,403 Views)

Hi Andrew,

 

Thanks for the reply.  Although I haven't included it in the code snippet above, my code is littered with error handlers hence I know everything is returning correctly.

 

You mention that I have to continously call DAQmxWriteAnalogueF64 to write data to the analogue output channel but I thought the whole point of regeneration was that you don't have to do that.  Indeed my software actually works perfectly fine by just setting up for regeneration with a call to DAQmxSetWriteRegenMod(...).  The voltage remains on the output indefinitely following a single write to DAQmxWriteAnalogueF64.  The example you have mentioned (Multi Volt Updates-SW) is an example that uses DAQmxWriteAnalogScalarF64() to write single samples one at a time using a software loop.  This is not what my code is achieving.  Cont Gen Volt Wfm-Int Clk is the example my code is based on.

 

My question was and still is, why do I have to stop the task before writing a new value to the buffer before the next call to DAQmxWriteAnalogueF64?

 

Thanks

Martin

0 Kudos
Message 3 of 5
(3,398 Views)
Solution
Accepted by topic author greenstuff

Hey Martin,

 

Apologies I misinterpreted the question; however I believe I have found the answer to your question. When you want to change analogue output levels “on the fly” you should be setting up the output type in non-regeneration mode. This will continually poll the buffer for new data, whilst outputting the previous value. I have found an example which will demonstrate this for you.

 

Example:

 

http://zone.ni.com/devzone/cda/epd/p/id/1733

 

Let me know how you are getting along.

Regards

Andrew George @ NI UK
0 Kudos
Message 4 of 5
(3,390 Views)

Hi Andrew,

 

Thanks for that, the example helped.

 

Cheers

Martin

0 Kudos
Message 5 of 5
(3,358 Views)