AnsweredAssumed Answered

Long delay using timer

Question asked by stastny.petr on Jul 4, 2014
Latest reply on Jul 4, 2014 by Ivan Ivanov
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++;
    }
}

Outcomes