Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
temp_tcouple_adc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Martin Mueller
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
31 #include "mcu_periph/adc.h"
32 #include "mcu_periph/uart.h"
33 #include "pprzlink/messages.h"
36 
37 #ifndef ADC_CHANNEL_TEMP_REF
38 #define ADC_CHANNEL_TEMP_REF ADC_4
39 #endif
40 #ifndef ADC_CHANNEL_TEMP_VAL
41 #define ADC_CHANNEL_TEMP_VAL ADC_3
42 #endif
43 
44 #ifndef ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES
45 #define ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES 16
46 #endif
47 
48 
52 
53 static struct adc_buf buf_temp_tcouple_ref;
54 static struct adc_buf buf_temp_tcouple_val;
55 
57 {
64  temp_cnt = 0;
65 }
66 
68 {
71 
72  /* no voltage divider, 10 bits adc, 3.3V max */
73  /* T = U * 52.288899706 - 7.977784737996595 */
74  fval[temp_cnt] = ((float)(val[temp_cnt] * 3.3) / 1023.)
75  * 52.288899706 - 7.977784737996595;
76  fref[temp_cnt] = ((float)(ref[temp_cnt] * 3.3) / 1023.)
77  * 100. - 13.;
78 
79  if (++temp_cnt >= TCOUPLE_NB) {
80  DOWNLINK_SEND_TEMP_TCOUPLE(DefaultChannel, DefaultDevice,
81  &fval[0], &fval[1], &fval[2], &fval[3],
82  &fref[0], &fref[1], &fref[2], &fref[3],
83  &val[0], &val[1], &val[2], &val[3],
84  &ref[0], &ref[1], &ref[2], &ref[3]);
85  temp_cnt = 0;
86  }
87 }
88 
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
uint8_t av_nb_sample
Definition: adc.h:57
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
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.
Definition: adc_arch.c:312
float fval[TCOUPLE_NB]
int32_t temp_cnt
uint16_t ref[TCOUPLE_NB]
static struct adc_buf buf_temp_tcouple_val
uint16_t val[TCOUPLE_NB]
void temp_tcouple_adc_periodic(void)
static struct adc_buf buf_temp_tcouple_ref
#define ADC_CHANNEL_TEMP_REF
float fref[TCOUPLE_NB]
#define ADC_CHANNEL_TEMP_VAL
#define ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES
void temp_tcouple_adc_init(void)
#define TCOUPLE_NB
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83