Use native ADC resolution where possible (#15719)
This commit is contained in:
@ -25,6 +25,8 @@
|
||||
|
||||
#include HAL_PATH(.,HAL.h)
|
||||
|
||||
#define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
|
||||
|
||||
inline void watchdog_refresh() {
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
HAL_watchdog_refresh();
|
||||
|
@ -365,6 +365,7 @@ inline void HAL_adc_init() {
|
||||
#define HAL_START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
|
||||
#endif
|
||||
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() ADC
|
||||
#define HAL_ADC_READY() !TEST(ADCSRA, ADSC)
|
||||
|
||||
|
@ -133,6 +133,7 @@ extern uint16_t HAL_adc_result; // result of last ADC conversion
|
||||
inline void HAL_adc_init() {}//todo
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -111,6 +111,7 @@ void eeprom_update_block (const void *__src, void *__dst, size_t __n);
|
||||
void HAL_adc_init();
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -89,6 +89,7 @@ int freeMemory();
|
||||
// ADC
|
||||
#define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_get_result()
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -131,11 +131,14 @@ int freeMemory();
|
||||
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
|
||||
// Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
|
||||
|
||||
using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
|
||||
#define HAL_ADC_RESULT_BITS 12 // 15 bit maximum, raw temperature is stored as int16_t
|
||||
#define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL
|
||||
#define HAL_ADC_RESOLUTION HAL_ADC_RESULT_BITS
|
||||
|
||||
using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
|
||||
extern uint32_t HAL_adc_reading;
|
||||
[[gnu::always_inline]] inline void HAL_start_adc(const pin_t pin) {
|
||||
HAL_adc_reading = FilteredADC::read(pin) >> 6; // returns 16bit value, reduce to 10bit
|
||||
HAL_adc_reading = FilteredADC::read(pin) >> (16 - HAL_ADC_RESULT_BITS); // returns 16bit value, reduce to required bits
|
||||
}
|
||||
[[gnu::always_inline]] inline uint16_t HAL_read_adc() {
|
||||
return HAL_adc_reading;
|
||||
|
@ -110,6 +110,7 @@ extern uint16_t HAL_adc_result; // result of last ADC conversion
|
||||
void HAL_adc_init();
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -188,6 +188,7 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
|
||||
inline void HAL_adc_init() {}
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -238,6 +238,7 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
|
||||
void HAL_adc_init();
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -208,6 +208,7 @@ void eeprom_update_block (const void *__src, void *__dst, size_t __n);
|
||||
inline void HAL_adc_init() {}
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -109,6 +109,7 @@ extern "C" {
|
||||
void HAL_adc_init();
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_get_result()
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
@ -115,6 +115,7 @@ extern "C" {
|
||||
void HAL_adc_init();
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_get_result()
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
|
Reference in New Issue
Block a user