xyControl  0.1
Quadrotor Flight Controller on AVR Basis
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Macros | Typedefs | Functions | Variables
Time Keeping

Measuring Time with Millisecond Resolution. More...

Files

file  time.h
 Time API Header.
 
file  time.c
 Time API Implementation.
 

Macros

#define TCRA   TCCR2A
 Timer 2 Control Register A. More...
 
#define TCRB   TCCR2B
 Timer 2 Control Register B. More...
 
#define OCR   OCR2A
 Timer 2 Compare Register A. More...
 
#define TIMS   TIMSK2
 Timer 2 Interrupt Mask. More...
 
#define OCIE   OCIE2A
 Timer 2 Compare Match A Interrupt Enable. More...
 

Typedefs

typedef uint64_t time_t
 Timekeeping Data Type. More...
 

Functions

void initSystemTimer (void)
 Initialize the system timer. More...
 
time_t getSystemTime (void)
 Get the System Uptime. More...
 
 ISR (TIMER2_COMPA_vect)
 Timer 2 Compare Match A Interrupt. More...
 

Variables

volatile time_t systemTime = 0
 Current System Uptime. More...
 

Detailed Description

Measuring Time with Millisecond Resolution.

Uses Timer 2

Prescaler 64

Count to 250

16000000 / 64 / 250 = 1000 –> 1 Interrupt per millisecond

Macro Definition Documentation

#define OCIE   OCIE2A

Timer 2 Compare Match A Interrupt Enable.

Definition at line 53 of file time.c.

#define OCR   OCR2A

Timer 2 Compare Register A.

Definition at line 51 of file time.c.

#define TCRA   TCCR2A

Timer 2 Control Register A.

Definition at line 49 of file time.c.

#define TCRB   TCCR2B

Timer 2 Control Register B.

Definition at line 50 of file time.c.

#define TIMS   TIMSK2

Timer 2 Interrupt Mask.

Definition at line 52 of file time.c.

Typedef Documentation

typedef uint64_t time_t

Timekeeping Data Type.

Overflows after 500 million years... :)

Definition at line 53 of file time.h.

Function Documentation

time_t getSystemTime ( void  )

Get the System Uptime.

Returns
System Uptime in Milliseconds
Examples:
hardwareTest.c, and uartFlight.c.

Definition at line 68 of file time.c.

References systemTime.

Referenced by complementaryExecute(), complementaryInit(), orientationTask(), and pidExecute().

68  {
69  return systemTime;
70 }
void initSystemTimer ( void  )

Initialize the system timer.

Execution every millisecond. Uses Timer 2.

Definition at line 55 of file time.c.

Referenced by xyInit().

55  {
56  // Timer initialization
57  TCRA |= (1 << WGM21); // CTC Mode
58  TCRB |= (1 << CS22); // Prescaler: 64
59  OCR = 250;
60  TIMS |= (1 << OCIE); // Enable compare match interrupt
61 }
ISR ( TIMER2_COMPA_vect  )

Timer 2 Compare Match A Interrupt.

Definition at line 64 of file time.c.

References systemTime.

64  {
65  systemTime++;
66 }

Variable Documentation

volatile time_t systemTime = 0

Current System Uptime.

Definition at line 47 of file time.c.

Referenced by getSystemTime(), and ISR().