cancel
Showing results for 
Search instead for 
Did you mean: 

Getting an delay by timer interruption

david.ye
Associate II
Posted on November 13, 2017 at 17:44

Hello Everyone,

I am working on the STM8AL3166 and try to handle a timer interrupt. My need is to wait 500ms and then check again a value (not pooling)

How/Where do I write the program when the interrupt occurs? Where can I find the header file?

I did several hours of searching and can not find anything, Please Help !

Thank,

David

#timer-interrupts #delay
11 REPLIES 11
Vyacheslav Azarov
Associate III
Posted on November 15, 2017 at 10:03

Ask please the question more fully. It's hard to understand what you want. Usually, a non-blocking delay in computation is possible only in a multitasking environment.

david.ye
Associate II
Posted on November 15, 2017 at 10:33

Hello,

Thank for the reply.

Let me rephrase my question : how do we get into the interrupt service routine?

I configured my timer as below

...

void InitTIM4(){

       TIM4_CR1= 0x04;       //Counter stops counting at the next update event (clearing the CEN bit)

       TIM4_IER= 0x01;         //enable interrupt

       TIM4_PRSCR=0xFE   //Fsysclk divided by 2^13 => timer tick= 1,024ms

}

...

   if(value==1){

        TIM4_CRR1=0x0A;   //interrupt in10ms

        TIM4_CR1=0x05;      //active the timer

...

Then how can I go into the interrupt service routine to tell him what to do when the interrupt occurs? which function to call? Do I need to import a specific library? 

Thank a lot in advance,

David

S.Ma
Principal
Posted on November 15, 2017 at 10:56

For 500msec or msec units, you can add your function inside the Systick() milisecond event. There you can countdown a global variable and when the variable reaches zero, you do something or raise a flag (a bit). The main loop can change the global countdown variable and when it reaches zero, the main loop will see a flag set, do the job and clear the flag, optionally rearm the countdown. Using HW Timer would be for finger time granularity (microseconds)

david.ye
Associate II
Posted on November 15, 2017 at 11:15

Hi,

Where can I find the Systick() millisecond event function? which library I have to download?

I am really not used to control time in programmation :\

Many thanks

Posted on November 15, 2017 at 11:31

In different compilers, interrupt service routines are declared differently. In any case you need to describe ISR logic by himself.

//SDCC:
void YourISRname(void) __interrupt(YOUR_VECTOR)
{
// ... Your logic
}
//COSMIC:
// is need to insertion this name in the special table
@interrupt void YourISRname(void)
{
// ... Your logic
}
//IAR:
#pragma vector = YOUR_VECTOR
 __interrupt void YourISRname(void)
{
// ... Your logic
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Read compiler manual, please.

Posted on November 15, 2017 at 16:34

Hello,

Thank you for this answer.

I am using Raisonnance, Ride 7 IDE.

I will read their compiler manual.

Regards

Posted on November 16, 2017 at 08:26

Hello Vyacheslav,

I have read the manual and found my need. The syntax is :

void MyISRName(void) interrupt MyVectorNb

{

// My algorithm

}

But I still have one question about the IDE. Is generally the simulator can simulate a timer? Because when I am debugging my code, the PC never goes into the interrupt handler.

Edit:

As a reminder, this is my program in pj.

Many thanks,

David

________________

Attachments :

codeTimer.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyIU&d=%2Fa%2F0X0000000b5h%2FCuFOQxsUME53knGN29w9obWBEq.USRBPhllBoTkYKF0&asPdf=false
Posted on November 16, 2017 at 09:30

I do not know as it is realized at Raisonnance. But the IAR-EW and ST-VD simulation of the periphery has not  fully implemented. Requires the definition of interrupt events manually, by writing to a special table.

Posted on November 18, 2017 at 05:04

Systick() is a feature of ARM (STM32) libraries. STM8 libraries do not have it, roll your own.

- pa