Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change Analog output waveform of Ni DAQmx quickly (each 2ms) in vc#

Hi All,

 

I am using USB6215 and want to generate different squar wave frequencies with it.

It works fine when I try to genrate different frequencies up to 40 KHz that I need.

The problem is that the only way that I found to change the frequency from 40KHz to 20KHz, was 

disposing the task and again making new task and write new data to it.

it takes about 55 ms abut I have to do it in less than 2ms because I am simulating a kind of frequency modulation.

the goal is to generate 40KHz, 20KHz and 8KHz eachone for about 1.5 to 2 ms and it will be decided at runtime that which frequency should be generated now.

Do you know how I can do it?

Thanks a lot for your help.

0 Kudos
Message 1 of 3
(1,791 Views)

Hello sorena,

 

You have at least two possibilities, which one to use depends on your requirements:

  • Use a counter task. You could generate a PWM waveform, which is a square waveform. Set the duty cycle to 50%, and then update the frequency every time you want to change it ("Counter Output Frequency").
  • If you need arbitrary waveforms, you are probably looking for "Continuous Generation". It's an output task that you do not stop. You stream a software-generated waveform to your device, it buffers it, and then outputs it at the defined rate. The difference to your current approach is that the device generates the waveform continuously, while you send the "new" data in batches to it. That needs to be fast enough, as you'll get an error the moment the buffer is empty.
    Main question here would be if you know early enough what frequency you need "next".

Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 2 of 3
(1,759 Views)

Hi,

Thanks for your guide but still I have two more questions:

- Can I use the counter task in Analog output? if yes can I update its frequency while the task is 

runing in C#.

- Actually I am struggling with controlling Continuous Generation in C#, whenever after first time I try 

to write data in a task stream by writer object I get error. Do you have any sample source code that

can help me to find it?

Best regards,

Sorena

 

0 Kudos
Message 3 of 3
(1,752 Views)