Main Page | File List | Globals | Related Pages

c/timer.h File Reference

This file provides routines to use a delay timer. More...

#include "globals.h"

Go to the source code of this file.

Defines

#define TIMER_DIV8   _BV(CS11)
 Timer divider by 8.
#define TIMER_DIV64   _BV(CS11) | _BV(CS10)
 Timer divider by 64.
#define TIMER_DIV256   _BV(CS12)
 Timer divider by 265.
#define TIMER_DIV1024   _BV(CS12) | _BV(CS10)
 Timer divider by 1024.
#define TIMER_DIVIDER   TIMER_DIV64
 The timer divider to be used by the timer_delay() function.

Functions

void timer_init (void)
 Initialize the timer.
void timer_delay (u16 delay)
 Make a short delay.


Detailed Description

This file provides routines to use a delay timer.

The timer implemented here is implemented this way to save energy (e.g on battery operated devices). It uses the 16 bit timer (on At90S2313) to generate an interrupt after the delay ends, so that the mcu can go to sleep mode (idle mode) in the meantime. The interrupt causes the mcu to leave the sleep mode and continue operation.

It uses the 16 bit wide timer and its "match on compare" interrupt, so this timer and its interrupt cannot be used while using the delay timer.


Function Documentation

void timer_delay u16  delay  ) 
 

Make a short delay.

This method stops execution for a defined period of time. The delay time is dependend on the following: The crystal frequency, the divider as defined by TIMER_DIVIDER and the value passed to this function.

The delay in seconds is ap. 1 / CRYSTAL_FREQ * DIVIDER * delay, but may be a bit more due to the function call overhead etc. With the /64 divider is is possible to generate delays up to 1 second.

void timer_init void   ) 
 

Initialize the timer.

This sets up the registers for timer usage. Additionaly you need to globally enable interrupts by calling sei() ! If not the mcu will stay in sleep mode infinitly.


Generated on Wed Oct 27 10:57:05 2004 by  doxygen 1.3.9.1