From b12be53ad067fb4351f4725d8df1a395bb1e5b17 Mon Sep 17 00:00:00 2001 From: Richard Unger Date: Fri, 12 May 2023 23:01:43 +0200 Subject: [PATCH 1/5] fix micros overflow error in Sensor.cpp --- src/common/base_classes/Sensor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/base_classes/Sensor.cpp b/src/common/base_classes/Sensor.cpp index 28511762..a80fa438 100644 --- a/src/common/base_classes/Sensor.cpp +++ b/src/common/base_classes/Sensor.cpp @@ -18,7 +18,12 @@ void Sensor::update() { float Sensor::getVelocity() { // calculate sample time float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6; - // TODO handle overflow - we do need to reset vel_angle_prev_ts + if (Ts < 0.0f) { // handle micros() overflow - we need to reset vel_angle_prev_ts + vel_angle_prev = angle_prev; + vel_full_rotations = full_rotations; + vel_angle_prev_ts = angle_prev_ts; + return velocity; + } if (Ts < min_elapsed_time) return velocity; // don't update velocity if deltaT is too small velocity = ( (float)(full_rotations - vel_full_rotations)*_2PI + (angle_prev - vel_angle_prev) ) / Ts; From 3bb05d0371637284b92387d699be3fb0a07901fe Mon Sep 17 00:00:00 2001 From: Richard Unger Date: Fri, 12 May 2023 23:01:59 +0200 Subject: [PATCH 2/5] Simplify HW-dependent define --- src/communication/StepDirListener.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/communication/StepDirListener.h b/src/communication/StepDirListener.h index 9ae13362..44b0e531 100644 --- a/src/communication/StepDirListener.h +++ b/src/communication/StepDirListener.h @@ -5,7 +5,7 @@ #include "../common/foc_utils.h" -#if defined(_STM32_DEF_) || defined(ESP_H) || defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_SAM_DUE) || defined(CORE_TEENSY) || defined(NRF52_SERIES) +#if !defined(TARGET_RP2040) #define PinStatus int #endif From 9b68c8e12022b4510e8360ec85a063190c7bdb03 Mon Sep 17 00:00:00 2001 From: Richard Unger Date: Fri, 12 May 2023 23:02:57 +0200 Subject: [PATCH 3/5] fix [BUG] RP2040 ADC Engine #264 --- src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp b/src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp index 40c13e34..22bb891a 100644 --- a/src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp +++ b/src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp @@ -10,6 +10,7 @@ #include "hardware/dma.h" #include "hardware/irq.h" #include "hardware/pwm.h" +#include "hardware/adc.h" /* Singleton instance of the ADC engine */ From 95bb2c3fde21c76cce53fe5980793dd4828997c6 Mon Sep 17 00:00:00 2001 From: Richard Unger Date: Fri, 12 May 2023 23:11:17 +0200 Subject: [PATCH 4/5] fix SAMD compile error --- src/communication/StepDirListener.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/communication/StepDirListener.h b/src/communication/StepDirListener.h index 44b0e531..5de0783f 100644 --- a/src/communication/StepDirListener.h +++ b/src/communication/StepDirListener.h @@ -5,7 +5,7 @@ #include "../common/foc_utils.h" -#if !defined(TARGET_RP2040) +#if !defined(TARGET_RP2040) && !defined(_SAMD21_) && !defined(_SAMD51_) && !defined(_SAME51_) #define PinStatus int #endif From 55debc4acb0c945d6967a2451d5615041c5b1a7d Mon Sep 17 00:00:00 2001 From: Richard Unger Date: Fri, 12 May 2023 23:38:09 +0200 Subject: [PATCH 5/5] change NOT_SET to float type --- src/common/foc_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/foc_utils.h b/src/common/foc_utils.h index e1e0b153..c5ff1852 100644 --- a/src/common/foc_utils.h +++ b/src/common/foc_utils.h @@ -28,7 +28,7 @@ #define _PI_6 0.52359877559f #define _RPM_TO_RADS 0.10471975512f -#define NOT_SET -12345.0 +#define NOT_SET -12345.0f #define _HIGH_IMPEDANCE 0 #define _HIGH_Z _HIGH_IMPEDANCE #define _ACTIVE 1