This library covers a large part of the functionality of ATmega128 timers. There are data types and functions which make usage of timers easier. Unfortunately, because of the complexity of AVR timers, there are no common functions to use different timers. Each of the timers has functions which start with the prefix of “timer” and its index.
Initializes timer 0 in normal mode. In this mode the timer counts from 0 to 255 (including). Overflow interrupt can be used. Parameters:
Initializes timer 2 in normal mode. In this mode timer counts from 0 to 255 (including). Overflow interrupt can be used. Parameters:
Stops timer 0/2.
Returns timer 0/2 current value. Parameters:
Sets timer 0/2 value. Parameters:
Enables or disables timer 0/2 overflow interrupt. The name of the interrupt vector is “TIMERn_OVF_vect” where “n” represents 0 or 2. Parameters:
Checks timer 0/2 overflow flag. Parameters:
Resets timer 0/2 overflow flag.
Initializes timer 1/3 in normal mode. In this mode timer counts from 0 to 65535 (including). Overflow interrupt can be used. Parameters:
Initializes timer 1/3 in CTC (Clear Timer on Compare Match) mode. In this mode timer counts to specified top value. Overflow interrupt can be used. Parameters:
Initializises timer 1/3 in fast PWM mode. In this mode timer counts to a specified value, which also determines the period of the PWM signal. Timer 1/3 has three 3 output compare units (A, B and C) to generate PWM signals. Overflow and compare match interrupts can be used. Parameters:
Stops timer 1/3.
Returns timer 1/3 current value. Parameters:
Sets timer 0/2 value. Parameters:
Returns timer 1/3 output compare unit A/B/C compare match register value. Parameters:
Sets timer 1/3 output compare unit A/B/C compare match register value. Parameters:
Returns timer 1/3 input capture register value. Parameters:
Sets timer 1/3 input capture register value. Parameters:
Enables or disables timer 1/3 overflow interrupt. The name of the interrupt vector is “TIMERn_OVF_vect” where “n” represents 1 või 3. Parameters:
Enables or disables timer 1/3 output compare unit A/B/C compare match interrupt. The name of the interrupt vector is “TIMERn_COMPx_vect” where “n” represents 1 or 3 and “x” represents A, B or C. Parameters:
Enables or disables timer 1/3 input capture interrupt. The name of the interrupt vector is “TIMERn_CAPT_vect”, where “n” represents 1 or 3. Parameters:
Checks timer 1/3 overflow flag. Parameters:
Checks timer 1/3 input capture flag. Parameters:
Resets timer 1/3 overflow flag.
Resets timer 1/3 input capture flag.
In the following program timer 0 is started in normal mode with overflow interrupt.
#include <homelab/timer.h> #include <avr/interrupt.h> // Overflow interrupt program. ISR(TIMER0_OVF_vect) { } int main(void) { // Initializing of timer 0 in normal mode. timer0_init_normal(TIMER0_PRESCALE_32); // Enabling timer 0 overflow interrupt. timer0_overflow_interrupt_enable(true); // Global interrupts enabling. sei(); }