[pyb.ADCAll()] strange results

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
User avatar
roland_vs
Posts: 75
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

[pyb.ADCAll()] strange results

Post by roland_vs » Mon Jul 02, 2018 1:49 pm

Hello,

I'm trying to get the internal voltages of a STM chip and so far I see some odd behaviour:

Code: Select all

# setting it up from REPL
import pyb
pyb.ADCAll(12,0x70000)

# enter through REPL
adc.read_core_temp()
adc.read_core_vbat()
adc.read_core_vref()
adc.read_vref()
The results are not exactly what I would expect, being:

Code: Select all

function	MIN	TYP	MAX
core vref	1.227	1.227	1.227
core_vbat	2.451	2.453	2.455
vref	        3.452	3.454	3.457
core temp      30.060	71.341	71.822
But after a soft reset (ctrl-D) and reentering the above it gets even stranger (IMHO):

Code: Select all

core vref	1.227	1.227	1.277
core vbat	2.452	2.453	2.455
vref	        2.999	3.000	3.002
core temp      71.501	71.501	71.661
The temperature and the core vref seem to behave as expected, but should vbat not be the same as vdd? Also In the second "run" the vref is 0,3V lower whereas the first run the vref was 0,15V higher that the 3,3V it is supposed to be...

The test was run on a NUCLEO_F091RC board. The VBAT is hardwired to VDD and the voltage measured is 3.31V.

The same test on my "reference" PYBV10 board showed expected behaviour:

Code: Select all

function | MIN | TYP | MAX
--- | --- | --- |---
core temp | 36.254 | 36.626 | 36.940 
core vref | 1.205 | 1.205 | 1.205
core vbat | 3.229 | 3.230 | 2.233
core vref | 3.250 | 3.250 | 3.252
So one would expect that the temperatures between these two version would stay around the same and that the core_vbat and vref would behave differently.

Is there a explanation for this?

chuckbook
Posts: 49
Joined: Fri Oct 30, 2015 11:55 pm

Re: [pyb.ADCAll()] strange results

Post by chuckbook » Mon Jul 02, 2018 4:46 pm

Be aware of the fact that so far only a limited number of MCUs (F405, F411, F7xx) are supported when it comes to internal voltage readout and self calibration.

User avatar
roland_vs
Posts: 75
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

Re: [pyb.ADCAll()] strange results

Post by roland_vs » Mon Jul 02, 2018 8:05 pm

The STM32F091RC also has self calibration, however I added it at line 256 to the adc.c, but need to check if there is a noticeable effect:

Code: Select all

#if defined(STM32F0)
    HAL_ADCEx_Calibration_Start(adch);
#endif
I also added a longer time constant at line 286(290) in the channel configuration, but I see that the HAL driver also does some more things, so maybe it is not needed to add it in the adc.c after all. Another check to do.

Code: Select all

#if defined(STM32F0)
    sConfig.SamplingTime = (channel == ADC_CHANNEL_TEMPSENSOR) ? ADC_SAMPLETIME_239CYCLES_5 : ADC_SAMPLETIME_28CYCLES_5;
Everything seems to be there.... Let's fire up the debugger :-)

chuckbook
Posts: 49
Joined: Fri Oct 30, 2015 11:55 pm

Re: [pyb.ADCAll()] strange results

Post by chuckbook » Tue Jul 03, 2018 11:42 am

Self calibration for F4 & F7 means evaluation of Vref by means of factory calibration parameters for temp sensor and internal band-gap reference. It has nothing to do with ADC calibration.

Post Reply