Skip to content

Conversation

@oleglazari
Copy link

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
Copy link
Member

@ActuallyTaylor ActuallyTaylor left a comment

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.

Copy link

@EvanHughes-dev EvanHughes-dev left a comment

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.

Copy link
Contributor

@mjh9585 mjh9585 left a comment

Choose a reason for hiding this comment

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

Two small comments.

Copy link

@EvanHughes-dev EvanHughes-dev left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants