LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange behaviour using simulate signal block to generate sine wave

Solved!
Go to solution

Hi,

 

I am trying to generate a simple 50 Hz sine wave from MyRio using a "simulate signal" block. The sinewave signal is generated from the Analog Output, reads it through the analog input, and shows it into a waveform chart.

 

Unfortunately, I got a strange behavior when setting the frequency to 50 Hz. The output seems flat, but it goes to sinusoidal again when I reduce or increase the frequency to 49 and 50.

 

So, what's make this strange behavior? Is it related to my block parameter/setting?

 

*I have tried building a sine wave generator using the mathematical function, and it worked perfectly without any strange behavior.

 

 

Download All
0 Kudos
Message 1 of 8
(1,405 Views)

Can you please compress the folder holding the entire myRIO Project and attach the resulting .zip file?  Are you plugging an Analog Out signal into the myRIO's Analog In port?  Which ports on the myRIO are you using?

 

You mention simulating a signal block.  It's not clear what you mean by "simulate" -- aren't you generating a signal and (almost simultaneously) sampling it?

 

In looking at your Express VI, it looked like the number of samples being put out and read in was 1 sample at a time.  If you attach your Project, we could look at (all) the details, and maybe even run it on a myRIO and really "see what you are seeing".

 

Bob Schor

0 Kudos
Message 2 of 8
(1,380 Views)

Hi Bob,

 

I attached the following zip file for the project.

 

Are you plugging an Analog Out signal into the myRIO's Analog In port?  Which ports on the myRIO are you using?

- Yes, I'm plugging directly from the AO0 (pin 2) to AI0 (pin3)

 

You mention simulating a signal block.  It's not clear what you mean by "simulate" -- aren't you generating a signal and (almost simultaneously) sampling it?

- So, Simulate signal block refers to the Express VI (sine wave block) that I used to generate the sinewave. The output of the block is connected to the AO0 and it's "hardwired" to the AI0 using a cable.

 

Thanks,

rwastuw

0 Kudos
Message 3 of 8
(1,361 Views)

Hi rwastuw,

 

oh wonders of using ExpressVIs and DDT wires…

 

Your SimulateSignal ExpressVI is set to create a sine wave with a sample frequency of 10kS/s containing 1000 samples. Your AO ExpressVI is set to output just one (1) sample.

 

What kind of output do you expect when you output just 1 sample out of 1000 samples?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(1,348 Views)

@GerdW wrote:

Hi rwastuw,

 

oh wonders of using ExpressVIs and DDT wires…

 

Your SimulateSignal ExpressVI is set to create a sine wave with a sample frequency of 10kS/s containing 1000 samples. Your AO ExpressVI is set to output just one (1) sample.

 

What kind of output do you expect when you output just 1 sample out of 1000 samples?

 


Please correct me if I'm wrong, but does this mean that the OP is (probably) accidentally aliasing the signal before outputting it?

I.e. the reason 50 Hz looks like a flat line is because "1000 mod 50" equals "0", so that the (one) voltage sample being output each 1000 samples happens to be the same voltage each time it is output?

-joeorbob

0 Kudos
Message 5 of 8
(1,318 Views)

Hi JoeOrBob,

 

yes.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(1,316 Views)

Hi Joe,

 

Thank you for your explanations! Now it makes sense.

 

Let me try to break down the process.

Firstly, If I generate 50Hz sinewave with 10k samples per sec and 1knumber of samples settings, I generate the 1000 sample to make the 50hz wave in one loop. Then, my analog input acquires one sample during that loop. So that's why I always get the same data in the next loop and after. cmiiw.

 

So, to overcome this problem, I should put the analog input into separated timed loops with the "dt" is faster than AO loops?

0 Kudos
Message 7 of 8
(1,288 Views)
Solution
Accepted by topic author rwastuw

Particularly when you are working "fast" (like 10k  samples/sec), you don't want to do things "one-at-a-time", as your loop will "spin" very rapidly, and you'll have to do a lot of processing on single elements.

 

A more sensible thing to do (which you, in fact, do when generating the data) is to do things in "chunks", say 1k elements at a time.  Now you need to only handle 10 iterations/sec, and are working with an array of elements (instead of single elements).

 

So why not do the same thing when you sample?  Instead of reading elements 1 at a time (which you need to do at a 10 kHz rate), why not read 1000 points at a time?

 

Here's a suggestion -- do a Web search for "Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications" (I might have a word or two wrong there).  See how easy it is to use native DAQmx functions (instead of relying on the Dreaded DAC Assistant, and its evil cohort of Express VI Functions and the awful Dynamic Data Wire).  It will go much better for you ...

 

Bob Schor

Message 8 of 8
(1,277 Views)