127 |
127 |
128 writeBit(PORTD, 4, 1); |
128 writeBit(PORTD, 4, 1); |
129 SREG = sr; |
129 SREG = sr; |
130 } |
130 } |
131 |
131 |
132 volatile uint8_t pulse_counter = 0; |
132 volatile uint16_t pulse_counter = 0; |
133 volatile uint8_t measure_progress = 0; |
133 volatile uint8_t measure_progress = 0; |
134 volatile uint8_t car_id = 0; |
134 volatile uint16_t car_id = 0; |
135 ISR(TIMER2_OVF_vect) { |
135 ISR(TIMER2_OVF_vect) { |
136 //TCNT2 = 0x90; |
136 TCNT2 = 0xF5; |
137 pulse_counter++; |
137 pulse_counter++; |
138 } |
138 } |
139 |
139 |
140 ISR (INT1_vect) { |
140 ISR (INT1_vect) { |
141 // measure pulse width |
141 // measure pulse width |
142 //RS232_putc('x'); |
142 //RS232_putc('x'); |
143 if (measure_progress == 0) { |
143 if (measure_progress == 0) { |
144 // start measuring |
144 // start measuring |
|
145 TCNT2 = 0xF5; |
145 pulse_counter = 0; |
146 pulse_counter = 0; |
146 measure_progress = 1; |
147 measure_progress = 1; |
147 // set INT1 to rising edge (stops current measurement) |
148 // set INT1 to rising edge (stops current measurement) |
148 //MCUCR |= _BV(ISC10); |
149 //MCUCR |= _BV(ISC10); |
149 writeBit(PORTD, 4, 1); |
150 writeBit(PORTD, 4, 1); |
177 //TCCR2 = (1<<CS21); // divide 8 |
178 //TCCR2 = (1<<CS21); // divide 8 |
178 TCCR2 = (1<<CS20); // divide 1 |
179 TCCR2 = (1<<CS20); // divide 1 |
179 TIMSK = 1<<TOIE2; |
180 TIMSK = 1<<TOIE2; |
180 |
181 |
181 // configure INT0+1 for falling edge |
182 // configure INT0+1 for falling edge |
182 MCUCR = _BV(ISC00) | _BV(ISC11); |
183 // INT2 on every edge |
183 // GICR = _BV(INT0) | _BV(INT1) ; // Enable INT0/2 |
184 //MCUCR = _BV(ISC00) | _BV(ISC11); |
184 GICR = _BV(INT1) ; // Enable INT0/2 |
185 MCUCR = _BV(ISC11); |
|
186 // GICR = _BV(INT0) | _BV(INT1) ; // Enable INT0/1 |
|
187 GICR = _BV(INT1) ; // Enable INT1 |
185 |
188 |
186 writeBit(DDRD, 4, 1); |
189 writeBit(DDRD, 4, 1); |
187 |
190 |
188 |
191 |
189 RS232_init(); // initialize RS485 interface |
192 RS232_init(); // initialize RS232 interface |
190 RS232_puts_p(PSTR("INIT OK\n")); |
193 RS232_puts_p(PSTR("INIT OK\n")); |
191 |
194 |
192 itoa (TIMER_100US, s, 10); |
|
193 RS232_puts(s); |
|
194 |
|
195 RS232_puts_p(PSTR(" timer\n")); |
|
196 i = 0; |
195 i = 0; |
197 |
196 |
198 sei(); |
197 sei(); |
199 while (1) { |
198 while (1) { |
200 // main loop |
199 // main loop |