2017-11-13 08:44 AM
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 #delay2017-11-15 01:03 AM
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.
2017-11-15 01:33 AM
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
2017-11-15 01:56 AM
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)
2017-11-15 02:15 AM
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
2017-11-15 03:31 AM
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.
2017-11-15 08:34 AM
Hello,
Thank you for this answer.
I am using Raisonnance, Ride 7 IDE.
I will read their compiler manual.
Regards
2017-11-16 12:26 AM
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=false2017-11-16 01:30 AM
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.
2017-11-17 09:04 PM
Systick() is a feature of ARM (STM32) libraries. STM8 libraries do not have it, roll your own.
- pa