cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 PWM based on external clock

htrvvrth
Associate

Hey guys, I need your help:

I want to use the STM32F103C8T6 board.

The microcontroller will receive an external 8 MHz clock (from a source other than the system clock).

I want the microcontroller to count to 8, and for 2 of those counts, one of the outputs should be high, and then for the remaining 6 counts, it should be low — this way generating a 1 MHz PWM signal with a 25% duty cycle.

It's important to me that the PWM signal remains in phase with the external source.

Is it possible to achieve this with the STM32F103C8T6 controller? If so how to approach this? Or will I need a different controller to implement this?

3 REPLIES 3

- read the timer chapter in RM

- use a system clock (more precisely, timer internal clock) with significantly higher frequency than the external clock, as the timer is synchronous thus resamples the external clock using internal clock

- connect external clock to TIMx_ETR pin (set as AF) and use the eternal clock mode related to ETR (see TIMx_CR2)

- set some channel to PWM as normally, with ARR=6-1 and CCRx=2-(plus of course set related pin as AF)

JW

 

Hey, thanks for the quick reply!
Wouldn't ARR=6-1 and CCRx=2 give a 33% duty cycle?

And from what I understand from your answer, you mean the STM32F103C8T6 can handle an 8 MHz input and a 1 MHz output with a 25% duty cycle in phase, due to oversampling 9 times with the 72 MHz base clock from the 8 MHz external clock.

How many operations does it take for the timer to operate and turn over, though? (for example AVR328 can reach to +/- 60Khz with 16Mhz clock when used in PWM mode because from my understanding - some CPU operations do occure there )

I mis-typed it: I meant CCRx=2-1.

There is no involvement of the processor here.

JW