Altera_Forum
Honored Contributor
20 years agoaltera timer hal overflow question ?
do altera hal timers work correct if the end of the system tick
variable range is reached ? Please check the following and tell me if I'm wrong. see files alt_tick.c, alt_alarm_start.c, /* * "_alt_nticks" is the number of system clock ticks that have elapsed since * reset. */ volatile alt_u32 _alt_nticks = 0; --> this will result in an overflow after about 49,71.. days if the system clock timer is set to 1ms, which is ok for a pc (normally shut off before 49 days), but an embedded system will normally run longer. what happens with the timers when an overflow condition exist ??? e.g. to simplify we use a range of 255 ticks and an periodic timer of 10 ticks. callbacks are run if (alarm->time <= _alt_nticks) is true so timer will run ticks 000 system starts ... 010 (10<=10)-> first callback (timer is rescheduled with alarmtime=alarmtime+10=20) ... 020 (20<=20)-> second callback (timer is rescheduled with alarmtime=alarmtime+10=30) ... ... ... 250 (250<=250)-->x' callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=4) 251 (4<=251)-->callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=14) 252 (14<=252)-->callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=24) 253 (24<=253)-->callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=34) 254 (34<=254)-->callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=44) 255 (44<=255)--> callback (timer is rescheduled with alarmtime=alarmtime+10 overflow will result in alarmtime=54) 000 (54<=000) is false ... 054 (54<=54) -> callback in the range of (tick_range - alarmtime) callbacks are executed every tick instead of alarmtime ticks, on alt_tick overflow, timer will be suspended for (alarmtime*alarmtime ticks). e.g. a periodic timer with 1000ms and a system timer tick of 1ms after 49,71 days the following will happen the timer will run 1000 times every 1ms just before _alt_nticks overruns, then it will need (1000*1000) ms = 1000sec = 16,66 minutes until the timer will start again. is this correct or I'm wrong ???