Skip to content
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

AdcMcuReadChannel sampling time is too low, causing BoardBatteryMeasureVoltage to return incorrect values #1617

Open
ndiddy99 opened this issue Aug 30, 2024 · 1 comment

Comments

@ndiddy99
Copy link

This applies at least on the NucleoL476 sample code, probably worth looking at the other STM32 sample code as well.

This line sets the ADC sampling time to 92 cycles for every ADC read. The problem is that when it's this low, it makes BoardBatteryMeasureVoltage return incorrect values when the input voltage is under 2.6 volts. We were able to solve this by changing the ADC sampling time to 640 cycles (ADC_SAMPLETIME_640CYCLES_5). This does slightly increase the amount of time the ADC takes to read, but given that AdcMcuReadChannel recalibrates the ADC every time it does a read, I'm assuming ADC read performance isn't a priority anyway.

@ndiddy99
Copy link
Author

ndiddy99 commented Sep 3, 2024

Some objective numbers rather than doing things empirically:
The STM32L476 datasheet (rev 11) says on page 117 that the minimum ADC sampling time when reading the internal voltage reference is 4us. When running the processor at 80MHz and not dividing the AHB clock or the ADC clock, 92 cycles corresponds to around 1.15us (not enough time) while 640 cycles corresponds to around 8us (enough time).

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

No branches or pull requests

1 participant