mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 12:51:24 +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
|
||||
// makes a difference.
|
||||
static int read(uint8_t pin, bool fromISR=false);
|
||||
// returns possible max value that the ADC can return
|
||||
static int16_t ADCmax();
|
||||
private:
|
||||
// On platforms that scan, it is called from waveform ISR
|
||||
// only on a regular basis.
|
||||
|
@ -144,6 +144,9 @@ int ADCee::init(uint8_t pin) {
|
||||
usedpins |= (1<<id);
|
||||
return value;
|
||||
}
|
||||
inline int16_t ADCee::ADCmax() {
|
||||
return 1023;
|
||||
}
|
||||
/*
|
||||
* 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);
|
||||
return adc1_get_raw(pinToADC1Channel(pin));
|
||||
}
|
||||
int16_t ADCee::ADCmax() {
|
||||
return 4095;
|
||||
}
|
||||
/*
|
||||
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
||||
*/
|
||||
|
@ -177,6 +177,9 @@ int ADCee::init(uint8_t pin) {
|
||||
|
||||
return value;
|
||||
}
|
||||
int16_t ADCee::ADCmax() {
|
||||
return 4095;
|
||||
}
|
||||
/*
|
||||
* Read function ADCee::read(pin) to get value instead of analogRead(pin)
|
||||
*/
|
||||
|
@ -29,9 +29,6 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#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
|
||||
|
||||
bool MotorDriver::commonFaultPin=false;
|
||||
@ -109,7 +106,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
||||
tripMilliamps=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
|
||||
// can reach the trip value. So independent of the current, 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.
|
||||
|
||||
// DIAG(F("Changing short detection value from %d to %d mA"),
|
||||
// raw2mA(rawCurrentTripValue), raw2mA(ADC_INPUT_MAX_VALUE-senseOffset));
|
||||
rawCurrentTripValue=ADC_INPUT_MAX_VALUE-senseOffset;
|
||||
// raw2mA(rawCurrentTripValue), raw2mA(ADCee::ADCmax()-senseOffset));
|
||||
rawCurrentTripValue=ADCee::ADCmax()-senseOffset;
|
||||
}
|
||||
|
||||
if (currentPin==UNUSED_PIN)
|
||||
|
Loading…
Reference in New Issue
Block a user