From fe6fe09ac8112b7a7410bcd47a137f61ccb234c5 Mon Sep 17 00:00:00 2001 From: "Hans R. Tanner" Date: Wed, 2 Nov 2022 09:40:36 -0400 Subject: [PATCH] baseline calibration --- DCCWaveform.cpp | 30 ++++++++++++++++++++++++++++++ MotorDrivers.h | 4 ++-- StringFormatter.cpp | 3 +-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 8be571f..b2d9b5b 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -297,7 +297,11 @@ void DCCWaveform::setAckBaseline() { if (isMainTrack) return; int baseline=motorDriver->getCurrentRaw(); for (int i = 0; i < 32; i++) +<<<<<<< Updated upstream baseline = max(baseline, motorDriver->getCurrentRaw()); +======= + baseline=max(baseline, motorDriver->getCurrentRaw()); +>>>>>>> Stashed changes ackThreshold= baseline + motorDriver->mA2raw(ackLimitmA); if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"), baseline,motorDriver->raw2mA(baseline), @@ -305,6 +309,32 @@ void DCCWaveform::setAckBaseline() { minAckPulseDuration, maxAckPulseDuration); } +/* +void DCCWaveform::setAckBaseline() { + if (isMainTrack) return; + int baseline = motorDriver->getCurrentRaw(); + + int baselinemin = baseline; + int baselinemax = baseline; + int newSample = 0; + for (int i = 0; i < 32; i++) + { + newSample = motorDriver->getCurrentRaw(); + baselinemax = max(baselinemax, newSample); + baselinemin = min(baselinemin, newSample); + } + baseline = baselinemax; + ackThreshold= baseline + motorDriver->mA2raw(ackLimitmA); + + if (Diag::ACK) DIAG(F("ACK min %d max %d"), baselinemin, baselinemax); + + if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"), + baseline,motorDriver->raw2mA(baseline), + ackThreshold,motorDriver->raw2mA(ackThreshold), + minAckPulseDuration, maxAckPulseDuration); +} +*/ + void DCCWaveform::setAckPending() { if (isMainTrack) return; ackMaxCurrent=0; diff --git a/MotorDrivers.h b/MotorDrivers.h index cfb0dd8..7513855 100644 --- a/MotorDrivers.h +++ b/MotorDrivers.h @@ -47,8 +47,8 @@ // // Arduino standard Motor Shield #define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \ - new MotorDriver(3, 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN), \ - new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, 2000, UNUSED_PIN) + new MotorDriver(3, 12, UNUSED_PIN, UNUSED_PIN, A0, 41.54, 5000, UNUSED_PIN), \ + new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 41.54, 5000, UNUSED_PIN) // Pololu Motor Shield #define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \ diff --git a/StringFormatter.cpp b/StringFormatter.cpp index 73a910f..28ee86d 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -29,13 +29,12 @@ #include "LCDDisplay.h" -bool Diag::ACK=false; +bool Diag::ACK=true; bool Diag::CMD=false; bool Diag::WIFI=false; bool Diag::WITHROTTLE=false; bool Diag::ETHERNET=false; bool Diag::LCN=false; - void StringFormatter::diag( const FSH* input...) { if (!diagSerial) return;