Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
humid_hih.c
Go to the documentation of this file.
1 /*
2  * $Id: humid_hih.c $
3  *
4  * Copyright (C) 2010 Martin Mueller
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
31 #include <std.h>
36 #include "mcu_periph/adc.h"
37 #include "mcu_periph/uart.h"
38 #include "messages.h"
40 
41 #ifndef DOWNLINK_DEVICE
42 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
43 #endif
44 
45 #ifndef ADC_CHANNEL_HUMID_HIH
46 #define ADC_CHANNEL_HUMID_HIH ADC_3
47 #endif
48 
49 #ifndef ADC_CHANNEL_HUMID_NB_SAMPLES
50 #define ADC_CHANNEL_HUMID_NB_SAMPLES 16
51 #endif
52 
54 float fhih_humid;
55 
56 static struct adc_buf buf_humid_hih;
57 
58 void humid_hih_init( void ) {
60 }
61 
62 void humid_hih_periodic( void ) {
63  float fvout, fhih_temp;
64 
65  /* get temperature from external source */
66  fhih_temp = ftempsht;
67  /****************************************/
68 
70 
71  /* 36k/68k voltage divider, 3.3V full sweep, 10 bits adc */
72  fvout = (adc_humid_hih / 1024.) * 3.3 * (104./68.);
73 
74  /* 5V supply, 1st order curve fit */
75  fhih_humid = ((fvout / 5.0)-0.16)/0.0062;
76 
77  /* temperature compensation */
78  fhih_humid = fhih_humid/(1.0546 - (0.00216 * fhih_temp));
79 
80  DOWNLINK_SEND_HIH_STATUS(DefaultChannel, DefaultDevice, &adc_humid_hih, &fhih_humid, &fhih_temp);
81 }
82 
unsigned short uint16_t
Definition: types.h:16
static struct adc_buf buf_humid_hih
Definition: humid_hih.c:56
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t adc_humid_hih
Definition: humid_hih.c:53
void humid_hih_init(void)
Definition: humid_hih.c:58
#define ADC_CHANNEL_HUMID_NB_SAMPLES
Definition: humid_hih.c:50
uint8_t av_nb_sample
Definition: adc.h:64
#define ADC_CHANNEL_HUMID_HIH
Definition: humid_hih.c:46
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
void humid_hih_periodic(void)
Definition: humid_hih.c:62
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
void adc_buf_channel(uint8_t adc_channel __attribute__((unused)), struct adc_buf *s __attribute__((unused)), uint8_t av_nb_sample __attribute__((unused)))
Required by infrared.c:ir_init()
Definition: jsbsim_ir.c:35
float fhih_humid
Definition: humid_hih.c:54
float ftempsht
Definition: humid_sht.c:23