00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <msp430x16x.h>
00046 #include <vcs_bsp/vcsbsp.h>
00047 #include <signal.h>
00048
00049 volatile unsigned long TB0_edge_time = 0;
00050 volatile unsigned long vspeed4_period_uS = 0;
00051 volatile int vspeed4_data_ready=0;
00052 volatile int tick_10mS=0;
00053
00054 void init_timer_a(void) {
00055
00056
00057
00058 TACTL=TASSEL1|ID1|ID0|MC1|TACLR;
00059 TACCTL0=CCIE;
00060 TACCR0=50000;
00061 }
00062
00063 interrupt (TIMERA0_VECTOR) Timer_A0_Handler(void) {
00064 TACCR0+=10000;
00065 tick_10mS=1;
00066 }
00067
00068 void init_timer_b(void) {
00069
00070 TBCTL = TBSSEL1+ID1+ID0+TBIE;
00071
00072
00073 TBCCTL0 = CM0+CCIS0+SCS+CAP+CCIE;
00074 TBCCTL3 = CM0+CCIS0+SCS+CAP+CCIE;
00075
00076
00077 TBCTL |= MC1;
00078 }
00079
00080 interrupt (TIMERB0_VECTOR) Timer_B0(void) {
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
00091 TB0_temp = TBCCR0;
00092 if ((TBCTL&TBIFG) && (TB0_temp<0x7fff)) {
00093 TB0_edge_time += (unsigned long) 0xFFFF;
00094 TBCTL&=~TBIFG;
00095 }
00096
00097
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
00103 else {
00104 TB0_edge_time = (unsigned long) TB0_temp - (unsigned long) TB0_edge_last;
00105 }
00106
00107
00108 if (TB0_edge_time > TB0_PERIOD_MAX) {
00109 TB0_edge_time=TB0_PERIOD_MAX;
00110 }
00111
00112
00113 TB0_filter_bank[TB0_filter_index++] = TB0_edge_time;
00114 TB0_filter_index&=0x07;
00115 for (i=0;i<8;i++) {
00116 TB0_accumulator+=TB0_filter_bank[i];
00117 }
00118 TB0_accumulator>>=3;
00119
00120
00121 if (!vspeed4_data_ready) {
00122 vspeed4_period_uS = TB0_accumulator;
00123 vspeed4_data_ready=1;
00124 }
00125
00126
00127 TB0_edge_last = TB0_temp;
00128 TB0_edge_time = 0;
00129
00130
00131 if ((TB0_indicator^=1)) {
00132 DS1_ON;
00133 }
00134 else {
00135 DS1_OFF;
00136 }
00137 }
00138
00139 interrupt (TIMERB1_VECTOR) Timer_B1(void) {
00140 static int gps_pulse_indicator=0;
00141 static int gps_pulse_timeout=0;
00142
00143 switch (TBIV) {
00144 case 0x02:
00145
00146 break;
00147 case 0x04:
00148
00149 break;
00150 case 0x06:
00151
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
00163 break;
00164 case 0x0A:
00165
00166 case 0x0C:
00167
00168 break;
00169 case 0x0E:
00170
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;
00181 }
00182 else {
00183 gps_pulse_timeout++;
00184 }
00185
00186 break;
00187 }
00188 }
00189
00190
00191