cancel
Showing results for 
Search instead for 
Did you mean: 

Is STM8S103F3 TIM4 auto-reload up-counter ?

jeffrey2
Associate II
Posted on December 15, 2009 at 12:44

Is STM8S103F3 TIM4 auto-reload up-counter ?

5 REPLIES 5
jeffrey2
Associate II
Posted on May 17, 2011 at 15:06

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 ]

baroudi
Associate II
Posted on May 17, 2011 at 15:06

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,

jeffrey2
Associate II
Posted on May 17, 2011 at 15:06

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 ]

baroudi
Associate II
Posted on May 17, 2011 at 15:06

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,

DAS.ANIL KUMAR
Associate II
Posted on July 12, 2014 at 09:04

how can i use TIM4  for 10 minute intruupt?????????????          plz help me if any know...thanks