cancel
Showing results for 
Search instead for 
Did you mean: 

Long delay using timer

Stastny.Petr
Associate III
Posted on July 04, 2014 at 09:46

Hello,

I program a firmware for very simple logic controller and I have problem with using a timer as exact delay generator. I need to generate delay from 1 sec to 250 minutes (15 000 sec). In the code down is show how the program work. Can you help me how to set timer to interrupt mode with described range? Thank you very much for your help Petr

int
step = 0;
void
main (
void
) {
while
(1) {
switch
(step) {
case
0: SetOutput(PA1); step++; 
break
; 
// write start
case
1: SetTimerValue(100); RunTimer(); step++; 
break
; 
// 100 second timer
case
2: 
break
; 
// do nothing, wait for interrupt from timer
case
3: ResetOutput(PA1); step++; 
break
; 
// write start
case
4: 
if
(BUTTON==0) {step=0;} 
// wait for press button to start
}
}
}
void
RunTimer(
int
TimeInSecond)
{
// set delay
// reset and start timer
// enable timer interrupt
}
void
TimerInterrupt{
if
(interruptFromTimer==ACTIVE) {
// disable timer
// step++;
}
}

1 REPLY 1
ivani
Associate II
Posted on July 04, 2014 at 15:10

Intervals of such big granularity (1 second) are more suitable for implementing by a software timer.
 For example, you could set the SYSTICK timer to fire an interrupt every 1ms and in the ISR you could increment a 32-bit (or 64-bit, if needed) variable, which will be your time base.
 Then, you could use this time base for various software timers per your needs.