mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
Cleaner ack check
And drop CPU specific stuff no longer needed.
This commit is contained in:
parent
a7740d652d
commit
1afb4753ec
|
@ -423,7 +423,7 @@ void DCCACK::checkAck(byte sentResetsSincePacket) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int current=progDriver->getCurrentRaw();
|
int current=progDriver->getCurrentRawInInterrupt();
|
||||||
numAckSamples++;
|
numAckSamples++;
|
||||||
if (current > ackMaxCurrent) ackMaxCurrent=current;
|
if (current > ackMaxCurrent) ackMaxCurrent=current;
|
||||||
// An ACK is a pulse lasting between minAckPulseDuration and maxAckPulseDuration uSecs (refer @haba)
|
// An ACK is a pulse lasting between minAckPulseDuration and maxAckPulseDuration uSecs (refer @haba)
|
||||||
|
|
|
@ -156,28 +156,28 @@ bool MotorDriver::canMeasureCurrent() {
|
||||||
int MotorDriver::getCurrentRaw() {
|
int MotorDriver::getCurrentRaw() {
|
||||||
if (currentPin==UNUSED_PIN) return 0;
|
if (currentPin==UNUSED_PIN) return 0;
|
||||||
int current;
|
int current;
|
||||||
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
|
// This function should NOT be called in an interruot so we
|
||||||
bool irq = disableInterrupts();
|
// dont need to fart about saving and restoring CPU specific
|
||||||
|
// interrupt registers.
|
||||||
|
noInterrupts();
|
||||||
current = analogRead(currentPin)-senseOffset;
|
current = analogRead(currentPin)-senseOffset;
|
||||||
enableInterrupts(irq);
|
interrupts();
|
||||||
#else // Uno, Mega and all the TEENSY3* but not TEENSY4*
|
|
||||||
unsigned char sreg_backup;
|
|
||||||
sreg_backup = SREG; /* save interrupt enable/disable state */
|
|
||||||
cli();
|
|
||||||
current = analogRead(currentPin)-senseOffset;
|
|
||||||
#if defined(ARDUINO_TEENSY32) || defined(ARDUINO_TEENSY35)|| defined(ARDUINO_TEENSY36)
|
|
||||||
overflow_count = 0;
|
|
||||||
#endif
|
|
||||||
if (sreg_backup & 128) sei(); /* restore interrupt state */
|
|
||||||
#endif // outer #
|
|
||||||
if (current<0) current=0-current;
|
if (current<0) current=0-current;
|
||||||
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
|
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
|
||||||
return (current == 0 ? -1 : -current);
|
return (current == 0 ? -1 : -current);
|
||||||
return current;
|
return current;
|
||||||
// IMPORTANT: This function can be called in Interrupt() time within the 56uS timer
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int MotorDriver::getCurrentRawInInterrupt() {
|
||||||
|
|
||||||
|
// IMPORTANT: This function must be called in Interrupt() time within the 56uS timer
|
||||||
// The default analogRead takes ~100uS which is catastrphic
|
// The default analogRead takes ~100uS which is catastrphic
|
||||||
// so DCCTimer has set the sample time to be much faster.
|
// so DCCTimer has set the sample time to be much faster.
|
||||||
}
|
|
||||||
|
if (currentPin==UNUSED_PIN) return 0;
|
||||||
|
return analogRead(currentPin)-senseOffset;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int MotorDriver::raw2mA( int raw) {
|
unsigned int MotorDriver::raw2mA( int raw) {
|
||||||
return (unsigned int)(raw * senseFactor);
|
return (unsigned int)(raw * senseFactor);
|
||||||
|
|
|
@ -55,6 +55,7 @@ class MotorDriver {
|
||||||
virtual void setSignal( bool high);
|
virtual void setSignal( bool high);
|
||||||
virtual void setBrake( bool on);
|
virtual void setBrake( bool on);
|
||||||
virtual int getCurrentRaw();
|
virtual int getCurrentRaw();
|
||||||
|
virtual int getCurrentRawInInterrupt();
|
||||||
virtual unsigned int raw2mA( int raw);
|
virtual unsigned int raw2mA( int raw);
|
||||||
virtual int mA2raw( unsigned int mA);
|
virtual int mA2raw( unsigned int mA);
|
||||||
inline int getRawCurrentTripValue() {
|
inline int getRawCurrentTripValue() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user