/* Speeduino - Simple engine management for the Arduino Mega 2560 platform Copyright (C) Josh Stewart A full copy of the license may be found in the projects root directory */ /* Timers are used for having actions performed repeatedly at a fixed interval (Eg every 100ms) They should not be confused with Schedulers, which are for performing an action once at a given point of time in the future Timers are typically low resolution (Compared to Schedulers), with maximum frequency currently being approximately every 10ms */ #include "timers.h" #include "globals.h" void initialiseTimers() { //Configure Timer2 for our low-freq interrupt code. TCCR2B = 0x00; //Disbale Timer2 while we set it up TCNT2 = 131; //Preload timer2 with 131 cycles, leaving 125 till overflow. As the timer runs at 125Khz, this causes overflow to occur at 1Khz = 1ms TIFR2 = 0x00; //Timer2 INT Flag Reg: Clear Timer Overflow Flag TIMSK2 = 0x01; //Timer2 Set Overflow Interrupt enabled. TCCR2A = 0x00; //Timer2 Control Reg A: Wave Gen Mode normal /* Now configure the prescaler to CPU clock divided by 128 = 125Khz */ TCCR2B |= (1<