1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

DC frequency fix bit shifting (debug code) step #4

This commit is contained in:
Harald Barth 2023-12-31 10:48:48 +01:00
parent bf17f2018b
commit ba0a41b6f2
6 changed files with 20 additions and 17 deletions

19
DCC.cpp
View File

@ -153,12 +153,14 @@ uint8_t DCC::getThrottleSpeedByte(int cab) {
return speedTable[reg].speedCode;
}
// returns -1 for fault, 0 to 3 for frequency
int8_t DCC::getThrottleFrequency(int cab) {
// returns 0 to 3 for frequency
uint8_t DCC::getThrottleFrequency(int cab) {
int reg=lookupSpeedTable(cab);
if (reg<0)
return -1;
return (int8_t)(speedTable[reg].functions >>29); // shift out first 29 bits so we have the "frequency bits" left
return 0; // use default frequency
uint8_t res = (uint8_t)(speedTable[reg].functions >>30);
DIAG(F("Speed table %d functions %l shifted %d"), reg, speedTable[reg].functions, res);
return res; // shift out first 29 bits so we have the "frequency bits" left
}
// returns direction on loco
@ -191,9 +193,12 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
b[nB++] = functionNumber >>7 ; // high order bits
}
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
return true;
}
// We use the reminder table up to 28 for normal functions.
// We use 29 to 31 for DC frequency as well.
if (functionNumber > 31)
return true;
int reg = lookupSpeedTable(cab);
if (reg<0) return false;
@ -206,7 +211,7 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
} else {
speedTable[reg].functions &= ~funcmask;
}
if (speedTable[reg].functions != previous) {
if (speedTable[reg].functions != previous && functionNumber > 28) {
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
CommandDistributor::broadcastLoco(reg);
}

2
DCC.h
View File

@ -61,7 +61,7 @@ public:
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
static int8_t getThrottleSpeed(int cab);
static uint8_t getThrottleSpeedByte(int cab);
static int8_t getThrottleFrequency(int cab);
static uint8_t getThrottleFrequency(int cab);
static bool getThrottleDirection(int cab);
static void writeCVByteMain(int cab, int cv, byte bValue);
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);

View File

@ -142,9 +142,9 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
if (pin == 9 || pin == 10) { // timer 2 is different
if (fbits >= 3)
abits = B11;
abits = B00000011;
else
abits = B01;
abits = B00000001;
if (fbits >= 3)
bbits = B0001;

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202312251647Z"
#define GITHUB_SHA "devel-202312310824Z"

View File

@ -349,6 +349,7 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
}
}
#endif
DIAG(F("Brake %d freqencybits %x"), brakePin, f);
DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency to 100Hz XXX May move to setup
DCCTimer::DCCEXanalogWrite(brakePin,brake);
#else // all AVR here

View File

@ -202,7 +202,7 @@ void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
FOR_EACH_TRACK(t) {
if (trackDCAddr[t]!=cab && cab != 0) continue;
if (track[t]->getMode() & TRACK_MODE_DC)
track[t]->setDCSignal(speedbyte);
track[t]->setDCSignal(speedbyte, DCC::getThrottleFrequency(trackDCAddr[t]));
}
}
@ -348,11 +348,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
}
void TrackManager::applyDCSpeed(byte t) {
int8_t frequency = DCC::getThrottleFrequency(trackDCAddr[t]);
if (frequency <0) // loco was not found
frequency = 0; // default
uint8_t speedByte = DCC::getThrottleSpeedByte(trackDCAddr[t]);
track[t]->setDCSignal(speedByte, (uint8_t)frequency);
track[t]->setDCSignal(DCC::getThrottleSpeedByte(trackDCAddr[t]),
DCC::getThrottleFrequency(trackDCAddr[t]));
}
bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])