2018-05-30 04:09 AM
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.
2018-05-30 07:07 PM
You eem to have trouble understanding what 'time delayed interrupt' is.
2018-05-30 10:08 PM
Sorry for my English.
'Delayed interrupt' should be invoked 1 sec after call of StartTimer1().
2018-05-31 04:35 PM
Easy. You can either poll the flag or if interrupt is used, run your code in the timer isr.
2018-05-31 09:29 PM
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.
2018-06-01 06:05 AM
'
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?
2018-06-03 09:36 AM
Time gone out and i solved this by polling.
Thank you for right solution!