AnsweredAssumed Answered

STM32F072 temp sensor counts wrong way !!

Question asked by mccabe.david on Dec 18, 2014
Latest reply on Dec 18, 2014 by baird.hal.001
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)

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


 

#include <stdio.h>

#include <stm32f0xx_gpio.h>

#include <stm32f0xx_rcc.h>

#include <stm32f0xx_adc.h>

 

intmain(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;

  staticint 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);

 }

}




Outcomes