cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S TIM1 delayed interrupt problem

Alexey Chernysh
Associate II
Posted on May 30, 2018 at 13:09

Hi!

I need time-delayed interrupt using TIM1 in my STM8S105K4 project in IAR free IDE

TIM2 & TIM3 already in use.

void SetupTimer1(){

 #define TIM1_PRESCALER 16000L

// once 1 msec

 TIM1_PSCRH = (unsigned char)(TIM1_PRESCALER>>8);

 TIM1_PSCRL = (unsigned char)(TIM1_PRESCALER);

 #define TIM1_LIMIT 1000L

// once 1 sec

 TIM1_ARRH = (unsigned char)(TIM1_LIMIT>>8);

 TIM2_ARRL = (unsigned char)(TIM1_LIMIT);    

}

void StartTimer1(){

 TIM1_CR1_OPM = 1; // One Pulse Mode enabled

 TIM1_CR1_URS = 1;

 TIM1_IER_UIE = 1;

 TIM1_CR1_CEN = 1;

}

void StopTimer1(){

  TIM1_SR1_UIF = 0;

  TIM1_CR1 = 0;

  TIM1_SR1 = 0;

}

#pragma vector = TIM1_OVR_UIF_vector

__interrupt void TIM1_OVR_UIF_handler(void){

 if (TIM1_SR1_UIF == 1){

   StopTimer1();

   // do something….

 }

}

\

void OnExternalEvent(){

  â€¦â€¦

  StartTimer1();

  .......

}

What is wrong?

Interrupt occurred once soon after call StartTimer1(), without 1 sec delay.

6 REPLIES 6
henry.dick
Senior II
Posted on May 31, 2018 at 04:07

You eem to have trouble understanding what 'time delayed interrupt' is.

Posted on May 31, 2018 at 05:08

Sorry for my English.

'Delayed interrupt' should be invoked 1 sec after call of StartTimer1().

Posted on May 31, 2018 at 23:35

Easy. You can either poll the flag or if interrupt is used, run your code in the timer isr.

Posted on June 01, 2018 at 04:29

Thank!

I know that.

Problem is with TIM1 programming. I am trying to use 'update' (counter overflow/underflow) interrupt.

I googled all tutorials and manuals, but something is wrong in my code.

First call of

StartTimer1() invoked interrupt

 without any delay.

Second call of StartTimer1() is silent, without any interrupt. 

Posted on June 01, 2018 at 13:05

'

I know that.

.... I am trying to use 'update' (counter overflow/underflow) interrupt.'

then you should know why you set the timer in one-shot mode then?

Posted on June 03, 2018 at 16:36

Time gone out and i solved this by polling.

Thank you for right solution!