Timer management - step pulse clock and system clock. More...
#include "timer.h"
#include <avr/interrupt.h>
#include "arduino.h"
#include "config.h"
Defines | |
#define | TICK_TIME 2 MS |
how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535) | |
#define | TICK_TIME_MS (TICK_TIME / (F_CPU / 1000)) |
convert back to ms from cpu ticks so our system clock runs properly if you change TICK_TIME | |
Functions | |
ISR (TIMER1_COMPB_vect) | |
comparator B is the system clock, happens every TICK_TIME | |
void | timer_init () |
initialise timer and enable system clock interrupt. | |
Variables | |
volatile uint32_t | next_step_time |
time until next step, as output compare register is too small for long step times | |
uint8_t | clock_counter_10ms = 0 |
every time our clock fires, we increment this so we know when 10ms has elapsed | |
uint8_t | clock_counter_250ms = 0 |
keep track of when 250ms has elapsed | |
uint8_t | clock_counter_1s = 0 |
keep track of when 1s has elapsed | |
volatile uint8_t | clock_flag = 0 |
flags to tell main loop when above have elapsed |
Timer management - step pulse clock and system clock.
Teacup uses timer1 to generate both step pulse clock and system clock.
We achieve this by using the output compare registers to generate the two clocks while the timer free-runs.
Teacup has tried numerous timer management methods, and this is the best so far.
void timer_init | ( | void | ) |
initialise timer and enable system clock interrupt.
step interrupt is enabled later when we start using it
Referenced by init().