Atmel Software Framework

adc_sensors.c File Reference

ADC Sensor interface.

Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.

#include "adc.h"
#include "adc_sensors.h"

Macros

#define LIGHT_SENSOR_MAX_SAMPLES   4
 
#define NTC_SENSOR_MAX_SAMPLES   4
 

Functions

void adc_handler (ADC_t *adc, uint8_t ch_mask, adc_result_t result)
 Callback for the ADC conversion complete. More...
 
void adc_sensors_init (void)
 Initialize ADC channels for NTC and lightsensor. More...
 
bool lightsensor_data_is_ready (void)
 
int16_t lightsensor_get_raw_value (void)
 Read the lightsensor value from the ADC. More...
 
bool ntc_data_is_ready (void)
 Check of there is NTC data ready to be read. More...
 
int16_t ntc_get_raw_value (void)
 Read the NTC value from the ADC. More...
 
int8_t ntc_get_temperature (void)
 Read the actual temperature from the NTC. More...
 

Variables

bool light_sensor_data_ready = false
 
adc_result_t light_sensor_sample = 0
 
bool ntc_sensor_data_ready = false
 bool to hold the data ready flag More...
 
adc_result_t ntc_sensor_sample = 0
 

#define LIGHT_SENSOR_MAX_SAMPLES   4

Referenced by adc_handler().

#define NTC_SENSOR_MAX_SAMPLES   4

Referenced by adc_handler().

void adc_handler ( ADC_t *  adc,
uint8_t  ch_mask,
adc_result_t  result 
)

Callback for the ADC conversion complete.

The ADC module will call this function on a conversion complete.

Parameters
adcthe ADC from which the interrupt came
ch_maskthe ch_mask that produced the interrupt
resultthe result from the ADC

References ADC_CH0, ADC_CH1, light_sensor_data_ready, LIGHT_SENSOR_MAX_SAMPLES, light_sensor_sample, lightsensor_measure(), ntc_measure(), ntc_sensor_data_ready, NTC_SENSOR_MAX_SAMPLES, ntc_sensor_sample, and result.

bool lightsensor_data_is_ready ( void  )
int16_t lightsensor_get_raw_value ( void  )

Read the lightsensor value from the ADC.

This will read the ADC value of the channel and pin connected to the lightsensor on the A3BU-Xplained.

Return values
theraw ADC value from the current ntc_sensor_sample

References light_sensor_sample.

Referenced by lightsensor_application().

bool ntc_data_is_ready ( void  )

Check of there is NTC data ready to be read.

When data is ready to be read this function will return true, and assume that the data is going to be read so it sets the ready flag to false.

Return values
trueif the NTC value is ready to be read
falseif data is not ready yet

References cpu_irq_restore(), cpu_irq_save(), and ntc_sensor_data_ready.

Referenced by ntc_sensor_application().

int16_t ntc_get_raw_value ( void  )

Read the NTC value from the ADC.

This will read the ADC value of the channel and pin connected to the NTC on the A3BU-Xplained.

Return values
theraw ADC value from the current ntc_sensor_sample

References ntc_sensor_sample.

int8_t ntc_get_temperature ( void  )

Read the actual temperature from the NTC.

This function returns the temperature in Celsius by piecewise linearisation of the complex transfer function between NTC resistance and ADC codes. The accuracy of the temperature is somewhat limited.

Note
The result is inaccurate for temperatures outside 5-45 degrees.
Return values
thetemperature in Celsius

References ntc_sensor_sample.

Referenced by ntc_sensor_application().

bool light_sensor_data_ready = false
adc_result_t light_sensor_sample = 0
bool ntc_sensor_data_ready = false

bool to hold the data ready flag

Referenced by adc_handler(), and ntc_data_is_ready().

adc_result_t ntc_sensor_sample = 0