cancel
Showing results for 
Search instead for 
Did you mean: 

Getting temperature from ADC on STM32f091

gaetanbusson
Associate II
Posted on April 27, 2016 at 15:46

Hello!

I have a problem with the sensor temperature of STM32F091 (ARM Cortex M0).

According to datasheet, temperature is coming from ADC channel 16.

In my program, ADC acquiring is working well because I can receive values from channels 10, 11 and  12.

The value I read from ADC channel 16 (temperature sensor) is 117.

According to

http://www2.st.com/content/ccc/resource/technical/document/reference_manual/c2/f8/8a/f2/18/e6/43/96/DM00031936.pdf/files/DM00031936.pdf/jcr:content/translations/en.DM00031936.pdf

, temperature is computed with the following formula:

temperature = ((110-30)/(TS_CAL2 - TS_CAL1)) x (TS_DATA * TS_CAL1) + 30

This formula doesn't work for me: zero is returned.

I tried to understand why by checking the value of TS_CAL1 and TS_CAL2 in the chip memory. The values are the following:

TS_CAL1 = 0xDF06 (1759 in decimal)

TS_CAL2 = 0x2605 (1318 in decimal)

I found these values at the addresses given in the

http://www2.st.com/content/ccc/resource/technical/document/datasheet/95/3c/2e/5b/21/09/45/a6/DM00115237.pdf/files/DM00115237.pdf/jcr:content/translations/en.DM00115237.pdf

.

If I well understand, I should have 1759 when I have 30�C.

How can I have this 16 bit value when my ADC is sampling 8 bits (255 max)?

Then I tried to change scale of TS_CAL1 and TS_CAL2 in case of ST made their acquiring in 12bits mode:

NEW_TS_CAL1 = (TS_CAL1 * 4095)/255 = 110

NEW_TS_CAL2 = (TS_CAL2 * 4095)/255 = 82

With these values the formula returns me a value of 8�C but the temperature in the romm I am currently working in is 24�C.

I don't know what to do now to make it work. Please help

#getting-temperature-from-adc-on
4 REPLIES 4
troy1818
Senior
Posted on April 29, 2016 at 13:01

Do you have any source on this that you can disclose ?

Posted on April 29, 2016 at 13:52

Do you have the endian order of the bytes backward? Remember this is small endian, and an example for reading the values is provided in C, use that and print the values, or list the individual bytes as they appear in memory.

Why 8-bit? The ADC is capable of 12-bit.

If you use 8-bit and the adjustment parameters are 12-bit you're going to have to scale the value you read from the ADC with a <<4 but you're going to lose a lot of resolution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
re.wolff9
Senior
Posted on April 30, 2016 at 11:16

8 bit gives you 16 degree steps. (the forum ate the rest of my post). 

Posted on May 18, 2016 at 16:52

The formula in the Datasheet:

>According to

http://www2.st.com/content/ccc/resource/technical/document/reference_manual/c2/f8/8a/f2/18/e6/43/96/DM00031936.pdf/files/DM00031936.pdf/jcr:content/translations/en.DM00031936.pdf

, temperature is computed with the following formula:

>temperature = ((110-30)/(TS_CAL2 - TS_CAL1)) x (TS_DATA * TS_CAL1) + 30

has a serious Problem I ran into, too.

You can not use integer math to get a temperature value that is correct. Define all used variables into float and you will get  proper results. If you do the math on a Piece of paper with integer, you always get 30 as a result ( the last +30 in the formula).

Best regards,

Markus.