2009-12-15 03:44 AM
Is STM8S103F3 TIM4 auto-reload up-counter ?
2011-05-17 06:06 AM
I can use TIM4 interrupt successfully as following codes:
// TIM4 auto-reload up-counter ? //TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A) TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B) //TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE); TIM4_ITConfig(TIM4_CR1_ARPE | TIM4_CR1_URS | TIM4_CR1_CEN, ENABLE); /* Enable TIM4 */ TIM4_Cmd(ENABLE); But I am NOT sure whether the TIM4 is auto-reload up-counter as STM8S103F3 RM0016 (page 239) document since the (B) statement toggles the LED faster than the (A) one. It means that the TIM4 interrupt period of (B) is shorter. [ This message was edited by: jeffrey.chang168 on 14-12-2009 15:54 ] [ This message was edited by: jeffrey.chang168 on 15-12-2009 00:12 ]2011-05-17 06:06 AM
Hi jeffrey.chang168,
As mentioned in the RM0016, the TIM4 is auto-reload up-counter timer. An below the explanation of the theory ! //TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A) If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (128 + 1) / 15625 = 8.256 ms TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B) If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (16 + 1) / 15625 = 1.088 ms Let me know if that stills unclear. Regards,2011-05-17 06:06 AM
Quote:
On 15-12-2009 at 10:39, Anonymous wrote: Hi jeffrey.chang168, As mentioned in the RM0016, the TIM4 is auto-reload up-counter timer. An below the explanation of the theory ! //TIM4_TimeBaseInit(TIM4_PRESCALER_128, 128); // (A) If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (128 + 1) / 15625 = 8.256 ms TIM4_TimeBaseInit(TIM4_PRESCALER_128, 16); // (B) If you are running your system in the default system clock configuration (2MHz), the TIM4 counter is clocked by 2000000 / prescaler = 2000000 / 128 = 15 625 Hz so update interrupt is generated each (16 + 1) / 15625 = 1.088 ms Let me know if that stills unclear. Regards, As mentioned in RM0016 page 239, the TIM4 interrupt is generated on counter overflow. So the UP counter is auto-reload on overflow. Case A) 128, 129, ..., 255, 0, 128 so Interrupt Period A should be (256 - 128) / 15625 = 128/15625. Case B) 16, 17, ..., 255, 16 so Interrupt Period B should be (256 - 16) / 15625 = 240/15625. Period A < Period B ////////////////////////////////////// If TIM4 is auto-reload DOWN counter. Case A) 128, 127, ..., 1, 0, 128 so Interrupt Period A should be (128 + 1) / 15625 = 129/15625. Case B) 16, 15, ..., 1, 0, 16 so Interrup Period should be (16 + 1) / 15625 = 17/15625. Period A > Period B Which one is correct ? [ This message was edited by: jeffrey.chang168 on 15-12-2009 16:59 ]2011-05-17 06:06 AM
Hi jeffrey.chang168,
I thought like you when I started developping on STM8 ! The overflow event occurs when the counter (CNTR register) reaches the Auto-Reload value (ARR register). That is explained in TIM1 section. the TIM4 interrupt is generated on counter overflow. So the UP counter is auto-reload on overflow. Case A) 0, 1, ..., 128 at 128 the overflows event so Interrupt Period A is (128 + 1) / 15625 = 8.256 ms Case B) 0, 1, ..., 15 at 16 the overflows event so Interrupt Period B is (16 + 1) / 15625 = 1.088 ms. I wish It is clear now. Regards,2014-07-12 12:04 AM