ADC Sensor interface.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "adc.h"
Functions | |
void | adc_handler (ADC_t *adc, uint8_t channel, 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... | |
static void | lightsensor_measure (void) |
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... | |
static void | ntc_measure (void) |
Call this to schedule a ADC reading of the temperature sensor. More... | |
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.
adc | the ADC from which the interrupt came |
ch_mask | the ch_mask that produced the interrupt |
result | the result from the ADC |
References ADC_CH0, light_sensor_data_ready, LIGHT_SENSOR_MAX_SAMPLES, light_sensor_sample, lightsensor_measure(), ntc_measure(), ntc_sensor_data_ready, NTC_SENSOR_MAX_SAMPLES, and ntc_sensor_sample.
Referenced by adc_sensors_init().
void adc_sensors_init | ( | void | ) |
Initialize ADC channels for NTC and lightsensor.
This will set up the ADC for reading the NTC and light sensor present on the A3BU-Xplained board.
References ADC_CH0, adc_enable(), adc_handler(), adc_read_configuration(), ADC_REF_VCC, ADC_RES_12, adc_set_callback(), adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_ON, ADC_TRIG_MANUAL, adc_write_configuration(), adcch_enable_interrupt(), ADCCH_MODE_COMPLETE, ADCCH_NEG_NONE, ADCCH_POS_PIN0, ADCCH_POS_PIN1, adcch_read_configuration(), adcch_set_input(), adcch_set_interrupt_mode(), and adcch_write_configuration().
Referenced by main().
bool lightsensor_data_is_ready | ( | void | ) |
References cpu_irq_restore(), cpu_irq_save(), and light_sensor_data_ready.
Referenced by lightsensor_application().
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.
the | raw ADC value from the current ntc_sensor_sample |
References light_sensor_sample.
Referenced by lightsensor_application().
|
inlinestatic |
References ADC_CH0, and adc_start_conversion().
Referenced by adc_handler(), and 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.
true | if the NTC value is ready to be read |
false | if 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.
the | raw 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.
the | temperature in Celsius |
References ntc_sensor_sample.
Referenced by ntc_sensor_application().
|
inlinestatic |
Call this to schedule a ADC reading of the temperature sensor.
Calling this will trigger the ADC to perform a reading of the on board NTC, the ADC will automatically recall this function the number of times specified for averaging.
References adc_start_conversion().
Referenced by adc_handler(), and ntc_sensor_application().