-
Hello, In my setup I am using the STM32L082. It is powered with 1.8V. The 1.8V is from a buck/boost convertor which itself is is powered by a SuperCap. I would like to measure the voltage of the SuperCap voltage, this is connected to pin PA0 (using a resistor divider to lower voltage) and mosfet switch to allow voltage measurement (PA1). So I thought a traditional readAnalog() would do the trick. Unfortunately I am experiencing some output that I cannot explain.
The calibrated VRREFINT from system memory makes sense and is approx. 1.22 (V) (3/4095 * 1673 = 1.2256...V Any idea? (attached some part of my code below)
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Hi, Here an example how to use internal channel: |
Beta Was this translation helpful? Give feedback.
-
That works. I placed it as building flag in my platformio.ini
FYI - implemented the following (for those who might run into this issue as well STM32L082) // Step 1: Initialize ADC
analogReadResolution(12); // 12-bit ADC (0-4095)
pinMode(PA0, INPUT_ANALOG); // Configure PA0 as an analog input
digitalWrite(PA1, HIGH); // Enable voltage measurement circuit
delay(100); // Allow voltage to stabilize
// Step 2: Read factory-calibrated VREFINT value from system memory
uint16_t vrefint_cal = *((uint16_t*)0x1FF80078);
// Step 3: Compute the actual voltage of VREFINT (factory calibration)
float Volt_refint = (3.0f / 4095.0f) * vrefint_cal;
// Step 4: Measure the actual ADC value of VREFINT and PA0
uint16_t vrefint_raw = analogRead(AVREF); // Read VREFINT (ADC Channel)
uint16_t pa0_raw = analogRead(PA0); // Read PA0 voltage
// Step 5: Compute estimated VDDA using VREFINT
float vdd_est = (Volt_refint / vrefint_raw) * 4095.0f;
// Step 6: Convert ADC PA0 reading to voltage using estimated VDDA
float pa0_voltage = (vdd_est / 4095.0f) * pa0_raw; Thanks again for your help Frederic! |
Beta Was this translation helpful? Give feedback.
-
Hi;
I'm not even a beginner, not even a newbie, so please accept my apologies
if this is a stupid thing:
I was looking at the library that is referred to, below, and I noticed
something that looked unusual, the two lines *highlighted*, are different
than all the other lines?
Just wonderin'
#ifndef ADC_SAMPLINGTIME
#if defined(ADC_SAMPLETIME_8CYCLES_5)
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_8CYCLES_5;
#elif *#defined(ADC_SAMPLETIME_12CYCLES)*
*#define ADC_SAMPLINGTIME ADC_SAMPLETIME_12CYCLES;*
#elif defined(ADC_SAMPLETIME_12CYCLES_5)
Best regards from Germany
Lohi Karhu
…On Mon, Mar 10, 2025, 18:32 Frederic Pillon ***@***.***> wrote:
No API. You can redefine this using build_opt.h:
https://github.com/stm32duino/Arduino_Core_STM32/blob/6b6a8a6cab34fe0f3bc78a36166acc5c99810f94/libraries/SrcWrapper/src/stm32/analog.cpp#L33
—
Reply to this email directly, view it on GitHub
<#2676 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGBMPKWWC2FOOWSMJHGWIVD2TXEDLAVCNFSM6AAAAABYWEN7VOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENBVGI2DOOI>
.
You are receiving this because you are subscribed to this thread.Message
ID: <stm32duino/Arduino_Core_STM32/repo-discussions/2676/comments/12452479
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
Just that the "syntax", if I can call it that, of this part:
#elif defined(ADC_SAMPLETIME_12CYCLES)
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_12CYCLES;
Doesn't have the. *_5 * after the "12CYCLES"
to match the format of all of the other lines, that look like this:
(ADC_SAMPLETIME_12CYCLES_5)
When something looks "out of place", I just wondered why...
…On Thu, Mar 13, 2025, 16:40 Frederic Pillon ***@***.***> wrote:
Sorry don't understand your question. Your code is not correct and does
not match the code:
https://github.com/stm32duino/Arduino_Core_STM32/blob/db4fdcc0f2b938cb8b797c50ade8b5cd886c5037/libraries/SrcWrapper/src/stm32/analog.cpp#L38-L41
—
Reply to this email directly, view it on GitHub
<#2676 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGBMPKVVN4OI3OATSKYOHKL2UGRFDAVCNFSM6AAAAABYWEN7VOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENBZGAZDKMQ>
.
You are receiving this because you commented.Message ID:
<stm32duino/Arduino_Core_STM32/repo-discussions/2676/comments/12490252@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
Okey dokey, just seemed strange that only one line was without the _5
As I said, new to this... 40 years of system level, and even IC Development
(like LP5523, STLED25) and even "bare metal" with MC6801/09, 68HC11, 68k,
but nary a line of C.
Thx
…On Thu, Mar 13, 2025, 17:57 Frederic Pillon ***@***.***> wrote:
Have in mind the core support several stm32 series, then not all have the
_5.
STM32C0 have:
https://github.com/stm32duino/Arduino_Core_STM32/blob/db4fdcc0f2b938cb8b797c50ade8b5cd886c5037/system/Drivers/STM32C0xx_HAL_Driver/Inc/stm32c0xx_hal_adc.h#L757-L767
but STM32U5 not:
https://github.com/stm32duino/Arduino_Core_STM32/blob/db4fdcc0f2b938cb8b797c50ade8b5cd886c5037/system/Drivers/STM32U5xx_HAL_Driver/Inc/stm32u5xx_hal_adc.h#L948-L958
—
Reply to this email directly, view it on GitHub
<#2676 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGBMPKWLLU2NN3HYVDKMZ3L2UG2G5AVCNFSM6AAAAABYWEN7VOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENBZGEZTCOA>
.
You are receiving this because you commented.Message ID:
<stm32duino/Arduino_Core_STM32/repo-discussions/2676/comments/12491318@
github.com>
|
Beta Was this translation helpful? Give feedback.
No API. You can redefine this using build_opt.h:
Arduino_Core_STM32/libraries/SrcWrapper/src/stm32/analog.cpp
Line 33 in 6b6a8a6