Skip to content

Commit 684cafc

Browse files
authored
Merge pull request #190 from facchinm/aref_internal_fix_getter
analogReference: add getter for AR_INTERNAL if defined at variant level
2 parents d0354d4 + 0ce10bf commit 684cafc

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

Diff for: cores/arduino/analog.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,17 @@ float analogReference() {
570570
case ADC_VREF_CONTROL_VREFH0_AVSS0:
571571
// the user must know the voltage he applies from outside
572572
return NAN;
573+
#ifdef AR_INTERNAL_VOLTAGE
574+
case ADC_VREF_CONTROL_IVREF_AVSS0:
575+
return AR_INTERNAL_VOLTAGE;
576+
#endif
573577
default:
574578
#if defined(AVCC_MEASURE_PIN)
575579
if (aref == 0) {
576580
analogReference(AR_INTERNAL);
577581
delayMicroseconds(5);
578582
for (int i = 0; i < 10; i++) {
579-
aref += analogRead(AVCC_MEASURE_PIN) * 1.43f * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution);
583+
aref += analogRead(AVCC_MEASURE_PIN) * AR_INTERNAL_VOLTAGE * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution);
580584
}
581585
aref = aref / 10;
582586
analogReference(AR_DEFAULT);

Diff for: variants/MINIMA/pins_arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ static const uint8_t SS = PIN_SPI_CS;
156156
#define AVCC_MEASURE_PIN 20
157157
#define AVCC_MULTIPLY_FACTOR 8.33
158158

159+
#define AR_INTERNAL_VOLTAGE 1.43f
160+
159161
#define USB_VID (0x2341)
160162
#define USB_PID (0x0069)
161163
#define USB_NAME "UNO R4 Minima"

Diff for: variants/PORTENTA_C33/pins_arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,5 @@ static const uint8_t SS = PIN_SPI_CS;
207207
#define SerialLoRa Serial3
208208

209209
#define RTC_CLOCK_SOURCE RTC_CLOCK_SOURCE_SUBCLK
210+
211+
#define AR_INTERNAL_VOLTAGE 1.18f

Diff for: variants/UNOWIFIR4/pins_arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ static const uint8_t SS = PIN_SPI_CS;
158158
#define AVCC_MEASURE_PIN 20
159159
#define AVCC_MULTIPLY_FACTOR 8.33
160160

161+
#define AR_INTERNAL_VOLTAGE 1.43f
162+
161163
#define USB_VID (0x2341)
162164
#define USB_PID (0x006D)
163165
#define USB_NAME "UNO R4 WiFi"

0 commit comments

Comments
 (0)