Skip to main content
Visitor II
May 30, 2018
Question

STM8S TIM1 delayed interrupt problem

  • May 30, 2018
  • 1 reply
  • 2270 views
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.

    This topic has been closed for replies.

    1 reply

    Visitor II
    May 31, 2018
    Posted on May 31, 2018 at 04:07

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

    Visitor II
    May 31, 2018
    Posted on May 31, 2018 at 05:08

    Sorry for my English.

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

    Visitor II
    May 31, 2018
    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.