Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 
52 
55 
56 void temp_tcouple_adc_init( void ) {
63  temp_cnt = 0;
64 }
65 
69 
70  /* no voltage divider, 10 bits adc, 3.3V max */
71  /* T = U * 52.288899706 - 7.977784737996595 */
72  fval[temp_cnt] = ((float)(val[temp_cnt] * 3.3) / 1023.)
73  * 52.288899706 - 7.977784737996595;
74  fref[temp_cnt] = ((float)(ref[temp_cnt] * 3.3) / 1023.)
75  * 100. - 13.;
76 
77  if (++temp_cnt >= TCOUPLE_NB) {
78  DOWNLINK_SEND_TEMP_TCOUPLE(DefaultChannel, DefaultDevice,
79  &fval[0], &fval[1], &fval[2], &fval[3],
80  &fref[0], &fref[1], &fref[2], &fref[3],
81  &val[0], &val[1], &val[2], &val[3],
82  &ref[0], &ref[1], &ref[2], &ref[3]);
83  temp_cnt = 0;
84  }
85 }
86 
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:57
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
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:53
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