diff options
-rw-r--r-- | include/arch/atmega2560/driver/timer.h | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/include/arch/atmega2560/driver/timer.h b/include/arch/atmega2560/driver/timer.h index 73a8125..c16fbe4 100644 --- a/include/arch/atmega2560/driver/timer.h +++ b/include/arch/atmega2560/driver/timer.h @@ -6,7 +6,7 @@ #include <avr/io.h> #include <avr/interrupt.h> -#define ON_TIMER_INTERRUPT_head ISR(TIMER0_COMPA_vect) { +#define ON_TIMER_INTERRUPT_head ISR(TIMER4_COMPA_vect) { #define ON_TIMER_INTERRUPT_tail } class Timer { @@ -17,24 +17,24 @@ class Timer { public: Timer() {} - inline void setup_khz(uint16_t const frequency) { - OCR0A = frequency ? 255 / frequency : 1; - TCCR0A = _BV(WGM01); - prescaler = _BV(CS01) | _BV(CS00); + inline void setup_khz(uint16_t const frequency) { // 16 MHz base + OCR4A = frequency ? 16000 / frequency : 65535; + TCCR4A = _BV(WGM42); + prescaler = _BV(CS40); } - inline void setup_hz(uint16_t const frequency) { - OCR0A = frequency ? 255 / frequency : 1; - TCCR0A = _BV(WGM01); - prescaler = _BV(CS02) | _BV(CS00); + inline void setup_hz(uint16_t const frequency) { // 16 MHz / 256 == 62.5 kHz base + OCR4A = frequency ? 62500 / frequency : 65535; + TCCR4A = _BV(WGM42); + prescaler = _BV(CS42); } inline void start(unsigned char const interrupt) { - TCNT0 = 0; - TCCR0B = prescaler; + TCNT4 = 0; + TCCR4B = prescaler; if (interrupt) { - TIMSK0 = _BV(OCIE0A); + TIMSK4 = _BV(OCIE4A); } } - inline void stop() { TCCR0B = 0; TIMSK0 = 0; } + inline void stop() { TCCR4B = 0; TIMSK4 = 0; } }; extern Timer timer; |