AnsweredAssumed Answered

STM8S TIM1 delayed interrupt problem

Question asked by Alexey Chernysh on May 30, 2018
Latest reply on Jun 3, 2018 by Alexey Chernysh

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.

Outcomes