arduino / arduino/ArduinoCore-avr

Feature Request: Add Support For Reference Voltages To analogRead

Open
#375 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hello,

I believe it would be valuable to be able to read the Arduino reference voltages using the built in Arduino library.

# Background
Many ATmega chips have an internal "1.1V Bandgap Reference" and a 0v reference voltage which their ADCs can read.

For details please see the [ATMega2560 data sheet](https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega640-1280-1281-2560-2561-Datasheet-DS40002211A.pdf). You can see the options to the Mux on P. 269, and the Mux selector is defined on P. 283.

# Use
These allow for measuring VCC. Once calibrated, this can be done with high accuracy.

# The Problem
`analogRead` explicitly masks MUX4, which must be set to obtain these values. This was probably done to block off all of the differential ADC options.

# Proposed Solutions
## Option 1:
Per `analogRead` There are a maximum of 54 defined pins, and twice that (108) for supporting channels. Reserving Pins 126 and 127 for these references and explicitly looking for those would work.

## Option 2:
Add dedicated functions to read the reference voltages.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the analogRead implementation and compare its MUX4 masking with the ATmega2560 datasheet's ADC MUX options on pages 269 and 283. Determine the supported API shape for reading the 1.1V bandgap and 0V references, then verify that the chosen interface can measure both reference voltages without breaking existing analogRead behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.