mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
faultPin can be inverted (from its inverted sense
This commit is contained in:
parent
22c0bff697
commit
31ecba08d8
|
@ -38,7 +38,7 @@ volatile portreg_t shadowPORTB;
|
||||||
volatile portreg_t shadowPORTC;
|
volatile portreg_t shadowPORTC;
|
||||||
|
|
||||||
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
||||||
byte current_pin, float sense_factor, unsigned int trip_milliamps, byte fault_pin) {
|
byte current_pin, float sense_factor, unsigned int trip_milliamps, int8_t fault_pin) {
|
||||||
powerPin=power_pin;
|
powerPin=power_pin;
|
||||||
invertPower=power_pin < 0;
|
invertPower=power_pin < 0;
|
||||||
if (invertPower) {
|
if (invertPower) {
|
||||||
|
@ -95,6 +95,9 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
||||||
|
|
||||||
faultPin=fault_pin;
|
faultPin=fault_pin;
|
||||||
if (faultPin != UNUSED_PIN) {
|
if (faultPin != UNUSED_PIN) {
|
||||||
|
invertFault=fault_pin < 0;
|
||||||
|
faultPin=invertFault ? 0-fault_pin : fault_pin;
|
||||||
|
DIAG(F("Fault pin = %d invert %d"), faultPin, invertFault);
|
||||||
getFastPin(F("FAULT"),faultPin, 1 /*input*/, fastFaultPin);
|
getFastPin(F("FAULT"),faultPin, 1 /*input*/, fastFaultPin);
|
||||||
pinMode(faultPin, INPUT);
|
pinMode(faultPin, INPUT);
|
||||||
}
|
}
|
||||||
|
@ -196,8 +199,12 @@ int MotorDriver::getCurrentRaw(bool fromISR) {
|
||||||
int current;
|
int current;
|
||||||
current = ADCee::read(currentPin, fromISR)-senseOffset;
|
current = ADCee::read(currentPin, fromISR)-senseOffset;
|
||||||
if (current<0) current=0-current;
|
if (current<0) current=0-current;
|
||||||
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON)
|
if ((faultPin != UNUSED_PIN) && powerMode==POWERMODE::ON) {
|
||||||
|
if (invertFault && isLOW(fastFaultPin))
|
||||||
return (current == 0 ? -1 : -current);
|
return (current == 0 ? -1 : -current);
|
||||||
|
if (!invertFault && !isLOW(fastFaultPin))
|
||||||
|
return (current == 0 ? -1 : -current);
|
||||||
|
}
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ class MotorDriver {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
||||||
byte current_pin, float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
byte current_pin, float senseFactor, unsigned int tripMilliamps, int8_t fault_pin);
|
||||||
void setPower( POWERMODE mode);
|
void setPower( POWERMODE mode);
|
||||||
POWERMODE getPower() { return powerMode;}
|
POWERMODE getPower() { return powerMode;}
|
||||||
// as the port registers can be shadowed to get syncronized DCC signals
|
// as the port registers can be shadowed to get syncronized DCC signals
|
||||||
|
@ -198,6 +198,7 @@ class MotorDriver {
|
||||||
bool dualSignal; // true to use signalPin2
|
bool dualSignal; // true to use signalPin2
|
||||||
bool invertBrake; // brake pin passed as negative means pin is inverted
|
bool invertBrake; // brake pin passed as negative means pin is inverted
|
||||||
bool invertPower; // power pin passed as negative means pin is inverted
|
bool invertPower; // power pin passed as negative means pin is inverted
|
||||||
|
bool invertFault; // fault pin passed as negative means pin is inverted
|
||||||
|
|
||||||
// Raw to milliamp conversion factors avoiding float data types.
|
// Raw to milliamp conversion factors avoiding float data types.
|
||||||
// Milliamps=rawADCreading * sensefactorInternal / senseScale
|
// Milliamps=rawADCreading * sensefactorInternal / senseScale
|
||||||
|
|
Loading…
Reference in New Issue
Block a user