- Timestamp:
- 03/18/14 16:30:12 (11 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/timer.c
r10674 r17632 1 #include " typedefs.h"1 #include "application.h" 2 2 #include <avr/interrupt.h> 3 3 4 5 volatile U16 milisec = 0; 6 volatile U32 sec = 0; 4 // We use the global volatile register! 5 // gVolReg.time_sec and 7 6 8 7 void timer_init() { 9 // TIMER2 is used as local clock: 10 // configure timer 2 11 TCCR2 = (1<<WGM21); // CTC Modus 12 TCCR2 |= (1<<CS21) | (1<<CS20); // Prescaler 64 --> counts up every 8us 13 OCR2 = 125-1; // --> output compare interrupt occurs every 125 x 8us = 1ms 14 // Compare Interrupt erlauben 15 TIMSK |= (1<<OCIE2); 16 8 // TIMER2 is used as local clock: 9 // configure timer 2 10 TCCR2 = (1<<WGM21); // CTC Modus 11 TCCR2 |= (1<<CS21) | (1<<CS20); // Prescaler 64 --> counts up every 8us 12 OCR2 = 125-1; // --> output compare interrupt occurs every 125 x 8us = 1ms 13 // Compare Interrupt erlauben 14 TIMSK |= (1<<OCIE2); 17 15 } 18 16 19 ISR (TIMER2_COMP_vect) 20 { 21 if (milisec < 999) 22 ++milisec; 23 else { 24 milisec = 0; 25 sec++; 26 } 27 17 ISR (TIMER2_COMP_vect) { 18 if (gVolReg.time_ms < 999) 19 ++gVolReg.time_ms; 20 else { 21 gVolReg.time_ms = 0; 22 gVolReg.time_sec++; 23 } 28 24 } -
firmware/FSC/src/timer.h
r10674 r17632 2 2 #define __TIMER_H 3 3 4 extern volatile U16 milisec;5 extern volatile U32 sec;6 7 4 void timer_init(); 8 5 ISR (TIMER2_COMP_vect);
Note:
See TracChangeset
for help on using the changeset viewer.