Microchip® Advanced Software Framework

temp_sensor.c File Reference

Temperature Sensor service.

Copyright (c) 2018-2020 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "temp_sensor.h"

Functions

static uint16_t adc_start_read_result (void)
 ADC START and Read Result. More...
 
static float calculate_temperature (uint16_t raw_code)
 Temperature Calculation. More...
 
static float convert_dec_to_frac (uint8_t val)
 Decimal to Fraction Conversation. More...
 
void get_temp_sensor_data (uint8_t *data)
 Function to read the temperature sensor value. More...
 
static void load_calibration_data (void)
 Calibration Data. More...
 
void temp_sensor_init (void)
 ADC Temperature Sensor mode configuration. More...
 
static double temp_sensor_value (int type)
 

Variables

struct adc_module adc_instance
 
static uint16_t ADCH
 
static uint16_t ADCR
 
static float coarse_temp
 
static float fine_temp
 
static float INT1VH
 
static float INT1VR
 
static float tempH
 
static float tempR
 
static float VADCH
 
static float VADCR
 

static uint16_t adc_start_read_result ( void  )
static

ADC START and Read Result.

          This function starts the ADC and wait for the ADC
          conversation to be complete   and read the ADC result
          register and return the same to calling function.
Parameters
[out]ADCresult value

References adc_get_status(), adc_instance, adc_read(), adc_start_conversion(), and ADC_STATUS_RESULT_READY.

Referenced by temp_sensor_value().

static float calculate_temperature ( uint16_t  raw_code)
static

Temperature Calculation.

         This function calculate fine temperature using Equation1 and Equation
         1b as mentioned in data sheet section "Temperature Sensor Characteristics"
         of Electrical Characteristics.
Parameters
[in]ADCoutput value
[out]Temperaturevalue in Celsius

References ADC_12BIT_FULL_SCALE_VALUE_FLOAT, coarse_temp, fine_temp, INT1V_VALUE_FLOAT, INT1VH, INT1VR, tempH, tempR, VADCH, and VADCR.

Referenced by temp_sensor_value().

static float convert_dec_to_frac ( uint8_t  val)
static

Decimal to Fraction Conversation.

          This function converts the decimal value into fractional
          and return the fractional value for temperature calculation
Parameters
[out]Fractionvalue of Decimal

Referenced by load_calibration_data().

void get_temp_sensor_data ( uint8_t *  data)

Function to read the temperature sensor value.

Parameters
[out]Pointerto Temperature Sensor output value

References temp_sensor_value().

Referenced by get_resource_data().

static void load_calibration_data ( void  )
static

Calibration Data.

This function extract the production calibration data information from Temperature log row content and store it variables for temperature calculation

References ADC_12BIT_FULL_SCALE_VALUE_FLOAT, ADCH, ADCR, convert_dec_to_frac(), INT1V_DIVIDER_1000, INT1VH, INT1VR, tempH, tempR, VADCH, and VADCR.

Referenced by temp_sensor_value().

void temp_sensor_init ( void  )

ADC Temperature Sensor mode configuration.

Function to initialize the ADC for reading temperature sensor value.

This function enables internal temperature sensor feature of ADC with below Settings

GLCK for ADC -> GCLK_GENERATOR_2 (16MHz) CLK_ADC -> 1.6 KHz REFERENCE -> internal 1 V POSITIVE INPUT -> INTRENAL Temperature reference NEGATIVE INPUT -> GND SAMPLES -> 4 SAMPLE_LENGTH -> 4

References ADC_CLOCK_PRESCALER_DIV2, adc_enable(), adc_get_config_defaults(), adc_init(), adc_instance, ADC_NEGATIVE_INPUT_GND, ADC_POSITIVE_INPUT_TEMP, ADC_TEMP_SAMPLE_LENGTH, adc_config::clock_prescaler, adc_config::clock_source, GCLK_GENERATOR_2, adc_config::negative_input, adc_config::positive_input, adc_config::reference, adc_config::sample_length, system_voltage_reference_disable(), system_voltage_reference_enable(), SYSTEM_VOLTAGE_REFERENCE_OUTPUT, and SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE.

Referenced by resource_init().

static double temp_sensor_value ( int  type)
static

struct adc_module adc_instance
uint16_t ADCH
static

Referenced by load_calibration_data().

uint16_t ADCR
static

Referenced by load_calibration_data().

float coarse_temp
static

Referenced by calculate_temperature().

float fine_temp
static

Referenced by calculate_temperature().

float INT1VH
static
float INT1VR
static
float tempH
static
float tempR
static
float VADCH
static
float VADCR
static