mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 16:16:13 +01:00
UNTESTED fast power,brake,fault pins
This commit is contained in:
parent
9dd210fa14
commit
653c421400
|
@ -22,10 +22,14 @@
|
||||||
|
|
||||||
#define setHIGH(fastpin) *fastpin.out |= fastpin.maskHIGH
|
#define setHIGH(fastpin) *fastpin.out |= fastpin.maskHIGH
|
||||||
#define setLOW(fastpin) *fastpin.out &= fastpin.maskLOW
|
#define setLOW(fastpin) *fastpin.out &= fastpin.maskLOW
|
||||||
|
#define isHIGH(fastpin) (*fastpin.out & fastpin.maskHIGH)
|
||||||
|
#define isLOW(fastpin) (!isHIGH(fastpin))
|
||||||
|
|
||||||
|
|
||||||
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
|
MotorDriver::MotorDriver(byte 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, byte fault_pin) {
|
||||||
powerPin=power_pin;
|
powerPin=power_pin;
|
||||||
|
getFastPin(F("POWER"),powerPin,fastPowerPin);
|
||||||
pinMode(powerPin, OUTPUT);
|
pinMode(powerPin, OUTPUT);
|
||||||
|
|
||||||
signalPin=signal_pin;
|
signalPin=signal_pin;
|
||||||
|
@ -41,16 +45,23 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
|
||||||
else dualSignal=false;
|
else dualSignal=false;
|
||||||
|
|
||||||
brakePin=brake_pin;
|
brakePin=brake_pin;
|
||||||
if (brakePin!=UNUSED_PIN){
|
if (brake_pin!=UNUSED_PIN){
|
||||||
pinMode(brakePin < 0 ? -brakePin : brakePin, OUTPUT);
|
invertBrake=brake_pin < 0;
|
||||||
|
brakePin=invertBrake ? 0-brake_pin : brake_pin;
|
||||||
|
getFastPin(F("BRAKE"),brakePin,fastBrakePin);
|
||||||
|
pinMode(brakePin, OUTPUT);
|
||||||
setBrake(false);
|
setBrake(false);
|
||||||
}
|
}
|
||||||
|
else brakePin=UNUSED_PIN;
|
||||||
|
|
||||||
currentPin=current_pin;
|
currentPin=current_pin;
|
||||||
pinMode(currentPin, INPUT);
|
pinMode(currentPin, INPUT);
|
||||||
|
|
||||||
faultPin=fault_pin;
|
faultPin=fault_pin;
|
||||||
if (faultPin != UNUSED_PIN) pinMode(faultPin, INPUT);
|
if (faultPin != UNUSED_PIN) {
|
||||||
|
getFastPin(F("FAULT"),faultPin,fastFaultPin);
|
||||||
|
pinMode(faultPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
senseFactor=sense_factor;
|
senseFactor=sense_factor;
|
||||||
tripMilliamps=trip_milliamps;
|
tripMilliamps=trip_milliamps;
|
||||||
|
@ -59,13 +70,14 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setPower(bool on) {
|
void MotorDriver::setPower(bool on) {
|
||||||
if (brakePin == -4 && on) {
|
if (on) {
|
||||||
// toggle brake before turning power on - resets overcurrent error
|
// toggle brake before turning power on - resets overcurrent error
|
||||||
// on the Pololu board if brake is wired to ^D2.
|
// on the Pololu board if brake is wired to ^D2.
|
||||||
setBrake(true);
|
setBrake(true);
|
||||||
setBrake(false);
|
setBrake(false);
|
||||||
|
setHIGH(fastPowerPin);
|
||||||
}
|
}
|
||||||
digitalWrite(powerPin, on ? HIGH : LOW);
|
else setLOW(fastPowerPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setBrake applies brake if on == true. So to get
|
// setBrake applies brake if on == true. So to get
|
||||||
|
@ -77,13 +89,9 @@ void MotorDriver::setPower(bool on) {
|
||||||
// compensate for that.
|
// compensate for that.
|
||||||
//
|
//
|
||||||
void MotorDriver::setBrake(bool on) {
|
void MotorDriver::setBrake(bool on) {
|
||||||
bool state = on;
|
if (brakePin == UNUSED_PIN) return;
|
||||||
byte pin = brakePin;
|
if (on ^ invertBrake) setHIGH(fastBrakePin);
|
||||||
if (brakePin < 0) {
|
else setLOW(fastBrakePin);
|
||||||
pin=-pin;
|
|
||||||
state=!state;
|
|
||||||
}
|
|
||||||
digitalWrite(pin, state ? HIGH : LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setSignal( bool high) {
|
void MotorDriver::setSignal( bool high) {
|
||||||
|
@ -99,7 +107,7 @@ void MotorDriver::setSignal( bool high) {
|
||||||
|
|
||||||
|
|
||||||
int MotorDriver::getCurrentRaw() {
|
int MotorDriver::getCurrentRaw() {
|
||||||
if (faultPin != UNUSED_PIN && digitalRead(faultPin) == LOW && digitalRead(powerPin) == HIGH)
|
if (faultPin != UNUSED_PIN && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
|
||||||
return simulatedOverload;
|
return simulatedOverload;
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
@ -47,10 +47,10 @@ class MotorDriver {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void getFastPin(const FSH* type,int pin, FASTPIN & result);
|
void getFastPin(const FSH* type,int pin, FASTPIN & result);
|
||||||
byte powerPin, signalPin, signalPin2, currentPin, faultPin;
|
byte powerPin, signalPin, signalPin2, currentPin, faultPin, brakePin;
|
||||||
FASTPIN fastSignalPin, fastSignalPin2;
|
FASTPIN fastPowerPin,fastSignalPin, fastSignalPin2, fastBrakePin,fastFaultPin;
|
||||||
bool dualSignal; // true to use signalPin2
|
bool dualSignal; // true to use signalPin2
|
||||||
int8_t brakePin; // negative means pin is inverted
|
bool invertBrake; // brake pin passed as negative means pin is inverted
|
||||||
float senseFactor;
|
float senseFactor;
|
||||||
unsigned int tripMilliamps;
|
unsigned int tripMilliamps;
|
||||||
int rawCurrentTripValue;
|
int rawCurrentTripValue;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user