Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

generate a square wave on analog output

Solved!
Go to solution

I am using a PXI-6229 DAQ card and I need to generate a square wave on ao0.  I am programming in C# and have found a shipping example that generates a sine wave.  I need to be able to modify the function generator that was included with the shipping example to output a 7.2kHz square wave with 50% duty cycle and 2V peak to peak.  I am attaching the function generator code.

 

Thanks

0 Kudos
Message 1 of 9
(7,094 Views)

Hello,

 

Thanks for the details about your application and what you are trying to do. Are you using Measurement Studio, or just Visual Studio? And what version?

 

Are you wanting to generate a continuous pulse train? Or just a single square wave pulse? For generating a square wave using the DAQmx API, I would recommend using the counters on your PXI-6229 to do pulse train generation. Please see this page http://www.ni.com/example/30745/en/.   You can modify this example to operate continuously rather than finitely. 

 

The ouput would not be on ao0, but on the counter output (counter 0 out is PFI 12 and counter 1 out is PFI 13) (https://itp.tugraz.at/~golubk_a/download/temperatur_regelung/datenblaeter/NI-Messkarte/docsource/M_S... ). 

 

Or there is this example (http://www.ni.com/example/27415/en/) that receives a digital trigger on PFI9, which can be retriggered. (See attachments on the right of the page, fourth one down is for C#.)

 

Best regards,

0 Kudos
Message 2 of 9
(7,045 Views)

Hi,

  Thanks for your reply.  Unfortunately I cannot use the CO since I do not have a choice as to where the output comes from.  The hardware was designed long before I received it and the designer who is no longer on the project designed a PWB that uses ao0 as the output for the square wave.  Is there an example to generate a square on ao0 using C# .net?

0 Kudos
Message 3 of 9
(7,035 Views)

paofthree,

 

Is the shipping example you found located in C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.5\Analog Out\Generate Voltage\ContGenVoltageWfm_IntClk\CS ? I attached this example.

 

I thought that the one entitled ContGenVoltageWfm should be able to be changed to square wave on the MainForm.cs [Design] UI, but for the life of me I can't get it to work. With your hardware configured, can you please try to use this example and change the input to this control to be square instead of sine?

 

Here is some information about an enum in C# .. http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/b4611bb5/  ... http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/9767dfc8/

0 Kudos
Message 4 of 9
(7,007 Views)
Solution
Accepted by topic author paofthree

After a lot of trial and error and adapting the example for generating a sine wave I have the solution for generating a square wave from analog output.  I am attaching the code.

0 Kudos
Message 5 of 9
(6,883 Views)

I'm glad to hear that you got it working. Thanks for posting your code.

0 Kudos
Message 6 of 9
(6,846 Views)

in the attached file, what is the parameter to specify the dutycyle?

0 Kudos
Message 7 of 9
(6,101 Views)

Thanks paofthree for your code. In the attached file, what is the parameter to specify the dutycyle?

0 Kudos
Message 8 of 9
(6,082 Views)

Sorry for the delay in replying.  The duty cycle is 50% so I did not bother having a parameter for it.  It is taken care of by the point generating function.

0 Kudos
Message 9 of 9
(5,754 Views)