mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-25 00:56:13 +01:00
Compare commits
2 Commits
ab1356d070
...
96a46f36c2
Author | SHA1 | Date | |
---|---|---|---|
|
96a46f36c2 | ||
|
10c59028e1 |
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-overcurrent-202307021155Z"
|
#define GITHUB_SHA "devel-overcurrent-202307022222Z"
|
||||||
|
|
|
@ -173,7 +173,7 @@ bool MotorDriver::isPWMCapable() {
|
||||||
|
|
||||||
void MotorDriver::setPower(POWERMODE mode) {
|
void MotorDriver::setPower(POWERMODE mode) {
|
||||||
if (powerMode == mode) return;
|
if (powerMode == mode) return;
|
||||||
//DIAG(F("POWERMODE=%d"), (int)mode);
|
//DIAG(F("Track %c POWERMODE=%d"), trackLetter, (int)mode);
|
||||||
lastPowerChange[(int)mode] = micros();
|
lastPowerChange[(int)mode] = micros();
|
||||||
if (mode == POWERMODE::OVERLOAD)
|
if (mode == POWERMODE::OVERLOAD)
|
||||||
globalOverloadStart = lastPowerChange[(int)mode];
|
globalOverloadStart = lastPowerChange[(int)mode];
|
||||||
|
@ -376,6 +376,67 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res
|
||||||
// DIAG(F(" port=0x%x, inoutpin=0x%x, isinput=%d, mask=0x%x"),port, result.inout,input,result.maskHIGH);
|
// DIAG(F(" port=0x%x, inoutpin=0x%x, isinput=%d, mask=0x%x"),port, result.inout,input,result.maskHIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// checkPowerOverload(useProgLimit, trackno)
|
||||||
|
// bool useProgLimit: Trackmanager knows if this track is in prog mode or in main mode
|
||||||
|
// byte trackno: trackmanager knows it's number (could be skipped?)
|
||||||
|
//
|
||||||
|
// Short ciruit handling strategy:
|
||||||
|
//
|
||||||
|
// There are the following power states: ON ALERT OVERLOAD OFF
|
||||||
|
// OFF state is only changed to/from manually. Power is on
|
||||||
|
// during ON and ALERT. Power is off during OVERLOAD and OFF.
|
||||||
|
// The overload mechanism changes between the other states like
|
||||||
|
//
|
||||||
|
// ON -1-> ALERT -2-> OVERLOAD -3-> ALERT -4-> ON
|
||||||
|
// or
|
||||||
|
// ON -1-> ALERT -4-> ON
|
||||||
|
//
|
||||||
|
// Times are in class MotorDriver (MotorDriver.h).
|
||||||
|
//
|
||||||
|
// 1. ON to ALERT:
|
||||||
|
// Transition on fault pin condition or current overload
|
||||||
|
//
|
||||||
|
// 2. ALERT to OVERLOAD:
|
||||||
|
// Transition happens if different timeouts have elapsed.
|
||||||
|
// If only the fault pin is active, timeout is
|
||||||
|
// POWER_SAMPLE_IGNORE_FAULT_LOW (100ms)
|
||||||
|
// If only overcurrent is detected, timeout is
|
||||||
|
// POWER_SAMPLE_IGNORE_CURRENT (100ms)
|
||||||
|
// If fault pin and overcurrent are active, timeout is
|
||||||
|
// POWER_SAMPLE_IGNORE_FAULT_HIGH (5ms)
|
||||||
|
// Transition to OVERLOAD turns off power to the affected
|
||||||
|
// output (unless fault pins are shared)
|
||||||
|
// If the transition conditions are not fullfilled,
|
||||||
|
// transition according to 4 is tested.
|
||||||
|
//
|
||||||
|
// 3. OVERLOAD to ALERT
|
||||||
|
// Transiton happens when timeout has elapsed, timeout
|
||||||
|
// is named power_sample_overload_wait. It is started
|
||||||
|
// at POWER_SAMPLE_OVERLOAD_WAIT (40ms) at first entry
|
||||||
|
// to OVERLOAD and then increased by a factor of 2
|
||||||
|
// at further entries to the OVERLOAD condition. This
|
||||||
|
// happens until POWER_SAMPLE_RETRY_MAX (10sec) is reached.
|
||||||
|
// power_sample_overload_wait is reset by a poweroff or
|
||||||
|
// a POWER_SAMPLE_ALL_GOOD (5sec) period during ON.
|
||||||
|
// After timeout power is turned on again and state
|
||||||
|
// goes back to ALERT.
|
||||||
|
//
|
||||||
|
// 4. ALERT to ON
|
||||||
|
// Transition happens by watching the current and fault pin
|
||||||
|
// samples during POWER_SAMPLE_ALERT_GOOD (20ms) time. If
|
||||||
|
// values have been good during that time, transition is
|
||||||
|
// made back to ON. Note that even if state is back to ON,
|
||||||
|
// the power_sample_overload_wait time is first reset
|
||||||
|
// later (see above).
|
||||||
|
//
|
||||||
|
// The time keeping is handled by timestamps lastPowerChange[]
|
||||||
|
// which are set by each power change and by lastBadSample which
|
||||||
|
// keeps track if conditions during ALERT have been good enough
|
||||||
|
// to go back to ON. The time differences are calculated by
|
||||||
|
// microsSinceLastPowerChange().
|
||||||
|
//
|
||||||
|
|
||||||
void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
|
|
||||||
switch (powerMode) {
|
switch (powerMode) {
|
||||||
|
@ -464,7 +525,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||||
unsigned long mslpc = (commonFaultPin ? (micros() - globalOverloadStart) : microsSinceLastPowerChange(POWERMODE::OVERLOAD));
|
unsigned long mslpc = (commonFaultPin ? (micros() - globalOverloadStart) : microsSinceLastPowerChange(POWERMODE::OVERLOAD));
|
||||||
if (mslpc > power_sample_overload_wait) {
|
if (mslpc > power_sample_overload_wait) {
|
||||||
// adjust next wait time
|
// adjust next wait time
|
||||||
power_sample_overload_wait *= 4;
|
power_sample_overload_wait *= 2;
|
||||||
if (power_sample_overload_wait > POWER_SAMPLE_RETRY_MAX)
|
if (power_sample_overload_wait > POWER_SAMPLE_RETRY_MAX)
|
||||||
power_sample_overload_wait = POWER_SAMPLE_RETRY_MAX;
|
power_sample_overload_wait = POWER_SAMPLE_RETRY_MAX;
|
||||||
// power on test
|
// power on test
|
||||||
|
|
|
@ -260,13 +260,13 @@ class MotorDriver {
|
||||||
|
|
||||||
// Times for overload management. Unit: microseconds.
|
// Times for overload management. Unit: microseconds.
|
||||||
// Base for wait time until power is turned on again
|
// Base for wait time until power is turned on again
|
||||||
static const unsigned long POWER_SAMPLE_OVERLOAD_WAIT = 10000UL;
|
static const unsigned long POWER_SAMPLE_OVERLOAD_WAIT = 40000UL;
|
||||||
// Time after we consider all faults old and forgotten
|
// Time after we consider all faults old and forgotten
|
||||||
static const unsigned long POWER_SAMPLE_ALL_GOOD = 5000000UL;
|
static const unsigned long POWER_SAMPLE_ALL_GOOD = 5000000UL;
|
||||||
// Time after which we consider a ALERT over
|
// Time after which we consider a ALERT over
|
||||||
static const unsigned long POWER_SAMPLE_ALERT_GOOD = 20000UL;
|
static const unsigned long POWER_SAMPLE_ALERT_GOOD = 20000UL;
|
||||||
// How long to ignore fault pin if current is under limit
|
// How long to ignore fault pin if current is under limit
|
||||||
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_LOW = 50000UL;
|
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_LOW = 100000UL;
|
||||||
// How long to ignore fault pin if current is higher than limit
|
// How long to ignore fault pin if current is higher than limit
|
||||||
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_HIGH = 5000UL;
|
static const unsigned long POWER_SAMPLE_IGNORE_FAULT_HIGH = 5000UL;
|
||||||
// How long to wait between overcurrent and turning off
|
// How long to wait between overcurrent and turning off
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
#define VERSION "4.2.62pre1"
|
#define VERSION "4.2.62pre2"
|
||||||
// 4.2.62 - completely new overcurrent detection
|
// 4.2.62 - completely new overcurrent detection
|
||||||
// 4.2.61 - MAX_CURRENT restriction (caps motor shield value)
|
// 4.2.61 - MAX_CURRENT restriction (caps motor shield value)
|
||||||
// 4.2.60 - Add mDNS capability to ESP32 for autodiscovery
|
// 4.2.60 - Add mDNS capability to ESP32 for autodiscovery
|
||||||
|
|
Loading…
Reference in New Issue
Block a user