From f0c1ea958cc9c22cc28b430e4dcdca8d85f128bf Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 2 Mar 2023 10:45:39 +0000 Subject: [PATCH] 4.2.19 sensorOffset bugfix --- MotorDriver.cpp | 15 ++++++++++----- version.h | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 763e5a3..a6a1766 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -90,9 +90,8 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i else brakePin=UNUSED_PIN; currentPin=current_pin; - if (currentPin!=UNUSED_PIN) { - senseOffset = ADCee::init(currentPin); - } + if (currentPin!=UNUSED_PIN) ADCee::init(currentPin); + senseOffset=0; // value can not be obtained until waveform is activated faultPin=fault_pin; if (faultPin != UNUSED_PIN) { @@ -121,8 +120,8 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i if (currentPin==UNUSED_PIN) DIAG(F("** WARNING ** No current or short detection")); else { - DIAG(F("CurrentPin=A%d, Offset=%d, TripValue=%d"), - currentPin-A0, senseOffset,rawCurrentTripValue); + DIAG(F("CurrentPin=A%d, TripValue=%d"), + currentPin-A0, rawCurrentTripValue); // self testing diagnostic for the non-float converters... may be removed when happy // DIAG(F("senseFactorInternal=%d raw2mA(1000)=%d mA2Raw(1000)=%d"), @@ -144,6 +143,12 @@ bool MotorDriver::isPWMCapable() { void MotorDriver::setPower(POWERMODE mode) { bool on=mode==POWERMODE::ON; if (on) { + // when switching a track On, we need to check the crrentOffset with the pin OFF + if (powerMode==POWERMODE::OFF && currentPin!=UNUSED_PIN) { + senseOffset = ADCee::read(currentPin); + DIAG(F("CurrentPin A%d sensOffset=%d"),currentPin-A0,senseOffset); + } + IODevice::write(powerPin,invertPower ? LOW : HIGH); if (isProgTrack) DCCWaveform::progTrack.clearResets(); diff --git a/version.h b/version.h index f846e0d..d621edf 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,8 @@ #include "StringFormatter.h" -#define VERSION "4.2.18" +#define VERSION "4.2.19" +// 4.2.19 - Bugfix for analog reading of track current sensor offeset. // 4.2.18 - I2C Multiplexer support through Extended Addresses, // added for Wire, 4209 and AVR I2C drivers. // - I2C retries when an operation fails.