#include "ustimer.h"
Defines | |
#define | US_TIMER_PRESCALER 8 |
#define | XTAL 11.0562 |
Functions | |
void | us_timer_init (void) |
initiates the timer | |
SIGNAL (SIG_OVERFLOW3) | |
uint32_t | us_time_get (void) |
get current time | |
uint32_t | us_time_get_difference (uint32_t time1) |
calculates the difference between a saved and the current time | |
double | us_time_get_difference_d (uint32_t time1) |
calculates the difference between a saved and the current time in micro-seconds | |
Variables | |
volatile uint32_t | us_time = 0 |
internal counter |
|
|
|
|
|
The interrupt handler for the micro-second(us) timer. 00036 { 00037 if(us_time < 0xFFFF) us_time++; //with 16Bit-Timer use 0xFFFF; 8bit: 0xFFFFFF 00038 else us_time = 0; 00039 }
|
|
get current time Calculates the current time from an incremented variable and the counter register of the timer. 00046 { 00047 uint16_t timer; 00048 00049 /* It is really, really important to stop global interrupts before 00050 * reading 16bit registers. See the avr-libc FAQ! */ 00051 cli(); 00052 timer = TCNT3; 00053 sei(); 00054 00055 return ((us_time << 16) + timer); 00056 }
|
|
calculates the difference between a saved and the current time Uses us_time_get() to get the current time. The if-condition at the end checks whether the later time is smaller. If so, then an timer overflow is assumed and the appropriate action is taken that the correct time can still be calculated. Therefore, the maximum time one can measure is 2^32 micro-seconds. 00068 { 00069 uint32_t time2; 00070 time2 = us_time_get(); 00071 if(time2 >= time1) return (time2-time1); 00072 else return (0xFFFFFFFF - time1+time2); //2^32 00073 }
|
|
calculates the difference between a saved and the current time in micro-seconds Same as us_time_get_difference(), but returns the value in micro seconds. 00079 { 00080 return ((double)(us_time_get_difference(time1) * US_TIMER_PRESCALER) / (double)XTAL); 00081 }
|
|
|
internal counter
|