cancel
Showing results for 
Search instead for 
Did you mean: 

PWM and Timer Interrupt on STM32F429ZIT6

sultanof
Associate II
Posted on April 19, 2014 at 15:48

Hello,

Excuse my basic question, I really tried to figure this out by reading RM0090 and STM32F427xx/STM32F429xx Datasheet (DocID024030 Rev 3) but I'm just playing poke&hope.

I want to create a PWM and count the rising edges to determine the true number of pulses.

How do I combine which TimerInterrupt with my PWM Configuration?

Part of my experimental code can be found here. It's creating a proper PWM and the timer interrupt is fired with the PWM frequency. Now how can I safely count the number of RISING EDGES of the PWM ?

http://pastebin.com/pZLgMcuH

Regards

Christoph
3 REPLIES 3
Posted on April 19, 2014 at 16:05

APB1 is typically running at DIV4 (42 MHz), the TIMCLK on APB1 is SystemCoreClock/2

The Prescaler used to run the TIM2 at 21 MHz would be ((SystemCoreClock/2) / 21000000) - 1;

What frequency do you want to count at? Very high frequencies will be lost a interrupt as the processor saturates. What does ''Safely Count'' mean?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sultanof
Associate II
Posted on April 19, 2014 at 19:31

Ok I don't know about the clock frequencies. I took the code from the Example ''TIM_PWMOutput'' contained in STM32F429I-Discovery_FW_V1.0.1

I want to count frequencies from 0 to ca. 3500Hz . I want to control speed and position of a stepper motor (maybe 3.5kHz is way to fast... no experience yet). I do not have a position(rotatoin) feedback from the motor so I want to keep track of the steps by counting (assuming I do not loose any, which is fine for my application).

Bitbanging the steppersignals by hand (code) is also an option, but I thought it's more elegant to use the hardware of the controller. This does not neccessariy be PWM ... But that leads to the point that I need an interrupt which corresponds to one rising edge of the pwm signal. And that's where I am lost concering the documentation ... since there is an hardware event (comparison of a register) to trigger a rising or falling edge, my assumption is I can somehow derive an interrupt from the same event ??

Regards

Posted on April 19, 2014 at 22:46

The PWM rising edge should be at ZERO (Update), the falling at CCRx/CCx, these all have interrupts associated. Interupting at 3.5 KHz shouldn't be an issue, try to avoid 100's KHz

If you can use a 16-bit counter for PWM do so, consider if you can loop back the pin to a 32-bit TIM and use that as a pulse counter. (One counting element per TIM)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..