cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Frequency Change On the Fly

Rogers.Gary
Senior II
Posted on September 09, 2016 at 02:43

I'm using an STM32F4 to generate PWM pulses. I need to do something a bit difference, the best way to describe it is like FSK ( frequency discontinuity not a problem if it occurs)

For example - if one was looking at sequence of 10 pulses, the first 5 are at T = 2ms (500hz), and the next 5 are at T = 1ms (1Khz) I would want to see the frequency change occur at the interval between the start of the 5th pulse and the start of the 6th - where that delta would be 1ms.

Hoping that someone provide a basic algorithm (or even a code example) on how to accomplish this. Interrupts? Timers? Any help is appreciated,

Thanks!

2 REPLIES 2
Posted on September 09, 2016 at 09:09

Change both TIMx_ARR and TIMx_CCRy to half of their previous value. Have both TIM1_CR1.ARPE and TIMx_CCMRx.OCyPE set so that both ARR and CCRy are shadowed; then the new values get loaded from shadows into the actual ARR and CCRy registers at the same moment at the next update event.

An even simpler way is to change the prescaler in TIMx_PSC.

JW

Walid FTITI_O
Senior II
Posted on September 09, 2016 at 13:24

Hi oofie01,

You can achieve that using the Timer DMA burst feature. I invite you to a new application note ''GP Timer Cookbook''

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/91/01/84/3f/7c/67/41/3f/DM00236305/files/DM00236305.pdf/jcr:content/translations/en.DM00236305.pdf

which contains user-cases example and theoritical explanation. Chapter 5 ''Arbitary waveforms generation using Timer DMA-burst'' descibes how this feature allows to modify on the fly the waveform outputted by a timer peripheral. The relevant firmware is inside the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-software/x-cube-timcooker.html

packge.

-Hannibal-