Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate sine waveform (myRio)

Solved!
Go to solution
What is the best way to generate a 1khz sine signal on one of the analog outputs of the myRio device? I tried a timed loop and the Point by Point Sine Generation VI similar to the Electret Microphone demo or this post: http://forums.ni.com/t5/Academic-Hardware-Products-ELVIS/frequency-matching-problem-with-myrio/m-p/2... by Sammy_K. But the resolution is a problem. The frequency is not very accurate and with a dt of 100 uS and a 1Mhz Clock I only get 10 samples per period. A dt of 10 is too much load for the processor (the deivce does not respond anymore and needs to be restarted). Is there a better way of generating a 1khz sine output or do I need to do this within the FPGA somehow?
0 Kudos
Message 1 of 11
(19,323 Views)
Solution
Accepted by topic author JulianR

Hi Julian,

 

The best and most performing way to generate a sine wave with the myRIO is to do it with FPGA. The onboard FPGA works completely in parallel and wouldn’t need some CPU resources.

The 2 following links should help you to generate a sine wave on the analog output from myRIO.

 

SineWave Generation using LabVIEW FPGA

https://forums.ni.com/t5/Example-Code/SineWave-Generation-using-LabVIEW-FPGA/ta-p/3996177

 

myRIO FPGA Sine Wave Sound Output

https://forums.ni.com/t5/Example-Code/myRIO-FPGA-Sine-Wave-Sound-Output/ta-p/3505365

 

If you still have troubles to generate the sine wave, you can send us your VI so that we can help you further.

 

Regards

 

Marc O.

Application Engineer

NI Germany

 

 

0 Kudos
Message 2 of 11
(19,284 Views)

Hey JulianR,

 

The thing to keep in mind is that each time you call the Analog Write express VI you write one data point to the analog output on the myRIO.  The rate at which data is output is determined by the rate at which you loop runs.  You can use a timed loop in LabVIEW to write analog output values at a relativly fixed loop rate and vary the value to generate a sine wave output.

 

I put together an example of doing just this (but using the value to set a PWM duty cycle rather than analog output) in this thread.  You'd basically need to replace the PWM express VI with the Analog Output Express VI.

 

Finally as Marc67 mentioned you could implement the sine wave output in LabVIEW FPGA which would give you more control and let you use faster output frequencies.  I'd start with the timed loop method and move to FPGA if you need faster output rates.

 

Let us know if you have more questions for us.

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 3 of 11
(19,259 Views)

Hello Marc67, hello Sammy_K,

 

As I said before the timed loop is not fast enough to generate a clean 1khz sine signal, so I implemented this functionality with the FPGA and attached my solution. I didn't choose fixed point arithmetic for a reason. Using only integer values (apart form the frequency) I won't loose any accuracy. The frequency and amplitude don't have to change very fast (or at all after initialization) so I can calculate these within my RT Vi.

myRio-Sine.PNG

0 Kudos
Message 4 of 11
(19,241 Views)

just to clarify, if you use fixed point, you don't neccesarily lose accuracy.  you do have to be careful with the sizes of intermediate values etc but fixed point numbers are just integers at heart.

Stu
0 Kudos
Message 5 of 11
(19,221 Views)

What Stu said. Fixed-point should be generally more accurate and cheaper than integers becasue it gives you more control over output widths and rounding modes. In your example above, you have to jump through hoops to sign extend the integers in order to do a fully multiply, then truncate the result by scaling down. With fixed-point, you could do that more efficiently in a single multiply by simply wiring 16-bit input types and overriding the output to the desired width and rounding mode.

 

Jim

0 Kudos
Message 6 of 11
(19,215 Views)

Hi Marc67,

 

The first example you gave is using PXI how could I use it on Myrio?

 

Regards

0 Kudos
Message 7 of 11
(19,127 Views)

Hi CZ_Kevin,

 

You can resuse the FPGA VI on several different targets. You will just need to adapt the I/O and the clocks.

 

Marc O

Application Engineer

NI Germany

0 Kudos
Message 8 of 11
(19,110 Views)

Hi Marc67,

 

I tried to make some change on the first example to make it fit myrio. But I really do not konw how to do it. It seems like some functions in PXI are using different data type from myrio functions. So just by changing the functions it still not work. And some of the funcions like SinescaleProp.vi can not be found.

Could you show me a little bit how to make it fit in myrio in detail?

 

BTW, In the second example why the Audio output is used? I tried to change that to Ao but it did not work. I can not get a Sine Wave from Ao. Could you tell me the reason?

 

Thank you.

 

Regards


CZ

0 Kudos
Message 9 of 11
(19,092 Views)

Hey,

 

I am kind of completely new to Labview and i want to program with a myRio. I have the same problem as CZ so maybe there is already a solution now.

What do I have to do to generate a sine or any periodic Signal  and output it on the AO? The examples with FPGA and the Timed Loop didn't not work for me. Does anybody have a solution for this at myrio?

Thank yo very much in advance

 

Kind Regards
Rob

0 Kudos
Message 10 of 11
(17,873 Views)