Text: Questions 1. Timer Functions
Arduino IDE provides millis() function that returns the number of milliseconds since the Arduino board began running the current program. millis() overflows (goes back to zero) after approximately 50 days (see https://www.arduino.cc/en/Reference/Millis).
The millis() function has a very simple structure; it just returns uptime_millis, which keeps track of the system uptime in milliseconds.
unsigned long uptime_millis; // keeps track of system uptime in msec
... other code to update millis..
unsigned long millis(void) { return uptime_millis; }
In this homework, your goal is to implement the above millis() function with the timer output-compare function 3 (OC3) on the HCS12 board. You need to generate an interrupt for OC3 so that uptime_millis can be updated while the CPU is executing another part of the program. Your implementation should have the following two functions:
1) void timer_init(void): It initializes and configures the timer and OC3. This function will be called at the very beginning of the main() function.
2) interrupt void OC3_ISR(void): The interrupt service routine (ISR) of OC3. This is the place where uptime_millis should be updated.