mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-17 06:29:15 +01:00
make max ADC value a per platform ADC function
This commit is contained in:
parent
65364212ca
commit
cf89fe2a72
@ -111,6 +111,8 @@ public:
|
|||||||
// it was called from ISR because for some implementations that
|
// it was called from ISR because for some implementations that
|
||||||
// makes a difference.
|
// makes a difference.
|
||||||
static int read(uint8_t pin, bool fromISR=false);
|
static int read(uint8_t pin, bool fromISR=false);
|
||||||
|
// returns possible max value that the ADC can return
|
||||||
|
static int16_t ADCmax();
|
||||||
private:
|
private:
|
||||||
// On platforms that scan, it is called from waveform ISR
|
// On platforms that scan, it is called from waveform ISR
|
||||||
// only on a regular basis.
|
// only on a regular basis.
|
||||||
|
@ -144,6 +144,9 @@ int ADCee::init(uint8_t pin) {
|
|||||||
usedpins |= (1<<id);
|
usedpins |= (1<<id);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
inline int16_t ADCee::ADCmax() {
|
||||||
|
return 1023;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
||||||
*/
|
*/
|
||||||
|
@ -156,6 +156,9 @@ int ADCee::init(uint8_t pin) {
|
|||||||
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
|
||||||
return adc1_get_raw(pinToADC1Channel(pin));
|
return adc1_get_raw(pinToADC1Channel(pin));
|
||||||
}
|
}
|
||||||
|
int16_t ADCee::ADCmax() {
|
||||||
|
return 4095;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
||||||
*/
|
*/
|
||||||
|
@ -177,6 +177,9 @@ int ADCee::init(uint8_t pin) {
|
|||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
int16_t ADCee::ADCmax() {
|
||||||
|
return 4095;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
||||||
*/
|
*/
|
||||||
|
@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include "ESP32-fixes.h"
|
#include "ESP32-fixes.h"
|
||||||
#define ADC_INPUT_MAX_VALUE 4095 // 12 bit ADC (should be moved to ADCee as well)
|
|
||||||
#else
|
|
||||||
#define ADC_INPUT_MAX_VALUE 1023 // 10 bit ADC
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool MotorDriver::commonFaultPin=false;
|
bool MotorDriver::commonFaultPin=false;
|
||||||
@ -109,7 +106,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||||||
tripMilliamps=trip_milliamps;
|
tripMilliamps=trip_milliamps;
|
||||||
rawCurrentTripValue=mA2raw(trip_milliamps);
|
rawCurrentTripValue=mA2raw(trip_milliamps);
|
||||||
|
|
||||||
if (rawCurrentTripValue + senseOffset > ADC_INPUT_MAX_VALUE) {
|
if (rawCurrentTripValue + senseOffset > ADCee::ADCmax()) {
|
||||||
// This would mean that the values obtained from the ADC never
|
// This would mean that the values obtained from the ADC never
|
||||||
// can reach the trip value. So independent of the current, the
|
// can reach the trip value. So independent of the current, the
|
||||||
// short circuit protection would never trip. So we adjust the
|
// short circuit protection would never trip. So we adjust the
|
||||||
@ -117,8 +114,8 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||||||
// maximum value instead.
|
// maximum value instead.
|
||||||
|
|
||||||
// DIAG(F("Changing short detection value from %d to %d mA"),
|
// DIAG(F("Changing short detection value from %d to %d mA"),
|
||||||
// raw2mA(rawCurrentTripValue), raw2mA(ADC_INPUT_MAX_VALUE-senseOffset));
|
// raw2mA(rawCurrentTripValue), raw2mA(ADCee::ADCmax()-senseOffset));
|
||||||
rawCurrentTripValue=ADC_INPUT_MAX_VALUE-senseOffset;
|
rawCurrentTripValue=ADCee::ADCmax()-senseOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentPin==UNUSED_PIN)
|
if (currentPin==UNUSED_PIN)
|
||||||
|
Loading…
Reference in New Issue
Block a user