Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate Biphasic Signal using C++

Is it possible  to generate a continuous biphasic analog signal on a PCI-6229 using DAQmx 8.0 and C++ programming language?
I want to be able to modify the amplitude, frequency and duty cycle, without stopink the task.
A sample signal would look like 10V for 2 ms, -5V for 4ms and 0v for 494ms.
 
Thank you !
 
 
 
0 Kudos
Message 1 of 7
(4,052 Views)
Hi sspeed,

Take a look at the DAQmx ANSI C Example located at C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog Out\Generate Voltage\Cont Gen Volt Wfm-Int Clk

To change the signal programmatically as the task runs, you will need to use the DAQmxSetWriteRegenMode function (before DAQmxCfgSampClkTiming) to tell DAQmx not to allow regeneration (DAQmx_Val_DoNotAllowRegen). This requires you to continue to write more samples to the buffer while the task is running, which is exactly what you need to do to write different amplitudes, frequencies, etc.
--
Michael P
National Instruments
0 Kudos
Message 2 of 7
(4,044 Views)

Thank you for your help!

The method it's working just fine for an internal clock.

In my application I have to use external clock(100Hz to  10 kHz) to generate this signal.

In this case to have the frequency that I want at different clock frequency I am using an 10000 elements buffer and dependent on the clock frequency I am writing the number of values that I need.For this I choose to manually allocate the output buffer.

I am using a PCI-6229 acquisition board , Borland C++ Builder 6.0 and this is the code I am using to initialize the task:

ErrChk(DAQmxCreateTask("",&GenStim));
ErrChk(DAQmxCreateAOVoltageChan(GenStim, "/Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
ErrChk(DAQmxCfgSampClkTiming(GenStim,"/Dev1/PFI12",10000,DAQmx_Val_Rising, DAQmx_Val_ContSamps,1000));
ErrChk(DAQmxSetWriteRegenMode(GenStim, DAQmx_Val_DoNotAllowRegen));
ErrChk(DAQmxCfgOutputBuffer(GenStim,10000));
ErrChk(DAQmxWriteAnalogF64(GenStim, 10000,0,10,DAQmx_Val_GroupByChannel,AOBuffer, &written,NULL));

When the last line is executed I get an "Invalid Floating point operation".

If I change the value from 10000 to 1000 the application works fine, but for clock frequencies bigger than 1000Hz I need to write more than 1000 Values.

Any Help is Greatly Appreciated.

Bogdan Mitrea

 

 

0 Kudos
Message 3 of 7
(4,020 Views)
Hi Bogdan,

See the KnowledgeBase articles linked below for information about the issue you are experiencing.

How Can I Use The NI-DAQmx ANSI C Function Library With Borland C and Delphi?

Can I Make NI-DAQmx Calls From Borland Delphi?
--
Michael P
National Instruments
0 Kudos
Message 4 of 7
(4,018 Views)

Thank you for your quick answer.

I am using NI-DAQmx 8.0 and as it states in the knowledge base this issue must be fixed.

I am using this board for a while with NIDAQmx 7.4 up to 8.0 and Borland C++ and I never had any problems with it.It is true that this is the first time when I am trying to manually configure the output buffer.

The lib file that I am using was obtained from the standard NIDAQmx installation file after I applied coff2omf command to make it compatible with Borland C++.

I also tried the Borland compatible file that is available for download on your website but the effect is the same.

I will try that code in Visual C++ 2005 just to be sure that is nothing wrong with it.

Thank you again for your answer.

Bogdan Mitrea

0 Kudos
Message 5 of 7
(4,013 Views)
Hello again.
I managed to solve the problem I wrote about in my last post.It was nothing wrong with DAQmx and Borland C++.It was just my code.Smiley Happy.
Now I have another one.
As I said before I am generating an analog signal and I am using external clock.That clock varies between 500Hz and 10kHZ.
To have everything covered I am using a 10,000 samples buffer.The values in the buffer are rescaled everytime when the clock frequency is changed.The problem is that whenever I change the clock frequency the samples are generating faster(If I change to a heigher frequency) or slower(if I go to a lower frequency) for a period of time than everything goes back to normal. My understanding is that there are some values in the circular buffer that had to be written befor the new ones.
 
My question is : Is there any way that I can reset(empty) the circular buffer or I have to stop and restart the Task.
 
Thank you.
 
Bogdan Mitrea
 
0 Kudos
Message 6 of 7
(3,995 Views)

Bogden,

I think the problem you are having, is exactly what you described. Unfortunately there is no way to dynamically change that buffer size during the acquisition on the fly, which is what you would need to fix that problem. So you will have to stop the task, resize it, and then start again. Hope that will work for you.

-GDE

0 Kudos
Message 7 of 7
(3,984 Views)