How I could set freq of timer 3 to 102.4Hz

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
raulvalencia
Posts: 6
Joined: Wed Jun 01, 2016 12:53 pm

How I could set freq of timer 3 to 102.4Hz

Post by raulvalencia »

Happy new year 2017 everyone,

I'm working on a stm32f401re nucleo board and I would like to configure the timer 3 to trigger my adc (trgo) with a frequency of 102.4 Hz, currently modifying pll and prescaler I have a freq of 102.5 Hz (why this frequency ?) in addition it is not stable .

I changed the PLL to work with 64 Mhz because this frequency is multiple of 1024, so of 102.4

Can anyone give me a "track" to set the timer?



Last year I worked with a cpld maxII and to use a CLK was very easy ... but now ...

Thanks in advance,

Raul
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: How I could set freq of timer 3 to 102.4Hz

Post by RoccoMarco »

Hi TIM3 is a 16-bit timer. You cannot reach that frequency since requires a divider of 64000000/102.4 which is 625000 (not reachable with 16-bit precision). Check if ADC could be triggered with TIM2 or TIM5 which are 32 bit timers.

Another way is to internally connect two timer (in this way one will be the prescaler of the other). I never had to solve a problem like yours.
raulvalencia
Posts: 6
Joined: Wed Jun 01, 2016 12:53 pm

Re: How I could set freq of timer 3 to 102.4Hz

Post by raulvalencia »

Hi,
Thanks for answering me.
I've another question : to check this frequency I'd like to use an IO in output mode, to see this "clk = 102.4 Hz" with my oscilloscope, and in this way, I'll be sure that I am using the good one...
Is that possible?
Anyone has a code example?

Thanks,

Raul
AdShea
Posts: 6
Joined: Mon Nov 30, 2015 9:03 pm
Has thanked: 1 time
Been thanked: 2 times

Re: How I could set freq of timer 3 to 102.4Hz

Post by AdShea »

You can set the prescaler (TIM3_PSC = 0x0009) to divide by 10 so the timer is only counting at 6.4MHz then use a timer roll-over of 62500 (TIM3_ARR = 0xF424) to get your 102.4Hz.

For testing the output, if you have a timer 3 channel pin available then just set the OCM for that channel to one of the PWM modes and set an output compare value somewhere near half (TIM3_CCMR.OCxM = 110; TIM3_CCRx = 0x7A12 where x is the timer pin you have available).
Post Reply