blackbox/interrupts.c

changeset 141
467e6351986e
parent 89
4b5b4c7ba03d
equal deleted inserted replaced
140:f910ad6ed0b6 141:467e6351986e
120 120
121 ISR (INT0_vect) { 121 ISR (INT0_vect) {
122 // car0 detector 122 // car0 detector
123 uint16_t tmp = 0; 123 uint16_t tmp = 0;
124 car0_new = TCNT1; // get current counter 124 car0_new = TCNT1; // get current counter
125 if (car0_old < car0_new) { 125 if ((car0 == 0) && (car0_old < car0_new)) {
126 // calculate difference 126 // calculate difference
127 if (car0 == 0) tmp = car0_new-car0_old; 127 tmp = car0_new-car0_old;
128 if ( (tmp > 54) && (tmp < 74) ) car0 = 1; 128 if ( (tmp > 54) && (tmp < 74) ) car0 = 1;
129 if ( (tmp > 118) && (tmp < 138) ) car0 = 2; 129 if ( (tmp > 118) && (tmp < 138) ) car0 = 2;
130 if ( (tmp > 186) && (tmp < 206) ) car0 = 3; 130 if ( (tmp > 186) && (tmp < 206) ) car0 = 3;
131 if ( (tmp > 246) && (tmp < 266) ) car0 = 4; 131 if ( (tmp > 246) && (tmp < 266) ) car0 = 4;
132 if ( (tmp > 310) && (tmp < 330) ) car0 = 5; 132 if ( (tmp > 310) && (tmp < 330) ) car0 = 5;
137 137
138 ISR (INT1_vect) { 138 ISR (INT1_vect) {
139 // car1 detector 139 // car1 detector
140 uint16_t tmp = 0; 140 uint16_t tmp = 0;
141 car1_new = TCNT1; // get current counter 141 car1_new = TCNT1; // get current counter
142 if (car1_old < car1_new) { 142 if ((car1 == 0) && (car1_old < car1_new)) {
143 // calculate difference 143 // calculate difference
144 if (car1 == 0) tmp = car1_new-car1_old; 144 tmp = car1_new-car1_old;
145 if ( (tmp > 54) && (tmp < 74) ) car1 = 1; 145 if ( (tmp > 54) && (tmp < 74) ) car1 = 1;
146 if ( (tmp > 118) && (tmp < 138) ) car1 = 2; 146 if ( (tmp > 118) && (tmp < 138) ) car1 = 2;
147 if ( (tmp > 186) && (tmp < 206) ) car1 = 3; 147 if ( (tmp > 186) && (tmp < 206) ) car1 = 3;
148 if ( (tmp > 246) && (tmp < 266) ) car1 = 4; 148 if ( (tmp > 246) && (tmp < 266) ) car1 = 4;
149 if ( (tmp > 310) && (tmp < 330) ) car1 = 5; 149 if ( (tmp > 310) && (tmp < 330) ) car1 = 5;

mercurial