mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
DC via power pin 1st try
This commit is contained in:
parent
2ada89f918
commit
9482041799
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "devel-202302121935Z"
|
||||
#define GITHUB_SHA "devel-202302122239Z"
|
||||
|
|
|
@ -146,12 +146,16 @@ void MotorDriver::setPower(POWERMODE mode) {
|
|||
if (on) {
|
||||
noInterrupts();
|
||||
IODevice::write(powerPin,invertPower ? LOW : HIGH);
|
||||
if (DCinuse)
|
||||
setDCSignal(curSpeedCode);
|
||||
interrupts();
|
||||
if (isProgTrack)
|
||||
DCCWaveform::progTrack.clearResets();
|
||||
}
|
||||
else {
|
||||
noInterrupts();
|
||||
if (DCinuse)
|
||||
detachDCSignal();
|
||||
IODevice::write(powerPin,invertPower ? HIGH : LOW);
|
||||
interrupts();
|
||||
}
|
||||
|
@ -245,8 +249,9 @@ uint16_t taurustones[28] = { 165, 175, 196, 220,
|
|||
220, 196, 175, 165 };
|
||||
#endif
|
||||
void MotorDriver::setDCSignal(byte speedcode) {
|
||||
if (brakePin == UNUSED_PIN)
|
||||
return;
|
||||
curSpeedCode = speedcode;
|
||||
DCinuse = true;
|
||||
|
||||
#if defined(ARDUINO_AVR_UNO)
|
||||
TCCR2B = (TCCR2B & B11111000) | B00000110; // set divisor on timer 2 to result in (approx) 122.55Hz
|
||||
#endif
|
||||
|
@ -257,7 +262,7 @@ void MotorDriver::setDCSignal(byte speedcode) {
|
|||
// spedcoode is a dcc speed & direction
|
||||
byte tSpeed=speedcode & 0x7F; // DCC Speed with 0,1 stop and speed steps 2 to 127
|
||||
byte tDir=speedcode & 0x80;
|
||||
byte brake;
|
||||
byte pwmratio;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
{
|
||||
int f = 131;
|
||||
|
@ -266,18 +271,18 @@ void MotorDriver::setDCSignal(byte speedcode) {
|
|||
f = taurustones[ (tSpeed-2)/2 ] ;
|
||||
}
|
||||
}
|
||||
DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency to 100Hz XXX May move to setup
|
||||
DCCEXanalogWriteFrequency(powerPin, f); // set DC PWM frequency to 100Hz XXX May move to setup
|
||||
}
|
||||
#endif
|
||||
if (tSpeed <= 1) brake = 255;
|
||||
else if (tSpeed >= 127) brake = 0;
|
||||
else brake = 2 * (128-tSpeed);
|
||||
if (invertBrake)
|
||||
brake=255-brake;
|
||||
if (tSpeed <= 1) pwmratio = 0;
|
||||
else if (tSpeed >= 127) pwmratio = 255;
|
||||
else pwmratio = 2 * tSpeed;
|
||||
if (invertPower)
|
||||
pwmratio =255-pwmratio;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
DCCEXanalogWrite(brakePin,brake);
|
||||
DCCEXanalogWrite(powerPin,pwmratio);
|
||||
#else
|
||||
analogWrite(brakePin,brake);
|
||||
analogWrite(powerPin,pwmratio);
|
||||
#endif
|
||||
//DIAG(F("DCSignal %d"), speedcode);
|
||||
if (HAVE_PORTA(fastSignalPin.shadowinout == &PORTA)) {
|
||||
|
|
|
@ -152,6 +152,7 @@ class MotorDriver {
|
|||
#else
|
||||
setDCSignal(128);
|
||||
#endif
|
||||
DCinuse = false;
|
||||
};
|
||||
int getCurrentRaw(bool fromISR=false);
|
||||
unsigned int raw2mA( int raw);
|
||||
|
@ -232,6 +233,7 @@ class MotorDriver {
|
|||
static const int TRIP_CURRENT_PROG=250;
|
||||
unsigned long power_sample_overload_wait = POWER_SAMPLE_OVERLOAD_WAIT;
|
||||
unsigned int power_good_counter = 0;
|
||||
|
||||
bool DCinuse = false;
|
||||
byte curSpeedCode = 0;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -218,7 +218,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
|||
if (!(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX)) {
|
||||
// DCC tracks need to have set the PWM to zero or they will not work.
|
||||
track[trackToSet]->detachDCSignal();
|
||||
track[trackToSet]->setBrake(false);
|
||||
//track[trackToSet]->setBrake(false);
|
||||
}
|
||||
|
||||
// EXT is a special case where the signal pin is
|
||||
|
@ -396,7 +396,7 @@ void TrackManager::setPower2(bool setProg,POWERMODE mode) {
|
|||
case TRACK_MODE_DC:
|
||||
case TRACK_MODE_DCX:
|
||||
if (setProg) break;
|
||||
driver->setBrake(true); // DC starts with brake on
|
||||
//driver->setBrake(true); // DC starts with brake on
|
||||
applyDCSpeed(t); // speed match DCC throttles
|
||||
driver->setPower(mode);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user