cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 ClockDivision

jonathan239955_stm1_st
Associate II
Posted on August 25, 2016 at 09:59

Hello,

I am using the board Nucleo-L476RG, the system core clock is running at 80 Mhz. I don't understand what is the purpose of ClockDivision. I thought that I can divide the frequency by 4 if I setTIM_CLOCKDIVISION_DIV4 but it's not working. I am usingPrescaler, but it's not enough because I need to count around 60sec using 16bit timer. Here is my code to have a 500 Hz frequency 80Mhz/ ((Prescaler+1)*

ClockDivision

) = 500

timer.Instance = TIM6;
timer.Init.Period = 0xffff; 
timer.Init.CounterMode = TIM_COUNTERMODE_UP;
timer.Init.Prescaler = 40000 - 1;
timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // has no effect
timer.Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(&timer);

Thanks for your help,
2 REPLIES 2
Walid FTITI_O
Senior II
Posted on August 25, 2016 at 10:36

Hi constant.jonathan, 

The Timer clock division CKD does not relate to the time-Base update. The prescaler and period does.

As mentioned in the corresponding register in reference manual, it is related ti the dead time configuration.

''Bits 9:8

CKD[1:0]

: Clock division

This bit-field indicates the division ratio between the timer clock (CK_INT) frequency and the

dead-time and sampling clock (t

DTS

)used by the dead-time generators and the digital filters

(TIx)'

-Hannibal-

Posted on August 25, 2016 at 19:45

Yes, unrelated to what you think it is does.

Use a 32-bit counter, use one that has a Repetition Counter setting the timebase to 1sec and repeat 60 times, the Update Interrupt will fire once a minute.

Use the RTC?

Use the 1ms/1KHz timer to count off time?

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