Skip to content

Commit

Permalink
Fix issues with higher speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolNamesAllTaken committed Nov 1, 2020
1 parent de46491 commit dca1f4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/radar_speed_sign/include/hb100.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HB100 {
public:
// sad sad, these are exposed because I need to hit them in an ISR
volatile uint32_t last_pulse_period{0};
volatile uint32_t last_pulse_ms{0};
volatile uint32_t last_pulse_us{0};

HB100(){}

Expand Down
2 changes: 1 addition & 1 deletion code/radar_speed_sign/src/hb100.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "hb100.hh"

uint16_t HB100::calc_speed() {
uint16_t curr_speed = 31360 / last_pulse_period / 1000; // V = Fd / 31.36, Fd = 1 / last_pulse_period[s]
uint16_t curr_speed = 31360 / last_pulse_period; // V = Fd / 31.36, Fd = 1 / last_pulse_period[s]
_speed_buf[_speed_buf_index] = curr_speed;
_speed_buf_index++;
if (_speed_buf_index >= SPEED_BUF_SIZE) {
Expand Down
8 changes: 5 additions & 3 deletions code/radar_speed_sign/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define ENCODER_STEPS_PER_NOTCH 1


volatile uint32_t last_pulse_ms = millis(); // [ms] time of last radar pulse
volatile uint32_t last_pulse_us = micros(); // [ms] time of last radar pulse
volatile uint32_t last_pulse_period = 0; // [ms] time between last two falling edges from radar

LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_WIDTH_CHARS, LCD_HEIGHT_LINES);
Expand All @@ -38,8 +38,8 @@ void timer1_isr() {
* Interrupt handler that triggers on falling pulses from HB100 radar
**/
void radar_isr() {
hb100.last_pulse_period = millis() - hb100.last_pulse_ms;
hb100.last_pulse_ms = millis();
hb100.last_pulse_period = micros() - hb100.last_pulse_us;
hb100.last_pulse_us = micros();
}

void setup() {
Expand Down Expand Up @@ -72,6 +72,8 @@ void loop() {
// Serial.print("HB100 last pulse period: ");
// Serial.println(hb100.last_pulse_period);
// Serial.print("Calculated speed: ");
Serial.print(hb100.last_pulse_period);
Serial.print(" ");
Serial.println(hb100.calc_speed());
seven_seg.write(hb100.calc_speed());
delay(10);
Expand Down

0 comments on commit dca1f4d

Please sign in to comment.