#include <msp430x16x.h>#include <vcs_bsp/vcsbsp.h>#include <signal.h>Include dependency graph for timer.c:

Go to the source code of this file.
Functions | |
| void | init_timer_a (void) |
| interrupt (TIMERA0_VECTOR) | |
| void | init_timer_b (void) |
| interrupt (TIMERB0_VECTOR) | |
| interrupt (TIMERB1_VECTOR) | |
Variables | |
| volatile unsigned long | TB0_edge_time = 0 |
| volatile unsigned long | vspeed4_period_uS = 0 |
| volatile int | vspeed4_data_ready = 0 |
| volatile int | tick_10mS = 0 |
|
|
Definition at line 54 of file timer.c. Referenced by init_bsp(). 00054 {
00055 // SMCLK/8 SOURCE
00056 // Timer in Continuous Mode
00057 // 1mS interrupt rate
00058 TACTL=TASSEL1|ID1|ID0|MC1|TACLR;
00059 TACCTL0=CCIE;
00060 TACCR0=50000;
00061 }
|
|
|
Definition at line 68 of file timer.c. Referenced by init_bsp(). 00068 {
00069 // Timer Setup
00070 TBCTL = TBSSEL1+ID1+ID0+TBIE; // SMCLK/8, Enable the Timer B interrupt, Timer off
00071
00072 // TB0 Capture Setup
00073 TBCCTL0 = CM0+CCIS0+SCS+CAP+CCIE; // Rising Edge, Synchronize, Enable Interrupt
00074 TBCCTL3 = CM0+CCIS0+SCS+CAP+CCIE; // Rising Edge, Synchronize, Enable Interrupt
00075
00076 // Start Timer B
00077 TBCTL |= MC1; // Continuous 16 bit counter mode
00078 }
|
|
|
Definition at line 139 of file timer.c. References TB0_edge_time, vspeed4_data_ready, and vspeed4_period_uS. 00139 {
00140 static int gps_pulse_indicator=0;
00141 static int gps_pulse_timeout=0;
00142
00143 switch (TBIV) {
00144 case 0x02:
00145 // TB1 VSpeed3
00146 break;
00147 case 0x04:
00148 // TB2 VSpeed2
00149 break;
00150 case 0x06:
00151 // TB3 VSpeed1
00152 if (gps_pulse_indicator) {
00153 DS4_ON;
00154 }
00155 else {
00156 DS4_OFF;
00157 }
00158 gps_pulse_indicator^=1;
00159 gps_pulse_timeout=0;
00160 break;
00161 case 8:
00162 // Channel 4
00163 break;
00164 case 0x0A:
00165 // Channel 5
00166 case 0x0C:
00167 // Channel 6
00168 break;
00169 case 0x0E:
00170 // Timer Overflow
00171 TB0_edge_time += (unsigned long) 0xFFFF;
00172 if (TB0_edge_time > TB0_PERIOD_MAX) {
00173 TB0_edge_time=TB0_PERIOD_MAX;
00174 if (!vspeed4_data_ready) {
00175 vspeed4_period_uS = TB0_edge_time;
00176 vspeed4_data_ready=1;
00177 }
00178 }
00179 if (gps_pulse_timeout>7) {
00180 DS4_OFF; // if we have not seen a transition in 500mS then turn off the indicator LED.
00181 }
00182 else {
00183 gps_pulse_timeout++;
00184 }
00185
00186 break;
00187 }
00188 }
|
|
|
Definition at line 80 of file timer.c. References TB0_edge_time, TB0_PERIOD_MAX, vspeed4_data_ready, and vspeed4_period_uS. 00080 {
00081 static unsigned int TB0_edge_last = 0;
00082 static int TB0_indicator = 0;
00083 static unsigned int TB0_filter_index=0;
00084 static unsigned long TB0_filter_bank[8] = {TB0_PERIOD_MAX,TB0_PERIOD_MAX,TB0_PERIOD_MAX,TB0_PERIOD_MAX,
00085 TB0_PERIOD_MAX,TB0_PERIOD_MAX,TB0_PERIOD_MAX,TB0_PERIOD_MAX};
00086 unsigned int TB0_temp;
00087 unsigned long TB0_accumulator=0;
00088 int i;
00089
00090 // TB0 Vspeed 4
00091 TB0_temp = TBCCR0; // Latch the timer value in the event that another edge arrives.
00092 if ((TBCTL&TBIFG) && (TB0_temp<0x7fff)) { // Handle case of timer overflow pending. TB0 is higher priority.
00093 TB0_edge_time += (unsigned long) 0xFFFF; // Add in the overflow value.
00094 TBCTL&=~TBIFG; // Clear the int flag so that we do not handle this rollover again
00095 }
00096
00097 // 1 or more rollovers have occured.
00098 if (TB0_edge_time) {
00099 TB0_edge_time += (unsigned long) 0xFFFF - (unsigned long) TB0_edge_last + (unsigned long) TB0_temp;
00100 TB0_edge_time -= (unsigned long) 0xFFFF;
00101 }
00102 // No rollovers have occured.
00103 else {
00104 TB0_edge_time = (unsigned long) TB0_temp - (unsigned long) TB0_edge_last;
00105 }
00106
00107 // Clamp the largest possible period to TB0_PERIOD_MAX
00108 if (TB0_edge_time > TB0_PERIOD_MAX) {
00109 TB0_edge_time=TB0_PERIOD_MAX;
00110 }
00111
00112 // Filter the signal
00113 TB0_filter_bank[TB0_filter_index++] = TB0_edge_time; // grab the latest data
00114 TB0_filter_index&=0x07; // Wrap the index to make the array circular
00115 for (i=0;i<8;i++) { // sweep through the array
00116 TB0_accumulator+=TB0_filter_bank[i]; // Sum the terms in the filter array
00117 }
00118 TB0_accumulator>>=3; // Divide by the array length (8);
00119
00120 // report the new data if the last piece has been read. Prevents read coherency issue with unsigned long.
00121 if (!vspeed4_data_ready) {
00122 vspeed4_period_uS = TB0_accumulator;// TB0_edge_time;// TB0_accumulator; //
00123 vspeed4_data_ready=1;
00124 }
00125
00126 // prepare for the next edge.
00127 TB0_edge_last = TB0_temp;
00128 TB0_edge_time = 0;
00129
00130 // Blink the TB0 Led
00131 if ((TB0_indicator^=1)) {
00132 DS1_ON;
00133 }
00134 else {
00135 DS1_OFF;
00136 }
00137 }
|
|
|
Definition at line 63 of file timer.c. References tick_10mS. 00063 {
00064 TACCR0+=10000;
00065 tick_10mS=1;
00066 }
|
|
|
Definition at line 49 of file timer.c. Referenced by interrupt(). |
|
|
Definition at line 52 of file timer.c. Referenced by interrupt(). |
|
|
Definition at line 51 of file timer.c. Referenced by interrupt(). |
|
|
Definition at line 50 of file timer.c. Referenced by interrupt(). |
1.3.9.1