Automatic commit at Wed Jul 25 15:50:05 WST 2012
[matches/honours.git] / research / TCS / apparatus / source_code / timer.c
1 //***************************************************************************\r
2 //\r
3 //  File........: timer0.c\r
4 //\r
5 //  Author(s)...: ATMEL Norway\r
6 //\r
7 //  Target(s)...: ATmega169\r
8 //\r
9 //  Compiler....: AVR-GCC 4.1.1; avr-libc 1.4.5\r
10 //\r
11 //  Description.: AVR Butterfly Timer0 routines\r
12 //\r
13 //  Revisions...: 1.0\r
14 //\r
15 //  YYYYMMDD - VER. - COMMENT                                       - SIGN.\r
16 //\r
17 //  20030116 - 1.0  - Created                                       - KS\r
18 //  20031009          port to avr-gcc/avr-libc                      - M.Thomas\r
19 //  20070129          SIGNAL->ISR                                   - mt\r
20 //\r
21 //***************************************************************************\r
22 \r
23 //mtA\r
24 //#include <inavr.h>\r
25 //#include "iom169.h"\r
26 #include <stdint.h>\r
27 #include <avr/io.h>\r
28 #include <avr/interrupt.h>\r
29 //mtE\r
30 #include "main.h"\r
31 #include "timer.h"\r
32 #include "setup.h"\r
33 #include "dac.h"\r
34 \r
35 //TIMER_CALLBACK_FUNC CallbackFunc[TIMER0_NUM_CALLBACKS];\r
36 \r
37 // Value definition:\r
38 // 0      The timer has expired\r
39 // 1-254  The timer is counting down\r
40 // 255    Free timer\r
41 \r
42 // mt char CountDownTimers[TIMER0_NUM_COUNTDOWNTIMERS];\r
43 //uint8_t CountDownTimers[TIMER0_NUM_COUNTDOWNTIMERS];\r
44 \r
45 /*****************************************************************************\r
46 *\r
47 *   Function name : Timer0_Init\r
48 *\r
49 *   Returns :       None\r
50 *\r
51 *   Parameters :    None\r
52 *\r
53 *   Purpose :       Initialize Timer/Counter 0\r
54 *\r
55 *****************************************************************************/\r
56 void Timer0_Init(void)\r
57 {\r
58     //mt char i;\r
59   //  uint8_t i;\r
60         DDRB |= (1<<SCK);\r
61 \r
62     // Initialize array of callback functions\r
63     //for (i=0; i<TIMER0_NUM_CALLBACKS; i++)\r
64     //    CallbackFunc[i] = NULL;\r
65 \r
66     // Initialize countdown timers\r
67     //for (i=0; i<TIMER0_NUM_COUNTDOWNTIMERS; i++)\r
68     //    CountDownTimers[i] = 255;\r
69 \r
70 \r
71     // Initialize Timer0.\r
72     // Used to give the correct time-delays in the song\r
73 \r
74     // Enable timer0 compare interrupt\r
75     TIMSK0 = (1<<OCIE0A);\r
76 \r
77     // Sets the compare value\r
78     OCR0A = 38;\r
79 \r
80     // Set Clear on Timer Compare (CTC) mode, CLK/256 prescaler\r
81     TCCR0A = (1<<WGM01)|(0<<WGM00)|(4<<CS00);\r
82 }\r
83 \r
84 \r
85 \r
86 /*****************************************************************************\r
87 *\r
88 *   Function name : TIMER0_COMP_interrupt\r
89 *\r
90 *   Returns :       None\r
91 *\r
92 *   Parameters :    None\r
93 *\r
94 *   Purpose :       Check if any functions are to be called\r
95 *\r
96 *****************************************************************************/\r
97 // mtA\r
98 // #pragma vector = TIMER0_COMP_vect\r
99 // __interrupt void TIMER0_COMP_interrupt(void)\r
100 // SIGNAL(SIG_OUTPUT_COMPARE0)\r
101 ISR(TIMER0_COMP_vect)\r
102 {\r
103 \r
104         setup.elapsed_time += 1;\r
105         PORTB ^= (1<<SCK);\r
106 \r
107 }\r

UCC git Repository :: git.ucc.asn.au