mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-25 05:31:24 +01:00
Update for T3.x to use SREG analogReads.
Still a bunch of commented out code but its a start.
This commit is contained in:
parent
136e993418
commit
8839eb293c
@ -20,13 +20,14 @@
|
|||||||
#include "MotorDriver.h"
|
#include "MotorDriver.h"
|
||||||
#include "DCCTimer.h"
|
#include "DCCTimer.h"
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#if defined(TEENSYDUINO)
|
//#if defined(TEENSYDUINO)
|
||||||
|
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
|
||||||
#include <ADC.h>
|
#include <ADC.h>
|
||||||
#include <ADC_util.h>
|
#include <ADC_util.h>
|
||||||
ADC *adc = new ADC(); // adc object
|
ADC *adc = new ADC(); // adc object
|
||||||
#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
//#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
||||||
ADC *adc1 = new ADC(); // adc object
|
//ADC *adc1 = new ADC(); // adc object
|
||||||
#endif
|
//#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
|
#define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
|
||||||
@ -71,18 +72,19 @@ MotorDriver::MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8
|
|||||||
senseOffset=analogRead(currentPin); // value of sensor at zero current
|
senseOffset=analogRead(currentPin); // value of sensor at zero current
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TEENSYDUINO)
|
//#if defined(TEENSYDUINO)
|
||||||
|
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
|
||||||
if(currentPin != current_pin && currentPin!=UNUSED_PIN){
|
if(currentPin != current_pin && currentPin!=UNUSED_PIN){
|
||||||
adc->adc0->setReference(ADC_REFERENCE::REF_3V3);
|
//adc->adc0->setReference(ADC_REFERENCE::REF_3V3);
|
||||||
adc->adc0->startContinuous(currentPin);
|
adc->adc0->startContinuous(currentPin);
|
||||||
} else if(currentPin!=UNUSED_PIN){
|
} else if(currentPin!=UNUSED_PIN){
|
||||||
#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
//#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
||||||
adc1->adc0->setReference(ADC_REFERENCE::REF_3V3);
|
// adc1->adc0->setReference(ADC_REFERENCE::REF_3V3);
|
||||||
adc1->adc0->startContinuous(currentPin);
|
// adc1->adc0->startContinuous(currentPin);
|
||||||
#else
|
//#else
|
||||||
adc->adc1->setReference(ADC_REFERENCE::REF_3V3);
|
//adc->adc1->setReference(ADC_REFERENCE::REF_3V3);
|
||||||
adc->adc1->startContinuous(currentPin);
|
adc->adc1->startContinuous(currentPin);
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
faultPin=fault_pin;
|
faultPin=fault_pin;
|
||||||
@ -148,6 +150,8 @@ void MotorDriver::setSignal( bool high) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile unsigned int overflow_count=0;
|
||||||
|
|
||||||
bool MotorDriver::canMeasureCurrent() {
|
bool MotorDriver::canMeasureCurrent() {
|
||||||
return currentPin!=UNUSED_PIN;
|
return currentPin!=UNUSED_PIN;
|
||||||
}
|
}
|
||||||
@ -163,16 +167,24 @@ int MotorDriver::getCurrentRaw(bool isMain) {
|
|||||||
if (currentPin==UNUSED_PIN) return 0;
|
if (currentPin==UNUSED_PIN) return 0;
|
||||||
|
|
||||||
int current;
|
int current;
|
||||||
#if defined(TEENSYDUINO)
|
//#if defined(TEENSYDUINO)
|
||||||
|
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
|
||||||
if(isMain) {
|
if(isMain) {
|
||||||
current = (uint16_t)adc->adc0->analogReadContinuous();
|
current = (uint16_t)adc->adc0->analogReadContinuous();
|
||||||
} else {
|
} else {
|
||||||
#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
//#if defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY32)
|
||||||
current = (uint16_t)adc1->adc0->analogReadContinuous();
|
//current = (uint16_t)adc1->adc0->analogReadContinuous();
|
||||||
#else
|
//#else
|
||||||
current = (uint16_t)adc->adc1->analogReadContinuous();
|
current = (uint16_t)adc->adc1->analogReadContinuous();
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
#elif defined(ARDUINO_TEENSY32) || defined(ARDUINO_TEENSY35)|| defined(ARDUINO_TEENSY36)
|
||||||
|
unsigned char sreg_backup;
|
||||||
|
sreg_backup = SREG; /* save interrupt enable/disable state */
|
||||||
|
cli();
|
||||||
|
current = analogRead(currentPin)-senseOffset;
|
||||||
|
overflow_count = 0;
|
||||||
|
SREG = sreg_backup; /* restore interrupt state */
|
||||||
#else
|
#else
|
||||||
current = analogRead(currentPin)-senseOffset;
|
current = analogRead(currentPin)-senseOffset;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user