Skip to main content
Visitor II
November 13, 2017
Question

Getting an delay by timer interruption

  • November 13, 2017
  • 4 replies
  • 2852 views
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
    This topic has been closed for replies.

    4 replies

    Visitor II
    November 15, 2017
    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.yeAuthor
    Visitor II
    November 15, 2017
    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

    Visitor II
    November 15, 2017
    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.

    david.yeAuthor
    Visitor II
    November 15, 2017
    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

    Visitor II
    November 15, 2017
    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.yeAuthor
    Visitor II
    November 15, 2017
    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

    Super User
    November 18, 2017
    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