Skip to content

analogReference: add getter for AR_INTERNAL if defined at variant level #190

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

Merged
merged 1 commit into from
Nov 16, 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
6 changes: 5 additions & 1 deletion cores/arduino/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,17 @@ float analogReference() {
case ADC_VREF_CONTROL_VREFH0_AVSS0:
// the user must know the voltage he applies from outside
return NAN;
#ifdef AR_INTERNAL_VOLTAGE
case ADC_VREF_CONTROL_IVREF_AVSS0:
return AR_INTERNAL_VOLTAGE;
#endif
default:
#if defined(AVCC_MEASURE_PIN)
if (aref == 0) {
analogReference(AR_INTERNAL);
delayMicroseconds(5);
for (int i = 0; i < 10; i++) {
aref += analogRead(AVCC_MEASURE_PIN) * 1.43f * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution);
aref += analogRead(AVCC_MEASURE_PIN) * AR_INTERNAL_VOLTAGE * AVCC_MULTIPLY_FACTOR / (1 << _analogRequestedReadResolution);
}
aref = aref / 10;
analogReference(AR_DEFAULT);
Expand Down
2 changes: 2 additions & 0 deletions variants/MINIMA/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ static const uint8_t SS = PIN_SPI_CS;
#define AVCC_MEASURE_PIN 20
#define AVCC_MULTIPLY_FACTOR 8.33

#define AR_INTERNAL_VOLTAGE 1.43f

#define USB_VID (0x2341)
#define USB_PID (0x0069)
#define USB_NAME "UNO R4 Minima"
Expand Down
2 changes: 2 additions & 0 deletions variants/PORTENTA_C33/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,5 @@ static const uint8_t SS = PIN_SPI_CS;
#define SerialLoRa Serial3

#define RTC_CLOCK_SOURCE RTC_CLOCK_SOURCE_SUBCLK

#define AR_INTERNAL_VOLTAGE 1.18f
2 changes: 2 additions & 0 deletions variants/UNOWIFIR4/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ static const uint8_t SS = PIN_SPI_CS;
#define AVCC_MEASURE_PIN 20
#define AVCC_MULTIPLY_FACTOR 8.33

#define AR_INTERNAL_VOLTAGE 1.43f

#define USB_VID (0x2341)
#define USB_PID (0x006D)
#define USB_NAME "UNO R4 WiFi"
Expand Down