Revision 399f7d1b

View differences:

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 {
scout_avr/src/bom.h
5 5
#include <stdint.h>
6 6
}
7 7

  
8
//#include <bom/bom.h>
9

  
8 10
// constants for direction
9
#define BOM_FRONT 0
10
#define BOM_BACK  1
11
#define BOM_LEFT  2
12
#define BOM_RIGHT 3
11
#define BOM_FRONT 0 //(bom::bom::FRONT)
12
#define BOM_BACK  1 //(bom::bom::BACK)
13
#define BOM_LEFT  2 //(bom::bom::LEFT)
14
#define BOM_RIGHT 3 //(bom::bom::RIGHT)
13 15

  
14 16
// timing, in us, for read of valid bits
15 17
#define MIN_LOW_PW 600
scout_avr/src/range.cpp
12 12
 * 
13 13
 * 37.5ms * 8 MHz / 8 prescaler = 37500 max wait
14 14
 * 37.5ms * 16 MHz / 8 prescaler = problem
15
 * 37.5ms * 16 MHz / 64 prescaler = 9375 max wait
15 16
 */
16 17

  
17 18
struct range_t {
......
64 65
  // enable INT2 and INT3
65 66
  EIMSK |= _BV(INT2) | _BV(INT3);
66 67
  
67
  // CS1 = 2, 1/8 prescaler
68
  // CS1 = 3, 1/64 prescaler
68 69
  // if this is changed, remember to change recv_edge in bom.cpp!
69
  TCCR5B = _BV(CS51);
70
  TCCR5B = _BV(CS50) | _BV(CS51);
70 71

  
71 72
  // set tx as output
72 73
  DDRG |= _BV(DDG1);

Also available in: Unified diff