Skip to content

Commit 191ea69

Browse files
GMagicianthinkyhead
authored andcommitted
🐛 Fix AD4985 with 5V input, add AD595 3.3V warning (MarlinFirmware#26021)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent 4416c82 commit 191ea69

File tree

21 files changed

+47
-28
lines changed

21 files changed

+47
-28
lines changed

Marlin/src/HAL/AVR/HAL.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ typedef Servo hal_servo_t;
147147
//
148148
// ADC
149149
//
150-
#define HAL_ADC_VREF 5.0
151-
#define HAL_ADC_RESOLUTION 10
150+
#define HAL_ADC_VREF_MV 5000
151+
#define HAL_ADC_RESOLUTION 10
152152

153153
//
154154
// Pin Mapping for M42, M43, M226

Marlin/src/HAL/DUE/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ typedef Servo hal_servo_t;
123123
//
124124
// ADC
125125
//
126-
#define HAL_ADC_VREF 3.3
126+
#define HAL_ADC_VREF_MV 3300
127127
#define HAL_ADC_RESOLUTION 10
128128

129129
#ifndef analogInputToDigitalPin

Marlin/src/HAL/ESP32/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void _delay_ms(const int ms);
169169
// MarlinHAL Class
170170
// ------------------------
171171

172-
#define HAL_ADC_VREF 3.3
172+
#define HAL_ADC_VREF_MV 3300
173173
#define HAL_ADC_RESOLUTION 10
174174

175175
class MarlinHAL {

Marlin/src/HAL/LINUX/HAL.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ extern MSerialT usb_serial;
8080
#define CRITICAL_SECTION_END()
8181

8282
// ADC
83-
#define HAL_ADC_VREF 5.0
84-
#define HAL_ADC_RESOLUTION 10
83+
#define HAL_ADC_VREF_MV 5000
84+
#define HAL_ADC_RESOLUTION 10
8585

8686
// ------------------------
8787
// Class Utilities

Marlin/src/HAL/LPC1768/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ extern DefaultSerial1 USBSerial;
127127
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
128128
// Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
129129

130-
#define HAL_ADC_VREF 3.3 // ADC voltage reference
130+
#define HAL_ADC_VREF_MV 3300 // ADC voltage reference
131131

132132
#define HAL_ADC_RESOLUTION 12 // 15 bit maximum, raw temperature is stored as int16_t
133133
#define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL

Marlin/src/HAL/NATIVE_SIM/HAL.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ extern MSerialT serial_stream_3;
114114
// ADC
115115
// ------------------------
116116

117-
#define HAL_ADC_VREF 5.0
118-
#define HAL_ADC_RESOLUTION 10
117+
#define HAL_ADC_VREF_MV 5000
118+
#define HAL_ADC_RESOLUTION 10
119119

120120
/* ---------------- Delay in cycles */
121121

Marlin/src/HAL/SAMD21/HAL.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ typedef Servo hal_servo_t;
111111
//
112112

113113
#define HAL_ADC_FILTERED 1 // Disable Marlin's oversampling. The HAL filters ADC values.
114-
#define HAL_ADC_VREF 3.3
115-
#define HAL_ADC_RESOLUTION 12
114+
#define HAL_ADC_VREF_MV 3300
115+
#define HAL_ADC_RESOLUTION 12
116116
#define HAL_ADC_AIN_START ADC_INPUTCTRL_MUXPOS_PIN3
117117
#define HAL_ADC_AIN_NUM_SENSORS 3
118118
#define HAL_ADC_AIN_LEN HAL_ADC_AIN_NUM_SENSORS-1

Marlin/src/HAL/SAMD51/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef Servo hal_servo_t;
112112
//
113113

114114
//#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
115-
#define HAL_ADC_VREF 3.3
115+
#define HAL_ADC_VREF_MV 3300
116116
#define HAL_ADC_RESOLUTION 10 // ... 12
117117

118118
//

Marlin/src/HAL/STM32/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ typedef libServo hal_servo_t;
160160
#define HAL_ADC_RESOLUTION 12
161161
#endif
162162

163-
#define HAL_ADC_VREF 3.3
163+
#define HAL_ADC_VREF_MV 3300
164164

165165
//
166166
// Pin Mapping for M42, M43, M226

Marlin/src/HAL/STM32/temp_soc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,6 @@
341341

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

344-
#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)
344+
#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)
345345

346346
#endif

Marlin/src/HAL/STM32F1/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ typedef int8_t pin_t;
190190
#define HAL_ADC_RESOLUTION 12
191191
#endif
192192

193-
#define HAL_ADC_VREF 3.3
193+
#define HAL_ADC_VREF_MV 3300
194194

195195
uint16_t analogRead(const pin_t pin); // need hal.adc_enable() first
196196
void analogWrite(const pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?

Marlin/src/HAL/TEENSY31_32/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ uint32_t __get_PRIMASK(void); // CMSIS
101101
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
102102
#endif
103103

104-
#define HAL_ADC_VREF 3.3
104+
#define HAL_ADC_VREF_MV 3300
105105
#define HAL_ADC_RESOLUTION 10
106106

107107
//

Marlin/src/HAL/TEENSY35_36/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef int8_t pin_t;
106106
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
107107
#endif
108108

109-
#define HAL_ADC_VREF 3.3
109+
#define HAL_ADC_VREF_MV 3300
110110
#define HAL_ADC_RESOLUTION 10
111111

112112
//

Marlin/src/HAL/TEENSY40_41/HAL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef int8_t pin_t;
124124
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
125125
#endif
126126

127-
#define HAL_ADC_VREF 3.3
127+
#define HAL_ADC_VREF_MV 3300
128128
#define HAL_ADC_RESOLUTION 10
129129
#define HAL_ADC_FILTERED // turn off ADC oversampling
130130

Marlin/src/feature/filwidth.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class FilamentWidthSensor {
6767
}
6868

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

7373
// A scaled reading is ready

Marlin/src/feature/power_monitor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ struct pm_lpf_t {
4646
class PowerMonitor {
4747
private:
4848
#if ENABLED(POWER_MONITOR_CURRENT)
49-
static constexpr float amps_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_AMP * PM_SAMPLE_RANGE);
49+
static constexpr float amps_adc_scale = (float(ADC_VREF_MV) / 1000.0f) / (POWER_MONITOR_VOLTS_PER_AMP * PM_SAMPLE_RANGE);
5050
static pm_lpf_t<amps_adc_scale, PM_K_VALUE, PM_K_SCALE> amps;
5151
#endif
5252
#if ENABLED(POWER_MONITOR_VOLTAGE)
53-
static constexpr float volts_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_VOLT * PM_SAMPLE_RANGE);
53+
static constexpr float volts_adc_scale = (float(ADC_VREF_MV) / 1000.0f) / (POWER_MONITOR_VOLTS_PER_VOLT * PM_SAMPLE_RANGE);
5454
static pm_lpf_t<volts_adc_scale, PM_K_VALUE, PM_K_SCALE> volts;
5555
#endif
5656

Marlin/src/inc/Conditionals_post.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#endif
3232

3333
// ADC
34-
#ifdef BOARD_ADC_VREF
35-
#define ADC_VREF BOARD_ADC_VREF
34+
#ifdef BOARD_ADC_VREF_MV
35+
#define ADC_VREF_MV BOARD_ADC_VREF_MV
3636
#else
37-
#define ADC_VREF HAL_ADC_VREF
37+
#define ADC_VREF_MV HAL_ADC_VREF_MV
3838
#endif
3939

4040
// Linear advance uses Jerk since E is an isolated axis

Marlin/src/inc/Warnings.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,16 @@
750750
#warning "Input Shaping for CORE / MARKFORGED kinematic axes is still experimental."
751751
#endif
752752

753+
/**
754+
* Automatic Multistepping Limit
755+
*/
753756
#if MULTISTEPPING_LIMIT_WARNING
754757
#warning "MULTISTEPPING_LIMIT has been automatically set to 128. Use a lower value if the machine is slow to respond."
755758
#endif
756759

760+
/**
761+
* SD Card extras
762+
*/
757763
#if SDSORT_CACHE_VFATS_WARNING
758764
#warning "SDSORT_CACHE_VFATS has been reduced to VFAT_ENTRIES_LIMIT."
759765
#endif
@@ -768,6 +774,16 @@
768774
#warning "Place the firmware bin file in a folder named 'STM32F4_UPDATE' on the SD card. Install with 'M936 V2'."
769775
#endif
770776

777+
/**
778+
* ProUI Boot Screen Duration
779+
*/
771780
#if ENABLED(DWIN_LCD_PROUI) && BOOTSCREEN_TIMEOUT > 2000
772781
#warning "For ProUI the original BOOTSCREEN_TIMEOUT of 1100 is recommended."
773782
#endif
783+
784+
/**
785+
* AD595 Minimum Voltage
786+
*/
787+
#if HAL_ADC_VREF_MV < 5000 && ANY_THERMISTOR_IS(-1) && DISABLED(ALLOW_AD595_3V3_VREF)
788+
#warning "The (-1) AD595 Thermocouple Amplifier requires 5V input supply! Use AD8495 for 3.3V ADC."
789+
#endif

Marlin/src/module/temperature.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2142,8 +2142,10 @@ void Temperature::task() {
21422142
UNUSED(ms);
21432143
}
21442144

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

21482150
/**
21492151
* Bisect search for the range of the 'raw' value, then interpolate

buildroot/tests/LPC1768

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exec_test $1 $2 "MKS SBASE with SWITCHING_NOZZLE, Grbl Realtime Report" "$3"
3434

3535
restore_configs
3636
opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EEB \
37-
EXTRUDERS 2 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 \
37+
EXTRUDERS 2 TEMP_SENSOR_1 -4 TEMP_SENSOR_BED 5 \
3838
GRID_MAX_POINTS_X 16 \
3939
NOZZLE_TO_PROBE_OFFSET '{ 0, 0, 0 }' \
4040
NOZZLE_CLEAN_MIN_TEMP 170 \

buildroot/tests/LPC1769

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exec_test $1 $2 "Azteeg X5GT Example Configuration" "$3"
1414

1515
restore_configs
1616
opt_set MOTHERBOARD BOARD_SMOOTHIEBOARD \
17-
EXTRUDERS 2 TEMP_SENSOR_0 -5 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 TEMP_0_CS_PIN P1_29 \
17+
EXTRUDERS 2 TEMP_SENSOR_0 -5 TEMP_SENSOR_1 -4 TEMP_SENSOR_BED 5 TEMP_0_CS_PIN P1_29 \
1818
GRID_MAX_POINTS_X 16 \
1919
NOZZLE_CLEAN_START_POINT "{ { 10, 10, 3 }, { 10, 10, 3 } }" \
2020
NOZZLE_CLEAN_END_POINT "{ { 10, 20, 3 }, { 10, 20, 3 } }"
@@ -43,6 +43,7 @@ exec_test $1 $2 "Smoothieboard with TFTGLCD_PANEL_SPI and many features" "$3"
4343
restore_configs
4444
use_example_configs delta/generic
4545
opt_set MOTHERBOARD BOARD_COHESION3D_REMIX \
46+
TEMP_SENSOR_0 1 \
4647
X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2130 Z_DRIVER_TYPE TMC2130 I_DRIVER_TYPE TB6560 \
4748
DEFAULT_AXIS_STEPS_PER_UNIT '{ 80, 80, 400, 500, 80 }' \
4849
DEFAULT_MAX_FEEDRATE '{ 300, 300, 5, 25, 300 }' \

0 commit comments

Comments
 (0)