cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 temp sensor counts wrong way !!

dave239955
Associate II
Posted on December 18, 2014 at 21:25

Hi I'm just playing around with the discovery board ST32F0

so I wrote a quick and dirty C app in CoIDE, started a ADC conversion etc and read in the on chip temp sensor. 

Thats all works fine ( or so it seems) even though I,m not calibrating it, nor compensating for the 3v versus 3v3 issue.

What I get at rest on the board is decimal 1900-1927

But strangely it counts lower when I put my finger on the chip and if I hit the chip with some freezer spray it counts higher  ( like 20xx-21xx)

weird ???

any ideas 

thanks

dave 

code below ( parts from a  CoIDE demo)

---------------

&sharpinclude

<stdio.h>

&sharpinclude

<stm32f0xx_gpio.h>

&sharpinclude

<stm32f0xx_rcc.h>

&sharpinclude

<stm32f0xx_adc.h>

int

main(

void

)

{

GPIO_InitTypeDef

gpio;

ADC_InitTypeDef

      ADC_InitStructure;

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,

ENABLE

); 

// Peripheral IO clock

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,

ENABLE

);

// ADC Clock

 GPIO_StructInit(&gpio);

 gpio.

GPIO_Pin

= GPIO_Pin_9;

// Green LED

 gpio.

GPIO_Mode

=

GPIO_Mode_OUT

;

 gpio.

GPIO_OType

=

GPIO_OType_PP

;

 gpio.

GPIO_PuPd

=

GPIO_PuPd_NOPULL

;

 gpio.

GPIO_Speed

= GPIO_Speed_50MHz;

 GPIO_Init(GPIOC, &gpio);

 gpio.

GPIO_Pin

= GPIO_Pin_7;

// Blue LED

 GPIO_Init(GPIOC, &gpio);

/* Initialize ADC structure */

 ADC_StructInit(&ADC_InitStructure);

 ADC_InitStructure.

ADC_ContinuousConvMode

=

ENABLE

;

 ADC_InitStructure.

ADC_DataAlign

= ADC_DataAlign_Right;

 ADC_InitStructure.

ADC_Resolution

= ADC_Resolution_12b;

 ADC_InitStructure.

ADC_ScanDirection

= ADC_ScanDirection_Upward;

 ADC_InitStructure.

ADC_ExternalTrigConvEdge

= ADC_ExternalTrigConvEdge_None;

 ADC_Init(ADC1, &ADC_InitStructure);

 ADC_ChannelConfig(ADC1,ADC_Channel_16,ADC_SampleTime_239_5Cycles);

 ADC_TempSensorCmd(

ENABLE

);

 ADC_Cmd(ADC1,

ENABLE

);

 ADC_StartOfConversion(ADC1);

printf

(

''Hello

Dave

!\r\n''

);

while

(1)

 {

 

static int

i;

 

static

int

led_state=0;

  uint16_t chip_temp;

 

for

(i=0; i<100000; ++i);

  GPIO_WriteBit(GPIOC, GPIO_Pin_9, led_state ?

Bit_SET

:

Bit_RESET

);

  led_state = !led_state;

  GPIO_WriteBit(GPIOC, GPIO_Pin_7, led_state ?

Bit_SET

:

Bit_RESET

);

  

while

(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) ==

RESET

);

// wait for conversion

  chip_temp = ADC_GetConversionValue(ADC1);

 

printf

(

''Chip

Temp

%d\r\n''

, chip_temp);

 }

}

#adc #discovery #stm32f0 #temp
3 REPLIES 3
Uwe Bonnes
Principal III
Posted on December 18, 2014 at 22:20

The on-chip sensor delivers a temperature proportional voltage. The on-chip parameter contain measured voltage at 30 and 110 degree and VDDA 3.3 V. With these values you have to calculate the temperature from the measured voltage.

Posted on December 18, 2014 at 22:41

''A thermistor is a passive device that changes its resistance with temperature. If the temperature-resistance characteristic is known, it can be used as a temperature sensor by measuring the resistance, or more precisely, the voltage across it. Thermistors are classified in to two types: NTC (negative temperature coefficient) and PTC (positive temperature coefficient). A NTC thermistor decreases its resistance while the temperature rises, and a PTC does the opposite.

http://embedded-lab.com/blog/?p=1019

Still weird? Aren't the set points stored in System Memory, so as to define the actual slope?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
raptorhal2
Lead
Posted on December 18, 2014 at 23:17

See Section 12.9 in the reference manual. The formula is:

Temperature (in °C) = {(V25 – VSENSE) / Avg_Slope} + 25

As VSENSE decreases, calculated Temperature increases. The confusing part is that the formula assumes an unsigned slope.

Cheers, Hal