Senzory 1.0
Timer Library

Timer library for AVR-GCC. More...

Definitions for 16-bit Timer/Counter1

Note
t_OVF = 1/F_CPU * prescaler * 2^n where n = 16, F_CPU = 16 MHz
#define tim1_stop()
 Stop timer, prescaler 000 --> STOP.
#define tim1_ovf_4ms()
 Set overflow 4ms, prescaler 001 --> 1.
#define tim1_ovf_33ms()
 Set overflow 33ms, prescaler 010 --> 8.
#define tim1_ovf_262ms()
 Set overflow 262ms, prescaler 011 --> 64.
#define tim1_ovf_1sec()
 Set overflow 1s, prescaler 100 --> 256.
#define tim1_ovf_4sec()
 Set overflow 4s, prescaler // 101 --> 1024.
#define tim1_ovf_enable()
 Enable overflow interrupt, 1 --> enable.
#define tim1_ovf_disable()
 Disable overflow interrupt, 0 --> disable.

Definitions for 8-bit Timer/Counter0

Note
t_OVF = 1/F_CPU * prescaler * 2^n where n = 8, F_CPU = 16 MHz
#define tim0_stop()
 Stop timer, prescaler 000 --> STOP.
#define tim0_ovf_16us()
 Set overflow 4ms, prescaler 001 --> 1.
#define tim0_ovf_128us()
 Set overflow 33ms, prescaler 010 --> 8.
#define tim0_ovf_1ms()
 Set overflow 262ms, prescaler 011 --> 64.
#define tim0_ovf_4ms()
 Set overflow 1s, prescaler 100 --> 256.
#define tim0_ovf_16ms()
 Set overflow 4s, prescaler // 101 --> 1024.
#define tim0_ovf_enable()
 Enable overflow interrupt, 1 --> enable.
#define tim0_ovf_disable()
 Disable overflow interrupt, 0 --> disable.

Definitions for 8-bit Timer/Counter2

Note
t_OVF = 1/F_CPU * prescaler * 2^n where n = 8, F_CPU = 16 MHz
#define tim2_stop()
 Stop timer, prescaler 000 --> STOP.
#define tim2_ovf_16us()
 Set overflow 4ms, prescaler 001 --> 1.
#define tim2_ovf_128us()
 Set overflow 33ms, prescaler 010 --> 8.
#define tim2_ovf_512us()
 Set overflow 262ms, prescaler 011 --> 32.
#define tim2_ovf_1ms()
 Set overflow 1s, prescaler 100 --> 64.
#define tim2_ovf_2ms()
 Set overflow 4s, prescaler // 101 --> 128.
#define tim2_ovf_4ms()
 Set overflow 4s, prescaler // 110 --> 256.
#define tim2_ovf_16ms()
 Set overflow 4s, prescaler // 111 --> 1024.
#define tim2_ovf_enable()
 Enable overflow interrupt, 1 --> enable.
#define tim2_ovf_disable()
 Disable overflow interrupt, 0 --> disable.

Detailed Description

Timer library for AVR-GCC.

#include <timer.h>

The library contains macros for controlling the timer modules.

Note
Based on Microchip Atmel ATmega328P manual and no source file is needed for the library.

Macro Definition Documentation

◆ tim0_ovf_128us

#define tim0_ovf_128us ( )
Value:
TCCR0B &= ~((1<<CS02) | (1<<CS00)); TCCR0B |= (1<<CS01);

Set overflow 33ms, prescaler 010 --> 8.

◆ tim0_ovf_16ms

#define tim0_ovf_16ms ( )
Value:
TCCR0B &= ~(1<<CS01); TCCR0B |= (1<<CS02) | (1<<CS00);

Set overflow 4s, prescaler // 101 --> 1024.

◆ tim0_ovf_16us

#define tim0_ovf_16us ( )
Value:
TCCR0B &= ~((1<<CS02) | (1<<CS01)); TCCR0B |= (1<<CS00);

Set overflow 4ms, prescaler 001 --> 1.

◆ tim0_ovf_1ms

#define tim0_ovf_1ms ( )
Value:
TCCR0B &= ~(1<<CS02); TCCR0B |= (1<<CS01) | (1<<CS00);

Set overflow 262ms, prescaler 011 --> 64.

◆ tim0_ovf_4ms

#define tim0_ovf_4ms ( )
Value:
TCCR0B &= ~((1<<CS01) | (1<<CS00)); TCCR0B |= (1<<CS02);

Set overflow 1s, prescaler 100 --> 256.

◆ tim0_ovf_disable

#define tim0_ovf_disable ( )
Value:
TIMSK0 &= ~(1<<TOIE0);

Disable overflow interrupt, 0 --> disable.

◆ tim0_ovf_enable

#define tim0_ovf_enable ( )
Value:
TIMSK0 |= (1<<TOIE0);

Enable overflow interrupt, 1 --> enable.

◆ tim0_stop

#define tim0_stop ( )
Value:
TCCR0B &= ~((1<<CS02) | (1<<CS01) | (1<<CS00));

Stop timer, prescaler 000 --> STOP.

◆ tim1_ovf_1sec

#define tim1_ovf_1sec ( )
Value:
TCCR1B &= ~((1<<CS11) | (1<<CS10)); TCCR1B |= (1<<CS12);

Set overflow 1s, prescaler 100 --> 256.

◆ tim1_ovf_262ms

#define tim1_ovf_262ms ( )
Value:
TCCR1B &= ~(1<<CS12); TCCR1B |= (1<<CS11) | (1<<CS10);

Set overflow 262ms, prescaler 011 --> 64.

◆ tim1_ovf_33ms

#define tim1_ovf_33ms ( )
Value:
TCCR1B &= ~((1<<CS12) | (1<<CS10)); TCCR1B |= (1<<CS11);

Set overflow 33ms, prescaler 010 --> 8.

◆ tim1_ovf_4ms

#define tim1_ovf_4ms ( )
Value:
TCCR1B &= ~((1<<CS12) | (1<<CS11)); TCCR1B |= (1<<CS10);

Set overflow 4ms, prescaler 001 --> 1.

◆ tim1_ovf_4sec

#define tim1_ovf_4sec ( )
Value:
TCCR1B &= ~(1<<CS11); TCCR1B |= (1<<CS12) | (1<<CS10);

Set overflow 4s, prescaler // 101 --> 1024.

◆ tim1_ovf_disable

#define tim1_ovf_disable ( )
Value:
TIMSK1 &= ~(1<<TOIE1);

Disable overflow interrupt, 0 --> disable.

◆ tim1_ovf_enable

#define tim1_ovf_enable ( )
Value:
TIMSK1 |= (1<<TOIE1);

Enable overflow interrupt, 1 --> enable.

◆ tim1_stop

#define tim1_stop ( )
Value:
TCCR1B &= ~((1<<CS12) | (1<<CS11) | (1<<CS10));

Stop timer, prescaler 000 --> STOP.

◆ tim2_ovf_128us

#define tim2_ovf_128us ( )
Value:
TCCR2B &= ~((1<<CS22) | (1<<CS20)); TCCR2B |= (1<<CS21);

Set overflow 33ms, prescaler 010 --> 8.

◆ tim2_ovf_16ms

#define tim2_ovf_16ms ( )
Value:
TCCR2B = (1<<CS22) | (1<<CS21)| (1<<CS20);

Set overflow 4s, prescaler // 111 --> 1024.

◆ tim2_ovf_16us

#define tim2_ovf_16us ( )
Value:
TCCR2B &= ~((1<<CS22) | (1<<CS21)); TCCR2B |= (1<<CS20);

Set overflow 4ms, prescaler 001 --> 1.

◆ tim2_ovf_1ms

#define tim2_ovf_1ms ( )
Value:
TCCR2B &= ~((1<<CS21) | (1<<CS20)); TCCR2B |= (1<<CS22);

Set overflow 1s, prescaler 100 --> 64.

◆ tim2_ovf_2ms

#define tim2_ovf_2ms ( )
Value:
TCCR2B &= ~(1<<CS21); TCCR2B |= (1<<CS22) | (1<<CS20);

Set overflow 4s, prescaler // 101 --> 128.

◆ tim2_ovf_4ms

#define tim2_ovf_4ms ( )
Value:
TCCR2B &= ~(1<<CS20); TCCR2B |= (1<<CS22) | (1<<CS21);

Set overflow 4s, prescaler // 110 --> 256.

◆ tim2_ovf_512us

#define tim2_ovf_512us ( )
Value:
TCCR2B &= ~(1<<CS22); TCCR2B |= (1<<CS21) | (1<<CS20);

Set overflow 262ms, prescaler 011 --> 32.

◆ tim2_ovf_disable

#define tim2_ovf_disable ( )
Value:
TIMSK2 &= ~(1<<TOIE2);

Disable overflow interrupt, 0 --> disable.

◆ tim2_ovf_enable

#define tim2_ovf_enable ( )
Value:
TIMSK2 |= (1<<TOIE2);

Enable overflow interrupt, 1 --> enable.

◆ tim2_stop

#define tim2_stop ( )
Value:
TCCR2B &= ~((1<<CS22) | (1<<CS21) | (1<<CS20));

Stop timer, prescaler 000 --> STOP.