Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling analog out timing from myRIO MSP ?

Solved!
Go to solution

Hello,

I'm new to myRIO and have just received mine.

 

How can you set the rate of analog out samples from the MSP port of a myRIO ?

For example, I wish to output an analog stream at 200ksps.

 

Placing the ANALOG OUT block in a timed loop and running only gives an output rate of 6.3kHz. (measured at the ao1 using a scope)

See the attached file.

 

Am I using the timed loop incorrectly ? (...havent used them before)

Or does myRIO needs some extra setup ?

 

Thanks for any help with what seems like a very simple problem.

 

Cheers.

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 1 of 10
(8,943 Views)

Hey carloman,

 

When you place a timed loop you'll need to configure its timing source and dt.  I'll assume you've done that already, but I just posted some info on how to do that in this thread (post 16).

 

I would start slowly to make sure you understand the loop configuration.  Try to output at 1KHz, then 5KHz and make sure that works as you expect.

 

 

200Ksps is getting pretty fast.  If you're running your code interactively (clicking the run arrow in LabVIEW) then the myRIO spends a lot of CPU time pipeing data from myRIO back to your desktop to update the front panel.  The loop rates will greatly increase if you build the LabVIEW application into an RT EXE and deploy it to the myRIO.  This strips out the front panel and lets the myRIO focus on running your code without worrying about updating the front panel.

 

If you still want to 'see' data from the myRIO you can create a host side VI that runs on your desktop and use shared variables or network streams to send data back and forth.

 

Another way to improve the loop rate is to use the myRIO advanced IO VIs rather than the express VIs to open the channel outside the loop, write as fast as you can in the loop, then close the channel after the loop.  This reduces some of the checking done by the EVI and should give a performance boost.

 

Let us know if that helps or if you have more questions.

 

Thanks!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 2 of 10
(8,939 Views)
>>>HI Sammy, Thanks for your reply.
My questions are below >>>>
@Kristoff2 wrote:

Hey carloman,

 

When you place a timed loop you'll need to configure its timing source and dt.  I'll assume you've done that already, but I just posted some info on how to do that in this thread (post 16).

 

I would start slowly to make sure you understand the loop configuration.  Try to output at 1KHz, then 5KHz and make sure that works as you expect.

 

>>>OK , have it working at 2k, but when I try for 10k it outputs only 5kHz.

I've set up timed loop correctly I think..see attached. Ultimately I need to run at 200k.

 

200Ksps is getting pretty fast.  If you're running your code interactively (clicking the run arrow in LabVIEW) then the myRIO spends a lot of CPU time pipeing data from myRIO back to your desktop to update the front panel.  The loop rates will greatly increase if you build the LabVIEW application into an RT EXE and deploy it to the myRIO.  This strips out the front panel and lets the myRIO focus on running your code without worrying about updating the front panel.

 

>>>DACs are spec'ed at 345ksps. The myDAQ DACs run an equivalent of this program at 200ksps...so Im thinking the ao1 from MSP should be able to run at 200ksps...its just a matter of getting it setup correctly.

I dont have anything on the front panel (though perhaps that doesnt matter) and Im only interested in ouputing to the myRIO at this stage.

>>>I tried to create an RT exe in project  Explorer...it deployed but still ran the same ie: at 5k instead of 10kHz.

 

If you still want to 'see' data from the myRIO you can create a host side VI that runs on your desktop and use shared variables or network streams to send data back and forth.

 

>>>I dont have that need inthis application.

 

Another way to improve the loop rate is to use the myRIO advanced IO VIs rather than the express VIs to open the channel outside the loop, write as fast as you can in the loop, then close the channel after the loop.  This reduces some of the checking done by the EVI and should give a performance boost.

 

>>>yes, i tried that ..pls see attached...same result.

 

>>>Any more insights into how to set this up would be most appreciated.

>>> carloman

 

 

Let us know if that helps or if you have more questions.

 

Thanks!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+


 

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
Download All
0 Kudos
Message 3 of 10
(8,928 Views)

Hey carloman,

 

You're code looks good.  I benchmarked something similar a while back and was able to get a 60KHz loop rate.  Keep in mind each loop iteration only writes one sample, so the loop rate we're talking about is not the same and the output signal frequency (for example a 60KHz loop rate woul only be able to generate a sine wave of about 20 KHz or less).  How are you measuring your loop rate?

 

The way myDAQ works (and NI DAQ in general) is much different than the way RIO devices (including myRIO) work under the hood.  The spec of 200Ksps is for the hardware.  You can easily achieve this rate using LabVIEW FPGA but there is some overhead involved when using RT VIs.

 

You'll need to build the RT exe and have it run at startup (not sure if I was clear on that before).  More info here.

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 4 of 10
(8,913 Views)
Hi Sammy,
>>>Thanks again.
>>>Some more questions though.

How are you measuring your loop rate?

>>>Im viewing the analog out signal at ao1 with a scope, and I can confirm the update rate per sample is around 5ksps....not the 10ksps I set up as the dt value. 

 

 

The way myDAQ works (and NI DAQ in general) is much different than the way RIO devices (including myRIO) work under the hood.  The spec of 200Ksps is for the hardware.  You can easily achieve this rate using LabVIEW FPGA but there is some overhead involved when using RT VIs.

 

You'll need to build the RT exe and have it run at startup (not sure if I was clear on that before).  More info here.

 

>>>OK, I followed the link instructions to buld a Source distrib, as well tried building a Real Time Application, and deployed them and ran as startups. All seemed to go OK, but the output signal is still 5kHz.

 

>>>Is there any thing else that needs to be done to the myRIO FPGA to achieve faster rates ?

>>>Im sure it can run much faster...just not familiar with RT setups.

>>>Have you had a chance to actually run my code on a myRIO and see if it goes at 10kHz for you ?

 

Thanks again,

carloman

 

 


 

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 5 of 10
(8,898 Views)

I made some modifications to your code to show how you can benchmark code in LabVIEW.

 

First is the RT VI.  I use a flat frame sequence with a tick count, then the code to benchmark (in this case the AO loop) then another tickcount.  I calculate the loop frequency based on the time it took to run 5000 iterations of the loop.  The first (or first few) are usually a bit slower since other things are starting up on the myRIO so I put the entire thing in a loop to run forever.  I use a shared variable to pipe this data back to a host side VI (see below).  When I run this interactivly I get a loop rate of about 20KHz.

 

0.PNG

 

Here is the host side VI to read the loop rate.

 

1.PNG

 

 

Since I already have a host side VI and I'm not relying on the interactive mode to view data I can easily build the RT side into a startup exe.  I added an item under the Build Specifications section under the myRIO target, added the RT Main VI as a source VI and build an RT exe.  Then I right click on the build spec and choose run as start up.  I this case I'm still getting about 20KHz because there weren't really many things that the compiler could optimize out (ie no controls / indicators).

 

I added RT Main 2 and just replaced the EVI with Advanced IO VIs.  I got about the same loop rate when running interactivly (maybe 10% faster).  This sort of surprised me...then I realized what was happening.

 

When you use a timed loop you're basically telling the operating system scheduler that you want your loop to run on every nth tick of a given clock.  So lets say I want my code to execute on the 5th tick of a 1MHz clock.  That means I want it to run once every 5 uS, but in this case the code takes slightly more than 5 uS to execute so I starts on the tick 0, but isn't done executing by tick 5...maybe the first execution is done by tick 16.  In this case the loop misses a few iterations and then has to wait 4 ticks until tick 20 to start again.  The same thing happens every iteration and even though our code takes about 16 ticks to execute it only runs once every 20 ticks.  These are made up numbers, but this is what is happening.

 

I changed RT Main 2 to use a while loop, which runs as fast as it can and is not tied to a clock tick.  I now get ~60KHz loop rate when using Advanced IO VIs interactivly.

 

Sorry for the long post, but this is something good to know about Real time operating systems and timed loops.  I'm sure you'll have questions about this so ask away!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

 

Message 6 of 10
(8,879 Views)

Hi Sammy,

Thanks for your long post and the example project.

I have built, deployed and run it as startup and I can replicate the 54kHz results you mentioned.

 

I modified the RT Main 2.vi so that it output random data to ao1 of Port C and Ive attached a screenshot showing it working.

 

Finally, my question is...can we make this run at 200ksps ?

What is limiting the execution rate to 53kHz ?

Of course a RT app run locally on the myRIO can run extremely fast, however when it needs to get data from LabVIEW running on the host does this set an upper limit on the data transfer rate, which is below that of the host PC itself ?

 

Thanks again for your efforts and any further insights,

Regards,

carloman

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 7 of 10
(8,859 Views)
Solution
Accepted by topic author carloman

Hey Carloman,

 

The speed in this case is limited by the software (OS, background processes and mainly the the LabVIEW code) running on the ARM CPU on the myRIO.  The 200 Ksps spec is for the hardware.  If you need to write this fast you'll need to use LabVIEW FPGA to write data. 

 

One of the reasons it's hard to hit the 200 Ksps output rate from the RT side is because each loop iteration only generates 1 sample (the FPGA is configured for single point output...one sample at a time).  The ideal way to generate samples from the RT side and write the data out at 200 Ksps is to generate multiple samples each loop and use an FPGA personality that supports buffered analog output.  This would allow you to generate N samples every loop iteration and then send the samples to an FPGA buffer (FIFO) that buffers and outputs the data.  I believe this is coming in a future software update.

 

For now you could implement this architecture by creating a custom FPGA personality or you could do everything in LV FPGA.

 

Let us know if that makes sense.

 

Thanks!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 8 of 10
(8,854 Views)

Hi Sam,

 

OK, this answers my questions.

So I shall make do with the 50k sample rate, until a new update releases multiple sample/buffered output capability (which myDAQ currently has).

 

Or I can create that myself using LV FPGA..which sounds tricky but may be worth looking at later.

 

Thanks for your help,

 

Cheers,

carloman

===============================================================

Take a look at DATEx, FOTEx, HELEx & SIGEx add-in trainer boards for NI ELVIS 1,2 & 2+ and DXIQ, ESSB for NI ELVIS III and myDSP for myDAQ to learn Wireless Telecoms, Signals & Systems, Fiber Optics and Green Energy principles (www.emona-tims.com)
0 Kudos
Message 9 of 10
(8,840 Views)

Hey Carloman,

 

LV FPGA makes FPGA pretty easy and there are a lot of great tools build into LabVIEW Real-Time and LabVIEW FPGA to make communication between the RT application and the FPGA easy.  The Compact RIO Developers Guide contains a lot of great information on developing for NI RIO systems (including myRIO).  Check out the sections on 3 and 5 on RT development and FPGA development.

 

Getting familiar with LabVIEW FPGA opens up a ton of new possibilities and the best part is all the skills you build with myRIO directly apply to all NI RIO targets including industry level targets.

 

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 10 of 10
(8,828 Views)