30 #include "pprzlink/messages.h"
51 #if PERIODIC_TELEMETRY
58 #ifndef TEMP_ADC_CHANNEL1
59 #ifndef TEMP_ADC_CHANNEL2
60 #ifndef TEMP_ADC_CHANNEL3
61 #error "at least one TEMP_ADC_CHANNEL1/2/3 needs to be defined to use the temp_adc module"
66 #ifdef TEMP_ADC_CHANNEL1
67 static struct adc_buf temp_buf1;
69 #ifndef TEMP_ADC_CHANNEL1_TYPE
70 #define TEMP_ADC_CHANNEL1_TYPE LM35
74 #ifdef TEMP_ADC_CHANNEL2
75 static struct adc_buf temp_buf2;
77 #ifndef TEMP_ADC_CHANNEL2_TYPE
78 #define TEMP_ADC_CHANNEL2_TYPE LM35
82 #ifdef TEMP_ADC_CHANNEL3
83 static struct adc_buf temp_buf3;
85 #ifndef TEMP_ADC_CHANNEL3_TYPE
86 #define TEMP_ADC_CHANNEL3_TYPE LM35
90 #ifndef TEMP_ADC_NB_SAMPLES
91 #define TEMP_ADC_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
97 #ifndef TEMP_ADC_SYNC_SEND
98 #define TEMP_ADC_SYNC_SEND FALSE
107 float log_r = log((pull_up_r * raw_adc) / (
ADC_RESOLUTION - raw_adc));
111 float temp_c = 1 / (a + (b * log_r) + (c * log_r * log_r * log_r));
112 temp_c = temp_c - 273.15;
118 return ((
float)raw_temp * (3300.0f / 1024.0f) / 10.0f);
133 #ifdef TEMP_ADC_CHANNEL1
137 #ifdef TEMP_ADC_CHANNEL2
141 #ifdef TEMP_ADC_CHANNEL3
145 #if PERIODIC_TELEMETRY
155 #ifdef TEMP_ADC_CHANNEL1
156 adc_raw = temp_buf1.sum / temp_buf1.av_nb_sample;
157 #if TEMP_ADC_CHANNEL1_TYPE == LM35
159 #elif TEMP_ADC_CHANNEL1_TYPE == NTC
165 #ifdef TEMP_ADC_CHANNEL2
166 adc_raw = temp_buf2.sum / temp_buf2.av_nb_sample;
167 #if TEMP_ADC_CHANNEL2_TYPE == LM35
169 #elif TEMP_ADC_CHANNEL2_TYPE == NTC
175 #ifdef TEMP_ADC_CHANNEL3
176 adc_raw = temp_buf3.sum / temp_buf3.av_nb_sample;
177 #if TEMP_ADC_CHANNEL3_TYPE == LM35
179 #elif TEMP_ADC_CHANNEL3_TYPE == NTC
181 TEMP_ADC_CHANNEL3_A, TEMP_ADC_CHANNEL3_B, TEMP_ADC_CHANNEL3_C);
#define TEMP_ADC_NB_SAMPLES
#define TEMP_ADC_CHANNEL1_PU_R
static float calc_ntc(int16_t raw_adc, uint16_t pull_up_r, float a, float b, float c)
Calculate the NTC tempreature in celcius based on the Steinhart equation.
#define TEMP_ADC_CHANNEL2_B
float get_temp(uint8_t nr)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Periodic telemetry system header (includes downlink utility and generated code).
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
arch independent ADC (Analog to Digital Converter) API
static float calc_lm35(int16_t raw_temp)
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
#define TEMP_ADC_CHANNEL2_PU_R
static void temp_adc_downlink(struct transport_tx *trans, struct link_device *dev)
void temp_adc_periodic(void)
#define DefaultPeriodic
Set default periodic telemetry.
static const struct usb_device_descriptor dev
#define TEMP_ADC_CHANNEL2
#define TEMP_ADC_CHANNEL2_A
Common code for AP and FBW telemetry.
#define TEMP_ADC_CHANNEL1_C
temperature driver for LM35 and 100k NTC analog sensores
#define TEMP_ADC_CHANNEL2_C
void temp_adc_init(void)
Temperature ADC initialize channels.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
#define TEMP_ADC_CHANNEL1_A
#define TEMP_ADC_CHANNEL1
#define TEMP_ADC_CHANNEL1_B
#define TEMP_ADC_SYNC_SEND
Send a TEMP_ADC message with every new measurement.