ADC Sensor interface.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
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.
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().
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().
Referenced by adc_handler(), and lightsensor_data_is_ready().
adc_result_t light_sensor_sample = 0 |
Referenced by adc_handler(), and lightsensor_get_raw_value().
bool to hold the data ready flag
Referenced by adc_handler(), and ntc_data_is_ready().
adc_result_t ntc_sensor_sample = 0 |
Referenced by adc_handler(), ntc_get_raw_value(), and ntc_get_temperature().