mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
handle motorboards with invereted brake pin (like pololu)
This commit is contained in:
parent
50e85d0b79
commit
7a5b84ef18
|
@ -34,7 +34,7 @@
|
||||||
#define ReadPin digitalRead2
|
#define ReadPin digitalRead2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte 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;
|
||||||
signalPin=signal_pin;
|
signalPin=signal_pin;
|
||||||
|
@ -46,7 +46,8 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte
|
||||||
tripMilliamps=trip_milliamps;
|
tripMilliamps=trip_milliamps;
|
||||||
rawCurrentTripValue=(int)(trip_milliamps / sense_factor);
|
rawCurrentTripValue=(int)(trip_milliamps / sense_factor);
|
||||||
pinMode(powerPin, OUTPUT);
|
pinMode(powerPin, OUTPUT);
|
||||||
pinMode(brakePin, OUTPUT);
|
pinMode(brakePin < 0 ? -brakePin : brakePin, OUTPUT);
|
||||||
|
setBrake(false);
|
||||||
pinMode(signalPin, OUTPUT);
|
pinMode(signalPin, OUTPUT);
|
||||||
if (signalPin2 != UNUSED_PIN) pinMode(signalPin2, OUTPUT);
|
if (signalPin2 != UNUSED_PIN) pinMode(signalPin2, OUTPUT);
|
||||||
pinMode(currentPin, INPUT);
|
pinMode(currentPin, INPUT);
|
||||||
|
@ -56,8 +57,24 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte
|
||||||
void MotorDriver::setPower(bool on) {
|
void MotorDriver::setPower(bool on) {
|
||||||
WritePin(powerPin, on ? HIGH : LOW);
|
WritePin(powerPin, on ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
void MotorDriver::setBrake( bool on) {
|
|
||||||
WritePin(brakePin, on ? HIGH : LOW);
|
// setBrake applies brake if on == true. So to get
|
||||||
|
// voltage from the motor bride one needs to do a
|
||||||
|
// setBrake(false).
|
||||||
|
// If the brakePin is negative that means the sense
|
||||||
|
// of the brake pin on the motor bridge is inverted
|
||||||
|
// (HIGH == release brake) and setBrake does
|
||||||
|
// compensate for that.
|
||||||
|
//
|
||||||
|
void MotorDriver::setBrake(bool on) {
|
||||||
|
bool state = on;
|
||||||
|
byte pin = brakePin;
|
||||||
|
if (brakePin < 0) {
|
||||||
|
pin=-pin;
|
||||||
|
state=!state;
|
||||||
|
}
|
||||||
|
WritePin(pin, state ? HIGH : LOW);
|
||||||
|
//DIAG(F("BrakePin: %d is %d\n"), pin, ReadPin(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorDriver::setSignal( bool high) {
|
void MotorDriver::setSignal( bool high) {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
class MotorDriver {
|
class MotorDriver {
|
||||||
public:
|
public:
|
||||||
MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin, float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin, byte current_pin, float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||||
virtual void setPower( bool on);
|
virtual void setPower( bool on);
|
||||||
virtual void setSignal( bool high);
|
virtual void setSignal( bool high);
|
||||||
virtual void setBrake( bool on);
|
virtual void setBrake( bool on);
|
||||||
|
@ -34,7 +34,8 @@ class MotorDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte powerPin, signalPin, signalPin2, brakePin,currentPin,faultPin;
|
byte powerPin, signalPin, signalPin2, currentPin, faultPin;
|
||||||
|
int8_t brakePin;
|
||||||
float senseFactor;
|
float senseFactor;
|
||||||
unsigned int tripMilliamps;
|
unsigned int tripMilliamps;
|
||||||
int rawCurrentTripValue;
|
int rawCurrentTripValue;
|
||||||
|
|
|
@ -15,8 +15,12 @@
|
||||||
|
|
||||||
const byte UNUSED_PIN = 255;
|
const byte UNUSED_PIN = 255;
|
||||||
|
|
||||||
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin,
|
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin, byte current_pin,
|
||||||
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||||
|
//
|
||||||
|
// If the brakePin is negative that means the sense
|
||||||
|
// of the brake pin on the motor bridge is inverted
|
||||||
|
// (HIGH == release brake)
|
||||||
|
|
||||||
// Arduino standard Motor Shield
|
// Arduino standard Motor Shield
|
||||||
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \
|
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \
|
||||||
|
@ -25,8 +29,8 @@ const byte UNUSED_PIN = 255;
|
||||||
|
|
||||||
// Pololu Motor Shield
|
// Pololu Motor Shield
|
||||||
#define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \
|
#define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \
|
||||||
new MotorDriver(4, 7, UNUSED_PIN, 9, A0, 18, 3000, 12), \
|
new MotorDriver(4, 7, UNUSED_PIN, -9, A0, 18, 3000, 12), \
|
||||||
new MotorDriver(2, 8, UNUSED_PIN, 10, A1, 18, 3000, UNUSED_PIN)
|
new MotorDriver(2, 8, UNUSED_PIN, -10, A1, 18, 3000, UNUSED_PIN)
|
||||||
|
|
||||||
// Firebox Mk1
|
// Firebox Mk1
|
||||||
#define FIREBOX_MK1 F("FIREBOX_MK1"), \
|
#define FIREBOX_MK1 F("FIREBOX_MK1"), \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user