Search This Blog

Mar 8, 2012

SiM3U1xx-temperature-sensor


Introduction

  SiM3U1xx and SiM3C1xx contain on-chip temperature sensor module.  The temp sensor produces a voltage that is proportional to the temperature of the die in the device.  This voltage is supplied as one of the inputs to SARADC (Analog to Digital Converter).  The ADC conversion result can be converted into a temperature in degrees with a little math.

Function Description

  The temperature sensor is controlled from within the Voltage reference and Temperature Sensor (VREF) module. And here is the VREF diagram.

The temperature sensor is enabled using the TEMPEN bit in the CONTROL register. When enabled, the temperature sensor output is available to any analog peripherals which have a temperature sensor input.  Below is detailed register descriptions for VREF0 registers.


The temperature sensor output is linear with a positive slope; when temperature increases, the output voltage of the sensor increases.  We got figure illustrates the temperature sensor transfer function.


We have equation to calculate temperature from above figure.
Tempc =( Vtemp - offset) / Slope

Where:
Tempc = the die temperature in degrees C.
Vtemp = the output voltage of the temperature sensor in mV
Offset = 760mV at 0 degree C
Slope = 2.8 mV/C

We can refer to the electrical characteristics section of the specific device data sheet for temperature sensor parameters.
And Vtemp can get from SARADC conversion result.
Vtemp   (code/ 1024) x VREF
Where:
code = the left-justified 10 bit SARADC output code
VREF  = the value of the voltage reference, which is around 2.4V or 1.2V if internal VREF is used.



Implementation Considerations

    The temp sensor measures the temperature of the die of the device, which is likely to be a few degrees warmer than the surrounding ambient temperature due to device power dissipation. In order to find the ambient temperature, the temperature increase due to self-heating must be subtracted from the result. The value of this temperature increase can be calculated or measured.
    The temperature increase due to self-heating can be measured in a number of ways. One method is to initiate a conversion soon after applying power to the device to get a 'cold' temperature reading, and then measure again after about a minute of operation, to get a 'hot' temperature reading. The difference between the two measurements is the contribution due to self-heating.
    Another method is to operate the device from a low SYSCLK frequency, for example a 32 kHz watch crystal, and take a temperature measurement, then operate the device at a higher frequency, the 16 MHz internal oscillator for example, and take the difference. The amount of self-heating at the lower clock frequency is negligible because the power dissipation of the device at that frequency is low.

Code Implementation

   We used AppBuilder to generate basic code we need, and then added necessary code to make temperature sensor works.
void CLKCTRL_setup_default_mode_clock_gates(void)
{
  SI32_CLKCTRL_A_enable_apb_to_modules_0(SI32_CLKCTRL_0,
                                         SI32_CLKCTRL_A_APBCLKG0_PB0 |
                                         SI32_CLKCTRL_A_APBCLKG0_SARADC0);
  SI32_CLKCTRL_A_enable_apb_to_modules_1(SI32_CLKCTRL_0,
                                         SI32_CLKCTRL_A_APBCLKG1_MISC1 |
                                         SI32_CLKCTRL_A_APBCLKG1_MISC0);
}
2.       Enable internal voltage reference and temperature sensor, select 2.4v as reference output  voltage.(gVREF0.c)

void VREF0_enter_default_mode_from_reset(void)
{
  SI32_VREF_A_enable_temperature_sensor(SI32_VREF_0);
  SI32_VREF_A_select_2p4_volts(SI32_VREF_0);
  SI32_VREF_A_enable_voltage_reference(SI32_VREF_0);
}
3.       Enable SARADC module; VREF select External REF pin; Timeslot0 channel is “Temperature Sensor Output”; Output packing mode is “Lower half-word only”. And keep default setting of reference GND select as “internal GND” and start of conversion source as “On Demand by writing 1to ADBUSY” (gSARADC.c)
void SARADC0_enter_default_mode_from_reset(void)
{
  SI32_SARADC_A_enable_module(SI32_SARADC_0);
  SI32_SARADC_A_select_vref_external(SI32_SARADC_0);
  SI32_SARADC_A_select_timeslot0_channel(SI32_SARADC_0, 20);
  SI32_SARADC_A_select_output_packing_mode_lower_halfword_only(SI32_SARADC_0);
}
4.       Port bank configuration. PB0.0 and PB0.12 need to be set as analog pin and skipped in crossbar.(gPB.c)
void pb_enter_default_mode_from_reset(void)
{
  SI32_PBCFG_A_unlock_ports(SI32_PBCFG_0);
  // PB0 Setup
  SI32_PBSTD_A_set_pins_analog(SI32_PBSTD_0, 0x1001);
  SI32_PBSTD_A_write_pbskipen(SI32_PBSTD_0, 0x1001);
  // PB1 Setup
  SI32_PBSTD_A_set_pins_push_pull_output(SI32_PBSTD_1, 0x0008);
  SI32_PBSTD_A_write_pbskipen(SI32_PBSTD_1, 0x0008);
  // Enable Crossbar0 signals & set properties
  SI32_PBCFG_A_enable_crossbar_0(SI32_PBCFG_0);
}
5.       Convert output voltage of temperature sensor and calculate temperate degree C.
//======================================================================
// Read back temperature sensor output and convert it to temperature value.
// The equation is: Vtemp = (code / 2^nbits) * Vref, Temperature=(Vtemp-Voff)/slope
// Notes: We use 10-bit ADC which means 2^10 = 1024; Vref we choose VREF pin
// reference voltage 1.2v or 2.4v, Vref = 1650mV; And Voff is 760mV at 0°C.
// Slope is 2.8 mV/°C
//======================================================================
void mySARADC0_convert_temperature_value(void)
{
  int32_t temperature = 0;
  int32_t vtemp,vref;
   vref = (vref_mode == 0)?1200:2400;
  SI32_SARADC_A_start_conversion(SI32_SARADC_0);
  while((0x20 & SI32_SARADC_A_read_fifostatus(SI32_SARADC_0)) == 0);
  vtemp = ( SI32_SARADC_A_read_data(SI32_SARADC_0) * vref) / 1024;
  temperature = (vtemp - 760) * 10000 / 280;
  printf("The temperature is %i.%02d degrees Celsius, vref = %imV\n",temperature/100,(uint32_t)(temperature % 100),vref); 
}

Function validation

   We can use hairdryer to heat the chip and observer the output of temperature value in the Debug (printf) Viewer.

References

1.       SiM3U1xx/SiM3C1xx Reference Manual: downloadable from the Silicon Labs web site at http://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support Documents/TechnicalDocs/SiM3U1xx_SiM3C1xx_RM.pdf&src=DocumentationWebPart

2.       SiM3U1xx Data Sheet: downloadable from the Silicon Labs web site at http://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support Documents/TechnicalDocs/SiM3U1xx.pdf&src=DocumentationWebPart

3.       Using the On-Chip Temperature Sensor : downloadable from the Silicon Labs web site at  http://www.silabs.com/Support%20Documents/TechnicalDocs/an103.pdf

No comments: