Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'adv vref' from HAL instead of constant voltage #26021

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ typedef Servo hal_servo_t;
//
// ADC
//
#define HAL_ADC_VREF 5.0
#define HAL_ADC_RESOLUTION 10
#define HAL_ADC_VREF_MV 5000
#define HAL_ADC_RESOLUTION 10

//
// Pin Mapping for M42, M43, M226
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/DUE/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ typedef Servo hal_servo_t;
//
// ADC
//
#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10

#ifndef analogInputToDigitalPin
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/ESP32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void _delay_ms(const int ms);
// MarlinHAL Class
// ------------------------

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10

class MarlinHAL {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/LINUX/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ extern MSerialT usb_serial;
#define CRITICAL_SECTION_END()

// ADC
#define HAL_ADC_VREF 5.0
#define HAL_ADC_RESOLUTION 10
#define HAL_ADC_VREF_MV 5000
#define HAL_ADC_RESOLUTION 10

// ------------------------
// Class Utilities
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/LPC1768/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extern DefaultSerial1 USBSerial;
// 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)

#define HAL_ADC_VREF 3.3 // ADC voltage reference
#define HAL_ADC_VREF_MV 3300 // ADC voltage reference

#define HAL_ADC_RESOLUTION 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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/NATIVE_SIM/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ extern MSerialT serial_stream_3;
// ADC
// ------------------------

#define HAL_ADC_VREF 5.0
#define HAL_ADC_RESOLUTION 10
#define HAL_ADC_VREF_MV 5000
#define HAL_ADC_RESOLUTION 10

/* ---------------- Delay in cycles */

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/SAMD21/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ typedef Servo hal_servo_t;
//

#define HAL_ADC_FILTERED 1 // Disable Marlin's oversampling. The HAL filters ADC values.
#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 12
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 12
#define HAL_ADC_AIN_START ADC_INPUTCTRL_MUXPOS_PIN3
#define HAL_ADC_AIN_NUM_SENSORS 3
#define HAL_ADC_AIN_LEN HAL_ADC_AIN_NUM_SENSORS-1
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/SAMD51/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typedef Servo hal_servo_t;
//

//#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10 // ... 12

//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ typedef libServo hal_servo_t;
#define HAL_ADC_RESOLUTION 12
#endif

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300

//
// Pin Mapping for M42, M43, M226
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/temp_soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,6 @@

#elif defined(TS_TYPICAL_V) && defined(TS_TYPICAL_SLOPE) && defined(TS_TYPICAL_TEMP)

#define TEMP_SOC_SENSOR(RAW) ((TS_TYPICAL_V - (RAW) / float(OVERSAMPLENR) / float(HAL_ADC_RANGE) * float(ADC_VREF)) / (TS_TYPICAL_SLOPE/1000) + TS_TYPICAL_TEMP)
#define TEMP_SOC_SENSOR(RAW) ((TS_TYPICAL_V - (RAW) / float(OVERSAMPLENR) / float(HAL_ADC_RANGE) * (float(ADC_VREF_MV) / 1000.0f)) / ((TS_TYPICAL_SLOPE) / 1000) + TS_TYPICAL_TEMP)

#endif
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ typedef int8_t pin_t;
#define HAL_ADC_RESOLUTION 12
#endif

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300

uint16_t analogRead(const pin_t pin); // need hal.adc_enable() first
void analogWrite(const pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY31_32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ uint32_t __get_PRIMASK(void); // CMSIS
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
#endif

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10

//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY35_36/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef int8_t pin_t;
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
#endif

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10

//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY40_41/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ typedef int8_t pin_t;
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
#endif

#define HAL_ADC_VREF 3.3
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10
#define HAL_ADC_FILTERED // turn off ADC oversampling

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/filwidth.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FilamentWidthSensor {
}

// Convert raw measurement to mm
static float raw_to_mm(const uint16_t v) { return v * float(ADC_VREF) * RECIPROCAL(float(MAX_RAW_THERMISTOR_VALUE)); }
static float raw_to_mm(const uint16_t v) { return v * (float(ADC_VREF_MV) / 1000.0f) * RECIPROCAL(float(MAX_RAW_THERMISTOR_VALUE)); }
static float raw_to_mm() { return raw_to_mm(raw); }

// A scaled reading is ready
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/power_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ struct pm_lpf_t {
class PowerMonitor {
private:
#if ENABLED(POWER_MONITOR_CURRENT)
static constexpr float amps_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_AMP * PM_SAMPLE_RANGE);
static constexpr float amps_adc_scale = (float(ADC_VREF_MV) / 1000.0f) / (POWER_MONITOR_VOLTS_PER_AMP * PM_SAMPLE_RANGE);
static pm_lpf_t<amps_adc_scale, PM_K_VALUE, PM_K_SCALE> amps;
#endif
#if ENABLED(POWER_MONITOR_VOLTAGE)
static constexpr float volts_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_VOLT * PM_SAMPLE_RANGE);
static constexpr float volts_adc_scale = (float(ADC_VREF_MV) / 1000.0f) / (POWER_MONITOR_VOLTS_PER_VOLT * PM_SAMPLE_RANGE);
static pm_lpf_t<volts_adc_scale, PM_K_VALUE, PM_K_SCALE> volts;
#endif

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#endif

// ADC
#ifdef BOARD_ADC_VREF
#define ADC_VREF BOARD_ADC_VREF
#ifdef BOARD_ADC_VREF_MV
#define ADC_VREF_MV BOARD_ADC_VREF_MV
#else
#define ADC_VREF HAL_ADC_VREF
#define ADC_VREF_MV HAL_ADC_VREF_MV
#endif

// Linear advance uses Jerk since E is an isolated axis
Expand Down
16 changes: 16 additions & 0 deletions Marlin/src/inc/Warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,16 @@
#warning "Input Shaping for CORE / MARKFORGED kinematic axes is still experimental."
#endif

/**
* Automatic Multistepping Limit
*/
#if MULTISTEPPING_LIMIT_WARNING
#warning "MULTISTEPPING_LIMIT has been automatically set to 128. Use a lower value if the machine is slow to respond."
#endif

/**
* SD Card extras
*/
#if SDSORT_CACHE_VFATS_WARNING
#warning "SDSORT_CACHE_VFATS has been reduced to VFAT_ENTRIES_LIMIT."
#endif
Expand All @@ -768,6 +774,16 @@
#warning "Place the firmware bin file in a folder named 'STM32F4_UPDATE' on the SD card. Install with 'M936 V2'."
#endif

/**
* ProUI Boot Screen Duration
*/
#if ENABLED(DWIN_LCD_PROUI) && BOOTSCREEN_TIMEOUT > 2000
#warning "For ProUI the original BOOTSCREEN_TIMEOUT of 1100 is recommended."
#endif

/**
* AD595 Minimum Voltage
*/
#if HAL_ADC_VREF_MV < 5000 && ANY_THERMISTOR_IS(-1) && DISABLED(ALLOW_AD595_3V3_VREF)
#warning "The (-1) AD595 Thermocouple Amplifier requires 5V input supply! Use AD8495 for 3.3V ADC."
#endif
6 changes: 4 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,8 +2142,10 @@ void Temperature::task() {
UNUSED(ms);
}

#define TEMP_AD595(RAW) ((RAW) * 5.0 * 100.0 / float(HAL_ADC_RANGE) / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)
#define TEMP_AD8495(RAW) ((RAW) * 6.6 * 100.0 / float(HAL_ADC_RANGE) / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET)
// For a 5V input the AD595 returns a value scaled with 10mV per °C. (Minimum input voltage is 5V.)
#define TEMP_AD595(RAW) ((RAW) * (ADC_VREF_MV / 10) / float(HAL_ADC_RANGE) / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)
// For a 5V input the AD8495 returns a value scaled with 5mV per °C. (Minimum input voltage is 2.7V.)
#define TEMP_AD8495(RAW) ((RAW) * (ADC_VREF_MV / 5) / float(HAL_ADC_RANGE) / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET)

/**
* Bisect search for the range of the 'raw' value, then interpolate
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/LPC1768
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exec_test $1 $2 "MKS SBASE with SWITCHING_NOZZLE, Grbl Realtime Report" "$3"

restore_configs
opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EEB \
EXTRUDERS 2 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 \
EXTRUDERS 2 TEMP_SENSOR_1 -4 TEMP_SENSOR_BED 5 \
GRID_MAX_POINTS_X 16 \
NOZZLE_TO_PROBE_OFFSET '{ 0, 0, 0 }' \
NOZZLE_CLEAN_MIN_TEMP 170 \
Expand Down
3 changes: 2 additions & 1 deletion buildroot/tests/LPC1769
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exec_test $1 $2 "Azteeg X5GT Example Configuration" "$3"

restore_configs
opt_set MOTHERBOARD BOARD_SMOOTHIEBOARD \
EXTRUDERS 2 TEMP_SENSOR_0 -5 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 TEMP_0_CS_PIN P1_29 \
EXTRUDERS 2 TEMP_SENSOR_0 -5 TEMP_SENSOR_1 -4 TEMP_SENSOR_BED 5 TEMP_0_CS_PIN P1_29 \
GRID_MAX_POINTS_X 16 \
NOZZLE_CLEAN_START_POINT "{ { 10, 10, 3 }, { 10, 10, 3 } }" \
NOZZLE_CLEAN_END_POINT "{ { 10, 20, 3 }, { 10, 20, 3 } }"
Expand Down Expand Up @@ -43,6 +43,7 @@ exec_test $1 $2 "Smoothieboard with TFTGLCD_PANEL_SPI and many features" "$3"
restore_configs
use_example_configs delta/generic
opt_set MOTHERBOARD BOARD_COHESION3D_REMIX \
TEMP_SENSOR_0 1 \
X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2130 Z_DRIVER_TYPE TMC2130 I_DRIVER_TYPE TB6560 \
DEFAULT_AXIS_STEPS_PER_UNIT '{ 80, 80, 400, 500, 80 }' \
DEFAULT_MAX_FEEDRATE '{ 300, 300, 5, 25, 300 }' \
Expand Down