Page 2 of 2

Re: STM32F103C8T6 Reference Voltage READ

Posted: Fri Jun 03, 2022 7:10 am
by hyur
ag123 wrote: Thu Jun 02, 2022 4:19 am google search for RM0008 stm32f103
you should get this
https://www.st.com/resource/en/referenc ... ronics.pdf

look in the chapter for ADC, look under temperature sensor section
in libmaple (roger's core) you may need to use the adc library or rather the adc includes in the core for that.
Following your advice, I checked the register and was able to read the internal temperature value as well.

I got the Vsense value through analogRead, and checked the internal temperature according to the following formula.
{(V25 - VSENSE) / Avg_Slope} + 25.

However, the formula related to Vrefint could not be found in the datasheet.

Is there something I'm missing out on?

Re: STM32F103C8T6 Reference Voltage READ

Posted: Fri Jun 03, 2022 7:31 am
by ag123
Vrefint is in the data sheet
https://www.st.com/en/microcontrollers- ... 103c8.html

5.3.4 Embedded reference voltage
VREFINT min 1.16, typ 1.2 max 1.24 v
that is the adc reading you get for 1.2v

so assuming a linear range, and that the top is vdd 3.3v
by linear projection : adc reading at vdd = 3.3 * adc_value / 1.2
that is the value at the top
it should be pretty close to 4096 ~ 2^12 for 12 bits adc

if I'm not too fussy about accuracy, I'd make a wild assumption 3.3v reads as 4096
so my voltage at adc reading : adc_volt = adc_value * 3.3 / 4096
otherwise you could substitute this 4096 with the adc reading at vdd found from the prior step using Vrefint

Re: STM32F103C8T6 Reference Voltage READ

Posted: Fri Jun 03, 2022 8:23 am
by hyur
Following your advice, I was able to read the datasheet and read the ADC1_IN17(Vrefint) value.

With Vrefint and the following formula, I was able to get a value of 3.27~3.28V.
float VRef = (1.20 / vrefint) * 4096.0;

I measured the voltage on the board and it came out 3.314V. Is this an acceptable errors?

If so, is the sampling time an issue?
Right now my sampling timing is set to 71.5 cycles.

Re: STM32F103C8T6 Reference Voltage READ

Posted: Fri Jun 03, 2022 9:11 am
by ag123
your formula looks right, the adc won't get the full 3.3v at the top in part due to the various electronics (e.g. transistors in there)
being a little less than 3.3v looks normal.
As things I do normally won't need very high precision or accuracy, i'd make do
other ways you could verify things is to measure a known voltage on the adc, e.g. compare with a multimeter etc
that'd let you know if you are on the right track.

Re: STM32F103C8T6 Reference Voltage READ

Posted: Mon Jun 06, 2022 11:49 pm
by hyur
As a result of measuring in millimeters, I was able to read a value similar to the internal reference voltage.

Thanks to you, I was able to solve my difficulties.

Thank you very much.

Re: STM32F103C8T6 Reference Voltage READ

Posted: Wed Aug 30, 2023 11:45 am
by john1995
hyur wrote: Fri Jun 03, 2022 8:23 am Following your advice, I was able to read the datasheet and read the ADC1_IN17(Vrefint) value.

With Vrefint and the following formula, I was able to get a value of 3.27~3.28V.
float VRef = (1.20 / vrefint) * 4096.0;

I measured the voltage on the board and it came out 3.314V. Is this an acceptable errors?

If so, is the sampling time an issue?
Right now my sampling timing is set to 71.5 cycles.
what value has the variable vrefint?