Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "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 #ifndef DOWNLINK_DEVICE
49 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
50 #endif
51 
55 
58 
59 void temp_tcouple_adc_init( void ) {
66  temp_cnt = 0;
67 }
68 
72 
73  /* no voltage divider, 10 bits adc, 3.3V max */
74  /* T = U * 52.288899706 - 7.977784737996595 */
75  fval[temp_cnt] = ((float)(val[temp_cnt] * 3.3) / 1023.)
76  * 52.288899706 - 7.977784737996595;
77  fref[temp_cnt] = ((float)(ref[temp_cnt] * 3.3) / 1023.)
78  * 100. - 13.;
79 
80  if (++temp_cnt >= TCOUPLE_NB) {
81  DOWNLINK_SEND_TEMP_TCOUPLE(DefaultChannel, DefaultDevice,
82  &fval[0], &fval[1], &fval[2], &fval[3],
83  &fref[0], &fref[1], &fref[2], &fref[3],
84  &val[0], &val[1], &val[2], &val[3],
85  &ref[0], &ref[1], &ref[2], &ref[3]);
86  temp_cnt = 0;
87  }
88 }
89 
unsigned short uint16_t
Definition: types.h:16
#define TCOUPLE_NB
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
float fval[TCOUPLE_NB]
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
static struct adc_buf buf_temp_tcouple_ref
#define ADC_CHANNEL_TEMP_VAL
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
uint16_t ref[TCOUPLE_NB]
#define ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES
uint16_t val[TCOUPLE_NB]
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
static struct adc_buf buf_temp_tcouple_val
#define ADC_CHANNEL_TEMP_REF
signed long int32_t
Definition: types.h:19
void temp_tcouple_adc_init(void)
void temp_tcouple_adc_periodic(void)
float fref[TCOUPLE_NB]
int32_t temp_cnt