LabVIEW Embedded

Showing results for 
Search instead for 
Did you mean: 

LM3s8962, Change PWM frequency on the fly

Go to solution


I am trying to understand how to change a PWM frequency programmatically in real-time. The Elemental IO property node doesn't work or at least I don t know when to call it.

In case you ask why, I want to control a stepper motor. 


Thx in advance.

0 Kudos
Message 1 of 5
Accepted by topic author L._Andrzejewski

Never mind,

Solved by starting the PWM outside of the main loop, using the elemental I/O. Than, inside the main loop, using the elemental IO proprety node, set duty cycle( in hudreds of percent so x100) fallowed by frequency.


Message 2 of 5

I'm using tis board to for stepping motor.


Can this frequency be changed lineary by property node from PWMx (PWM0), selected item frequency? And HOW!


I was trying to do this with the numeric control, by increasing or decreasing the input vaule. The output frequency IS changing, but NOT lineary.

With number 0, the outpus is 0. With number 1, output is active, with low frequency. With number 7 output is also active, with a little higher frequency, and so on....But BETWEN these numbers, output is deactivated...


TNX in advence...

0 Kudos
Message 3 of 5

From NI help:

"Frequency: Sets the PWM output frequency in Hz. The PWM frequency is the inverse of the PWM period. A 16-bit divider from the system clock controls the frequency. For example, if the system clock is 50 MHz, the lowest possible PWM frequency is approximately 760 Hz. If you need a lower frequency, predivide the PWM time base from the system clock. To change the predivider, right-click the Elemental I/O Node in the Project Explorer window and select Properties. This property affects outputs in pairs: 0/1, 2/3, 4/5. For example, if you set the frequency for output 4, you also set the frequency for output 5 because both outputs share a common time base."



Make sure the frequency you request is at least that...

I stopped using the PWM and used a timer with an interrupt to control my stepper, it gave me position and velocity control up to 10kHz... which is way over what a stepper can handle anyway. Allows to precisely  control the number of steps generated.


I don t know how to change the predivide values,you will need to research that.



Message 4 of 5

Can you attach a snippet of your code using the configuration you mentioned.  I am having trouble getting my system to work using a PID controller.  I am interested in what you are using as it may work better in my system.  Thanks.

0 Kudos
Message 5 of 5