Page 1 of 1

How I could set freq of timer 3 to 102.4Hz

Posted: Sat Jan 07, 2017 4:16 pm
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

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

Posted: Sat Jan 07, 2017 4:24 pm
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.

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

Posted: Tue Jan 10, 2017 10:36 pm
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

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

Posted: Fri Jan 13, 2017 4:46 pm
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).