From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

frequency matching problem with myrio!!

Solved!
Go to solution

I am so sorry for making you confused.

 

okay, let me make sure about my question. I misunderstood your statement above. 

 

I definitely can generate PWM with fixed duty cycles with using PWM express VI.( It was very easy.) However, I want to generate sinusoidal PWM. Sinusoidal PWM (Sine PWM). I thought sinusoidal PWM has fixed duty cycle but, it is not.(it was my mistake.. sorry again.) I’d like to know if there is any way to generate a sinusoidal PWM output using myRIO with a PWM frequency of about 40 kHz.

 

Thanks.

0 Kudos
Message 11 of 30
(10,936 Views)
Solution
Accepted by topic author nim21kr

Alright, I threw something together quickly.  I think this is close to what you're asking for.  Let us know if it helps / makes sense (there are probably better ways to do this but this was the first thing I thought of).

 

0.PNG

 

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

Message 12 of 30
(10,930 Views)

0.PNG

Thank you for your supports.

I checked this signal with oscilloscope and it seems okay. however, I don't understand what you did in some parts.

 

my questions are..

 

1)Theoretically, sine PWM is generated by comparing Sine signal and Triangle signal. So, in your way, the outer frequency(Freq I32 on the above the picture) is the frequency of sine signal and the inner frequency(PWM freq) is the frequency of triangle frequency. am I right?

 

2)could you please expain why dt divided by source clock and what is the "seconds / Tick" ? I don't understand this part in timed loop.

 

3)why do we need increment of 1 from result of sine wave(on the above picture) and divided by 2 for the Duty cycle? could you please expain me how does it work?

 

 

your application seems very helpful and I am looking forward your reply. Thank you very much.

 

0 Kudos
Message 13 of 30
(10,920 Views)

Hey nim21kr,

 

I look at the problem from a software standpoint because that's my background, so while you could do this by mixing two signals I won't go into that.

 

So we want a PWM output with a sinusoidal duty cycle and fixed frequency.  We can do this by calling the PWM EVI in a loop.  Each time the loop iterates it calls the PWM EVI and sets a new duty cycle (0-1).  We need to calculate the duty cycle so that it ends up being sinusoidal.  To do this we need to know how much time has elapsed to calculate the 'current' duty cycle at the instant the loop executes.

 

A timed loop running on myRIO is deterministic, which means it will execute at the rate we specify and it can 'trump' other processes of lower priority to execute at the rate we specify.  In the screen shot above the loop is timed off of a 1MHz clock and executes once every 1000 (dt in the screen shot) clock ticks.  So we know that we get one loop execution per 1M / 1K clock ticks.  I added these as constants and did the math on the VI so that you can change it easily.

 

Ok so we know how much time has gone by.  Now we need to generate a sine output based on that and a user specified frequency.  LabVIEW has a sine function that calculates the sine of a number.  So I want to increment a number each loop iteration so that I can take the sine of it and get my duty cycle.  By taking 2pi * the time per loop iteration * the user specified frequency I get amount I need to increment my running total each time to get the correct frequency.  I use shift registers to store this number and generate a running sum.  

 

My running sum is passed into the sine function and give us a -1 to 1 value.  I increment the value to shift it to the 0 to 2 range, then divide by 2 to scale it to 0 to 1 which matches the duty cycle input.

 

This was more complicated than I originally hoped, and there may very well be a better way to accomplish this..The above example is just the first thing I thought of.

 

Let us know if you have questions about this.

 

Thanks!

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

Message 14 of 30
(10,916 Views)

Thank you very much your specific explanatoion!!!!

 

It is very helpful to understand your code!

 

Can I ask further and fundamental questions about some part?

 

 1)

According your saying, the loop is timed off of a 1MHz clock and executes once every 1000 (dt in the screen shot) clock ticks. how can we define the the loop executes once every 1000 clock ticks. I think I don't have enough background about "ticks" concept in Labview. is this mean that unit for number of running in every clock in the loop? So, do I need a "tick" in every time when the timed loop is running? and How 1Mhz and 1000dt clock ticks are defined?( which means that we can just specify them?)

 

2) 

In order to my duty cycle from sine function, why do we need to take 2pi * the time per loop iteration * the user specified frequency? According to your saying, it is necessary to get the correct frequency for running total each time. However, it is not clear to me. Could you please explain me more detail? Moreover, the function of "shift registers" is to store the number and to generate a running sum? Could you please explain about this spsecifically?

 

Your code was impressive to me. however, my background is not programming and I am not a advanced labview programmer so that your code seems little bit complicate to understand for me. Even though that, I really appreciate your consideration and support.

 

Thank you very much!

 

0 Kudos
Message 15 of 30
(10,906 Views)

Hey nim21k,

 

Lets compare the LabVIEW While Loop and Timed Loop.  

 

The while loop executes as fast as it can until you stop it.  'As fast as it can' is determined by the operating system's scheduler and will be affected by other things running on the system.  Therefore a while loop is non-deterministic because the rate at which it executes changes.  For example if the OS (Windows) decides something  else is more important (maybe  a virus scan) the LabVIEW loop will get less CPU time and execute 'slower'.

 

Timed loops, on the other hand and designed for use on Real-Time Operating Systems (RTOS) and allow you to very accurately specify the rate at which they execute and even their priority.  The RTOS (NI Linux Real-Time on myRIO) is designed to execute tasks deterministically, meaning it tries to guarantee timing on when things will execute.  When you place a timed loop you specify a time source and a dt.  The time source is a clock.  In the example above I used a 1MHz source which means I have a clock that generates 1 tick per uS.  I set the dt to 1000 which means that every 1000 ticks I want my loop to run, therefore my loop should run once ever 1000 ticks = once every 1000 uS = once every mS.  You can configure the timed loop by double clicking on its 'ears' (the blue bit to the left of the loop) or by passing in parameters (this is what I did in my example above).

 

Timed loops allow you to execute tasks at a very precise, fixed interval, but only work well on deterministic operating systems such as those used on NI Real-Time targets (but not Windows, Mac, or Desktop Linux).

 

Let us know if that makes sense or if you have more questions.

 

Thanks!

 

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

Message 16 of 30
(10,899 Views)

0.PNG

 

I really appreciate your detail explanation. I have further questions.

 

1) is the "blue" frequency above figure, representing the sampling frequency?  when I decrease the value of "blue" frequency, the sampling is seemed to be increased. so, the best value for accurate waveform in oscilloscope is 1 , right? if not, could you explain me the function of the "blue" frequency?

 

2) Could you explain me about what is the "running total" above figure? My understanding is that this is just initial value to make a running sum. if so, can I make a shifted PWM signal?

 

3) As I mentioned question 2), now I am designing to TWO different PWM with TWO digital output and the one is "phase shifted". What I implemented is that I put the "pi" ,mathematical value, instead of "running total" so that I expected the another signal would be shifted by 180 degree. However, The result on the oscilloscope did not show me the phase shifted one like what I expected. Could you give me any advice about how can I generate the shifted signal?

 

Thanks

0 Kudos
Message 17 of 30
(10,877 Views)

Hey,

 

The Frequency control allows the user to specify the duty cycle frequency.  Basically if you specify 5 in the Freq control the duty cycle will go from 0 to 1 back to 0 sinusoidally 5 times per second.  The actual rate at which the duty cycle is updated (changed) is determined by the timed loop rate.  In this case the duty cycle is updated every 1000 ticks of the 1MHz clock so once every 1 mS we update the duty cycle to a new value determined by the math inside the loop.

 

The running total starts at 0 and is used to generate the sine value.  As time increases the running total increases by an amount determined by the frequency.  This allows us to take the sine of the running total to generate the correct duty cycle output.

 

I assume you mean you are using two PWM blocks, not two digital outputs.  For the phase shifted one you should be able to take the value going into the sine block, add your offset (pi for example) and do the same calculation (sine then +1, then divide by two) and pass that number into the other PWM duty cycle.

 

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

Message 18 of 30
(10,867 Views)

Hi, 

I try to change the pwm function to the analog out using the channel of the audio output. But I did not get anything after I connect Myrio to a oscilloscope. Could you tell me why? And what should I do to fix that?

 

0 Kudos
Message 19 of 30
(10,805 Views)

Hey CZ_Kevin,

 

In general you should start a new thread if you have a new question.

 

That being said the hardware hardware on the analog vs digital pins is different so you cannot use an analog pin for a a digital function or a digital pin for an analog function.

 

 

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 20 of 30
(10,801 Views)