Revision 399f7d1b
ID | 399f7d1bbc8102e5b1859f12ce0a1ec7daeb821d |
Changed sonar/bom timer to 64 prescalar
Also fixed bug in the bom's timer usage, where it depended on an integer
overflow that was no longer occuring due to the higher F_CPU.
scout_avr/src/bom.cpp | ||
---|---|---|
152 | 152 |
if (is_rising) { |
153 | 153 |
// TODO check 320us? or have 320us timeout on rising edge? |
154 | 154 |
} else { |
155 |
// uses timer 5, assuming prescale 1/8
|
|
155 |
// uses timer 5, assuming prescale 1/64
|
|
156 | 156 |
// timer 5 is set up by range_init() |
157 |
// this should be in units of microseconds |
|
158 |
int now = TCNT5 / (F_CPU / 8 / 1000000); |
|
157 |
int now = TCNT5; |
|
158 |
int min_low = TIME_MICROS(MIN_LOW_PW, 64); |
|
159 |
int max_low = TIME_MICROS(MAX_LOW_PW, 64); |
|
160 |
int min_high = TIME_MICROS(MIN_HIGH_PW, 64); |
|
161 |
int max_high = TIME_MICROS(MAX_HIGH_PW, 64); |
|
159 | 162 |
|
160 | 163 |
if (rx->count) { |
161 |
int diff = now - rx->last_time;
|
|
164 |
int diff = (now - rx->last_time);
|
|
162 | 165 |
rx->bits <<= 1; |
163 |
if (MIN_LOW_PW < diff && diff < MAX_LOW_PW) {
|
|
166 |
if (min_low < diff && diff < max_low) {
|
|
164 | 167 |
// 0 already in bits |
165 |
} else if (MIN_HIGH_PW < diff && diff < MAX_HIGH_PW) {
|
|
168 |
} else if (min_high < diff && diff < max_high) {
|
|
166 | 169 |
// add 1 to bits |
167 | 170 |
rx->bits |= 1; |
168 | 171 |
} else { |
Also available in: Unified diff