Page 1 of 1

Strange ADC conversion for temp sensor and internal vref

Posted: Sat Sep 01, 2012 8:19 am
by andyturk
I posted this on the ST e2e board, but thought I'd put it here too since the app is running under ChibiOS.
--------------------------------------------------------------------------------------------------------------------------

I'm running some ADC tests on a VLDiscovery board. The values returned for sampling the internal temp sensor and voltage reference seem to move around in surprising ways. Here's some data:

Code: Select all

> ADC samples:
 channel 16: 2401 1732 2047 2046 2046 2048 2048 2047 2048 2046
 channel 17: 1914 1931 2058 2059 2061 1803 1804 2061 1804 2061
 channel  4: 2044 2046 2045 2043 2045 2041 2046 2042 2045 2044
 channel  1:  978  979  978  978  979  978  980  978  978  978
 channel 16: 1307 1896 1895 1896 1896 1896 1897 1897 1897 1897
 channel 17: 1776 1994 1994 1994 1996 1996 1995 1995 1995 1994
ADC samples:
 channel 16: 2402 1733 2046 2045 2045 2046 2044 2045 2046 2047
 channel 17: 1916 1931 2057 2058 2059 2060 2059 2059 2060 2061
 channel  4: 2045 2046 2045 2043 2045 2044 2045 2043 2020 2046
 channel  1:  977  979  979  978  978  978  979  978  978  979
 channel 16: 1307 1896 1895 1896 1895 1895 1896 1895 1896 1896
 channel 17: 1775 1993 1994 1994 1994 1994 1995 1994 1995 1995
ADC samples:
 channel 16: 2401 1731 2045 2044 2045 2046 2046 2046 2045 2046
 channel 17: 1914 1928 2059 2057 2059 2058 2059 2060 2058 2059
 channel  4: 2043 2045 2043 2041 2046 2044 2046 2044 2023 2044
 channel  1:  978  979  978  978  977  978  980  978  978  978
 channel 16: 1308 1895 1894 1896 1895 1895 1896 1895 1896 1895
 channel 17: 1776 1992 1993 1994 1994 1994 1995 1993 1994 1993


These are three successive runs of code that collects 10 samples from six input channels. Channels 16 and 17 are the internal temperature sensor and voltage reference respectively, measured once at the beginning of the run and again at the end. Channel 4 is a voltage divider at 50% of VDD and Channel 1 is set by a potentiometer.

Notice that the external ADC inputs are quite stable (e.g., Channels 1 and 4). However, the internal inputs suggest that temperature and/or voltage are changing between the first sampling and the second. Every ADC sample in this code (regardless of which channel) gets 239.5 ADC clocks for sampling time.

The temp/vref values aren't particularly interesting in the long run, but I'd like to understand what the ADC is doing. Is there an explanation for why the internal stuff varies so much?

In case it matters, I've hacked this VLDiscovery board to use a STM32F103RG mcu instead of the original.

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sat Sep 01, 2012 8:36 am
by mabl
Hi andyturk,

I once ran into similar issues with ATMEL AVRs when I did fast sampling since the internal sources had too high impedance. But probably that's not your problem, since you have very long sampling times, right?

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sat Sep 01, 2012 9:08 am
by Giovanni
Correct, consult the RM because the sensor and vref require a very long sampling time, I think it is correctly done in the demos using the ADC.

In general usable sampling times depend on input impedance.

Giovanni

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sun Sep 02, 2012 1:50 am
by andyturk
I think I found the problem. The board initialization was leaving ADCPRE at DIV2 which meant the ADC clock was running at 36MHz--way over the 14MHz limit. Once I set ADCPRE to DIV8, the numbers got better.

Code: Select all

> ADC samples:
 channel 16:  548 1908 1910 1909 1910 1910 1910 1909 1912 1910
 channel 17: 1660 1696 1695 1694 1696 1693 1695 1693 1695 1695
 channel  4: 2044 2045 2044 2043 2046 2045 2046 2047 2041 2043
 channel  1:  928  930  929  929  928  930  929  928  930  931
 channel 16: 1910 1910 1909 1910 1911 1910 1910 1912 1910 1910
 channel 17: 1693 1696 1694 1694 1693 1696 1696 1693 1695 1696
 channel  4: 2044 2043 2043 2045 2045 2045 2046 2043 2042 2044
 channel  1:  928  929  928  930  929  929  928  928  927  930
ADC samples:
 channel 16: 1484 1909 1908 1908 1909 1908 1908 1908 1910 1910
 channel 17: 1586 1695 1694 1693 1695 1692 1693 1693 1695 1694
 channel  4: 2045 2044 2044 2043 2045 2045 2046 2045 2044 2045
 channel  1:  926  930  929  929  930  927  929  929  929  930
 channel 16: 1909 1908 1909 1909 1908 1908 1909 1908 1908 1911
 channel 17: 1691 1696 1694 1693 1693 1693 1691 1695 1693 1693
 channel  4: 2043 2043 2046 2045 2043 2045 2045 2045 2044 2045
 channel  1:  928  929  930  927  926  930  927  919  930  929
ADC samples:
 channel 16: 1484 1911 1910 1910 1911 1908 1910 1910 1911 1910
 channel 17: 1588 1695 1694 1691 1692 1693 1694 1692 1694 1693
 channel  4: 2044 2046 2044 2045 2045 2045 2043 2043 2044 2045
 channel  1:  930  929  928  928  930  927  928  927  927  928
 channel 16: 1909 1910 1910 1911 1910 1910 1911 1911 1910 1911
 channel 17: 1694 1695 1692 1691 1694 1693 1693 1695 1695 1693
 channel  4: 2044 2044 2045 2044 2044 2044 2044 2046 2044 2044
 channel  1:  928  929  929  928  929  927  929  929  929  928

This was with Vdd/Vdda = 2.989v
The channel 4 pin at 1.494v = (1.494/2.989)*4096 = 2047
The channel 1 pin at 0.68v = (0.68/2.989)*4096 = 932
Vrefint (channel 17) is spec'd between 1.16 and 1.24v which is 1589 to 1699 on the ADC
The internal channels use a sampling time greater than 17.1us (specified in the ref manual). The external channels use the shortest sampling time available.

The only issue seems to be that the first samples from the internal channels are always low. I don't think this is related to enabling TSVREFE because that happens when the board was reset. The samples are taken when I press the user button a gazillion clock cycles later. Not a deal breaker, just odd.

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sun Sep 02, 2012 2:57 pm
by Giovanni
Hi, is that a modified Discovery board? The stock board has a 24MHz clock and that results in a 12MHz ADC clock.

Giovanni

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sun Sep 02, 2012 4:14 pm
by andyturk
Giovanni wrote:Hi, is that a modified Discovery board? The stock board has a 24MHz clock and that results in a 12MHz ADC clock.

Giovanni

Yup. It's got a F103RG running at 72MHz.

Re: Strange ADC conversion for temp sensor and internal vref

Posted: Sun Sep 02, 2012 4:20 pm
by Giovanni
Be careful, you have to use a mcuconf.h for a STM32F1 and make a modified board file.

Giovanni