mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-27 14:21:25 +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;
|
||||
}
|
||||
|
||||
int current=progDriver->getCurrentRaw();
|
||||
int current=progDriver->getCurrentRawInInterrupt();
|
||||
numAckSamples++;
|
||||
if (current > ackMaxCurrent) ackMaxCurrent=current;
|
||||
// An ACK is a pulse lasting between minAckPulseDuration and maxAckPulseDuration uSecs (refer @haba)
|
||||
|
@ -156,28 +156,28 @@ bool MotorDriver::canMeasureCurrent() {
|
||||
int MotorDriver::getCurrentRaw() {
|
||||
if (currentPin==UNUSED_PIN) return 0;
|
||||
int current;
|
||||
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
|
||||
bool irq = disableInterrupts();
|
||||
// This function should NOT be called in an interruot so we
|
||||
// dont need to fart about saving and restoring CPU specific
|
||||
// interrupt registers.
|
||||
noInterrupts();
|
||||
current = analogRead(currentPin)-senseOffset;
|
||||
enableInterrupts(irq);
|
||||
#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 #
|
||||
interrupts();
|
||||
if (current<0) current=0-current;
|
||||
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && isHIGH(fastPowerPin))
|
||||
return (current == 0 ? -1 : -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
|
||||
// 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) {
|
||||
return (unsigned int)(raw * senseFactor);
|
||||
|
@ -55,6 +55,7 @@ class MotorDriver {
|
||||
virtual void setSignal( bool high);
|
||||
virtual void setBrake( bool on);
|
||||
virtual int getCurrentRaw();
|
||||
virtual int getCurrentRawInInterrupt();
|
||||
virtual unsigned int raw2mA( int raw);
|
||||
virtual int mA2raw( unsigned int mA);
|
||||
inline int getRawCurrentTripValue() {
|
||||
|
Loading…
Reference in New Issue
Block a user