Skip to content

VREF-olutionary: VREF support/instantiation for ADCs#124

Merged
ActuallyTaylor merged 7 commits into
mainfrom
feature/ol2764RIT/adcVREF
Jan 18, 2026
Merged

VREF-olutionary: VREF support/instantiation for ADCs#124
ActuallyTaylor merged 7 commits into
mainfrom
feature/ol2764RIT/adcVREF

Conversation

@oleglazari

Copy link
Copy Markdown
Contributor

Add configurable VREF voltage support to the ADC system for improved measurement accuracy.

The ADC bases its voltage calculations from the VREF pin on the STM32F302R8, but the ADC hardware doesn't implicitly know what the actual voltage at VREF is. Previously, the system assumed a hardcoded 3.3V reference, which could lead to inaccurate voltage readings when using different reference voltages.

This PR adds setVref(float vref) and getVref() methods to the ADC interface, enabling accurate measurements with various reference voltages (1.8V, 3.3V, 5.0V, etc.). The implementation replaces hardcoded VREF values with configurable runtime settings in both STM32F3xx and F4xx platforms.

io::ADC& adc = io::getADC<io::Pin::PA_0, io::ADCPeriph::ONE>();
adc.setVref(5.0f);  // Set 5V reference
float voltage = adc.read();  // Now calculated with correct VREF

And do not fret, the default will always be 3.3V so old ADC code will not break

@oleglazari oleglazari requested a review from a team September 30, 2025 11:19

@ActuallyTaylor ActuallyTaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good! I just see a quick code removal in one of the samples.

Comment thread samples/adc/single_adc.cpp Outdated
Comment thread samples/adc/vref_demo.cpp Outdated

@EvanHughes-dev EvanHughes-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good. There's just two comments (really the same comment) that needs clarification.

Comment thread include/core/io/platform/f3xx/ADCf3xx.hpp Outdated
Comment thread include/core/io/platform/f4xx/ADCf4xx.hpp Outdated

@mjh9585 mjh9585 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments.

Comment thread samples/adc/multi_adc.cpp Outdated
Comment thread samples/adc/vref_demo.cpp Outdated

@EvanHughes-dev EvanHughes-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ActuallyTaylor ActuallyTaylor merged commit 7a4d273 into main Jan 18, 2026
1 check passed
@ActuallyTaylor ActuallyTaylor deleted the feature/ol2764RIT/adcVREF branch January 18, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants