1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 13:41:23 +01:00

Distunguish between in/out of FASTPIN

This commit is contained in:
Harald Barth 2021-02-04 11:43:13 +01:00
parent 653c421400
commit 514bb31cdd
3 changed files with 26 additions and 15 deletions

View File

@ -119,6 +119,11 @@ void DCCWaveform::checkPowerOverload() {
case POWERMODE::ON: case POWERMODE::ON:
// Check current // Check current
lastCurrent=motorDriver->getCurrentRaw(); lastCurrent=motorDriver->getCurrentRaw();
if (lastCurrent < 0) {
// We have a fault pin condition to take care of
DIAG(F("\n*** %S FAULT PIN ACTIVE TOGGLE POWER ON THIS OR BOTH TRACKS ***\n"), isMainTrack ? F("MAIN") : F("PROG"));
lastCurrent = -lastCurrent;
}
if (lastCurrent <= tripValue) { if (lastCurrent <= tripValue) {
sampleDelay = POWER_SAMPLE_ON_WAIT; sampleDelay = POWER_SAMPLE_ON_WAIT;
if(power_good_counter<100) if(power_good_counter<100)
@ -129,9 +134,9 @@ void DCCWaveform::checkPowerOverload() {
setPowerMode(POWERMODE::OVERLOAD); setPowerMode(POWERMODE::OVERLOAD);
unsigned int mA=motorDriver->raw2mA(lastCurrent); unsigned int mA=motorDriver->raw2mA(lastCurrent);
unsigned int maxmA=motorDriver->raw2mA(tripValue); unsigned int maxmA=motorDriver->raw2mA(tripValue);
DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d offtime=%l ***\n"), isMainTrack ? F("MAIN") : F("PROG"), mA, maxmA, power_sample_overload_wait);
power_good_counter=0; power_good_counter=0;
sampleDelay = power_sample_overload_wait; sampleDelay = power_sample_overload_wait;
DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d offtime=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), mA, maxmA, sampleDelay);
if (power_sample_overload_wait >= 10000) if (power_sample_overload_wait >= 10000)
power_sample_overload_wait = 10000; power_sample_overload_wait = 10000;
else else
@ -142,6 +147,8 @@ void DCCWaveform::checkPowerOverload() {
// Try setting it back on after the OVERLOAD_WAIT // Try setting it back on after the OVERLOAD_WAIT
setPowerMode(POWERMODE::ON); setPowerMode(POWERMODE::ON);
sampleDelay = POWER_SAMPLE_ON_WAIT; sampleDelay = POWER_SAMPLE_ON_WAIT;
// Debug code....
DIAG(F("\n*** %S TRACK POWER RESET delay=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), sampleDelay);
break; break;
default: default:
sampleDelay = 999; // cant get here..meaningless statement to avoid compiler warning. sampleDelay = 999; // cant get here..meaningless statement to avoid compiler warning.

View File

@ -20,9 +20,9 @@
#include "MotorDriver.h" #include "MotorDriver.h"
#include "DIAG.h" #include "DIAG.h"
#define setHIGH(fastpin) *fastpin.out |= fastpin.maskHIGH #define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
#define setLOW(fastpin) *fastpin.out &= fastpin.maskLOW #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
#define isHIGH(fastpin) (*fastpin.out & fastpin.maskHIGH) #define isHIGH(fastpin) (*fastpin.inout & fastpin.maskHIGH)
#define isLOW(fastpin) (!isHIGH(fastpin)) #define isLOW(fastpin) (!isHIGH(fastpin))
@ -59,14 +59,13 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
faultPin=fault_pin; faultPin=fault_pin;
if (faultPin != UNUSED_PIN) { if (faultPin != UNUSED_PIN) {
getFastPin(F("FAULT"),faultPin,fastFaultPin); getFastPin(F("FAULT"),faultPin, 1 /*input*/, fastFaultPin);
pinMode(faultPin, INPUT); pinMode(faultPin, INPUT);
} }
senseFactor=sense_factor; senseFactor=sense_factor;
tripMilliamps=trip_milliamps; tripMilliamps=trip_milliamps;
rawCurrentTripValue=(int)(trip_milliamps / sense_factor); rawCurrentTripValue=(int)(trip_milliamps / sense_factor);
simulatedOverload=(int)(32000/senseFactor);
} }
void MotorDriver::setPower(bool on) { void MotorDriver::setPower(bool on) {
@ -107,13 +106,13 @@ void MotorDriver::setSignal( bool high) {
int MotorDriver::getCurrentRaw() { int MotorDriver::getCurrentRaw() {
int current = analogRead(currentPin);
if (faultPin != UNUSED_PIN && isLOW(fastFaultPin) && isHIGH(fastPowerPin)) if (faultPin != UNUSED_PIN && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
return simulatedOverload; return -current;
return current;
// IMPORTANT: This function can be called in Interrupt() time within the 56uS timer // IMPORTANT: This function can be called in Interrupt() time within the 56uS timer
// The default analogRead takes ~100uS which is catastrphic // The default analogRead takes ~100uS which is catastrphic
// so DCCTimer has set the sample time to be much faster. // so DCCTimer has set the sample time to be much faster.
return analogRead(currentPin);
} }
unsigned int MotorDriver::raw2mA( int raw) { unsigned int MotorDriver::raw2mA( int raw) {
@ -123,11 +122,14 @@ int MotorDriver::mA2raw( unsigned int mA) {
return (int)(mA / senseFactor); return (int)(mA / senseFactor);
} }
void MotorDriver::getFastPin(const FSH* type,int pin, FASTPIN & result) { void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & result) {
DIAG(F("\nMotorDriver %S Pin=%d,"),type,pin); DIAG(F("\nMotorDriver %S Pin=%d,"),type,pin);
uint8_t port = digitalPinToPort(pin); uint8_t port = digitalPinToPort(pin);
result.out = portOutputRegister(port); if (input)
result.inout = portInputRegister(port);
else
result.inout = portOutputRegister(port);
result.maskHIGH = digitalPinToBitMask(pin); result.maskHIGH = digitalPinToBitMask(pin);
result.maskLOW = ~result.maskHIGH; result.maskLOW = ~result.maskHIGH;
DIAG(F(" port=0x%x, out=0x%x, mask=0x%x\n"),port, result.out,result.maskHIGH); DIAG(F(" port=0x%x, inoutpin=0x%x, isinput=%d, mask=0x%x\n"),port, result.inout,input,result.maskHIGH);
} }

View File

@ -27,7 +27,7 @@
#endif #endif
struct FASTPIN { struct FASTPIN {
volatile uint8_t *out; volatile uint8_t *inout;
uint8_t maskHIGH; uint8_t maskHIGH;
uint8_t maskLOW; uint8_t maskLOW;
}; };
@ -46,7 +46,10 @@ class MotorDriver {
} }
private: private:
void getFastPin(const FSH* type,int pin, FASTPIN & result); void getFastPin(const FSH* type,int pin, bool input, FASTPIN & result);
void getFastPin(const FSH* type,int pin, FASTPIN & result) {
getFastPin(type, pin, 0, result);
}
byte powerPin, signalPin, signalPin2, currentPin, faultPin, brakePin; byte powerPin, signalPin, signalPin2, currentPin, faultPin, brakePin;
FASTPIN fastPowerPin,fastSignalPin, fastSignalPin2, fastBrakePin,fastFaultPin; FASTPIN fastPowerPin,fastSignalPin, fastSignalPin2, fastBrakePin,fastFaultPin;
bool dualSignal; // true to use signalPin2 bool dualSignal; // true to use signalPin2
@ -54,6 +57,5 @@ class MotorDriver {
float senseFactor; float senseFactor;
unsigned int tripMilliamps; unsigned int tripMilliamps;
int rawCurrentTripValue; int rawCurrentTripValue;
int simulatedOverload;
}; };
#endif #endif