1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +01:00

EXPERIMENTAL vpin for motorDriver power

No need to use fastpin for power, so we can allow a remoted vpin which helps when TrafficManger is running short of pins
This commit is contained in:
Asbelos 2022-03-23 12:30:21 +00:00
parent 2a87a6e997
commit 99c7ff6c3f
4 changed files with 13 additions and 12 deletions

View File

@ -84,6 +84,9 @@ void setup()
EthernetInterface::setup();
#endif // ETHERNET_ON
// Initialise HAL layer before reading EEprom or setting up MotorDrivers
IODevice::begin();
// Responsibility 3: Start the DCC engine.
// Note: this provides DCC with two motor drivers, main and prog, which handle the motor shield(s)
// Standard supported devices have pre-configured macros but custome hardware installations require

View File

@ -64,9 +64,6 @@ void DCC::begin(const FSH * motorShieldName) {
shieldName=(FSH *)motorShieldName;
StringFormatter::send(Serial,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
// Initialise HAL layer before reading EEprom.
IODevice::begin();
#ifndef DISABLE_EEPROM
// Load stuff from EEprom
(void)EEPROM; // tell compiler not to warn this is unused

View File

@ -33,11 +33,10 @@
bool MotorDriver::usePWM=false;
bool MotorDriver::commonFaultPin=false;
MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
MotorDriver::MotorDriver(VPIN 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) {
powerPin=power_pin;
getFastPin(F("POWER"),powerPin,fastPowerPin);
pinMode(powerPin, OUTPUT);
IODevice::write(powerPin,LOW);// set to OUTPUT and off
signalPin=signal_pin;
getFastPin(F("SIG"),signalPin,fastSignalPin);
@ -102,9 +101,9 @@ void MotorDriver::setPower(POWERMODE mode) {
// on the Pololu board if brake is wired to ^D2.
setBrake(true);
setBrake(false);
setHIGH(fastPowerPin);
IODevice::write(powerPin,HIGH);
}
else setLOW(fastPowerPin);
else IODevice::write(powerPin,LOW);
powerMode=mode;
}
@ -160,7 +159,7 @@ int MotorDriver::getCurrentRaw() {
current = analogRead(currentPin)-senseOffset;
interrupts();
if (current<0) current=0-current;
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON)
return (current == 0 ? -1 : -current);
return current;

View File

@ -22,6 +22,7 @@
#ifndef MotorDriver_h
#define MotorDriver_h
#include "FSH.h"
#include "IODevice.h"
// Virtualised Motor shield 1-track hardware Interface
@ -48,7 +49,7 @@ enum class POWERMODE : byte { OFF, ON, OVERLOAD };
class MotorDriver {
public:
MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin,
MotorDriver(VPIN 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( POWERMODE mode);
virtual POWERMODE getPower() { return powerMode;}
@ -75,8 +76,9 @@ class MotorDriver {
void getFastPin(const FSH* type,int pin, FASTPIN & result) {
getFastPin(type, pin, 0, result);
}
byte powerPin, signalPin, signalPin2, currentPin, faultPin, brakePin;
FASTPIN fastPowerPin,fastSignalPin, fastSignalPin2, fastBrakePin,fastFaultPin;
VPIN powerPin;
byte signalPin, signalPin2, currentPin, faultPin, brakePin;
FASTPIN fastSignalPin, fastSignalPin2, fastBrakePin,fastFaultPin;
bool dualSignal; // true to use signalPin2
bool invertBrake; // brake pin passed as negative means pin is inverted
float senseFactor;