From df54ababd77bd3cc925f176e9c615fe97f96ce09 Mon Sep 17 00:00:00 2001 From: Martin Mueller Date: Fri, 22 Jul 2011 17:13:15 +0200 Subject: [PATCH] Add University of Reading solar radiation sensor. --- conf/messages.xml | 23 ++++++- conf/modules/light_solar.xml | 17 ++++++ sw/airborne/modules/meteo/light_solar.c | 80 +++++++++++++++++++++++++ sw/airborne/modules/meteo/light_solar.h | 14 +++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 conf/modules/light_solar.xml create mode 100644 sw/airborne/modules/meteo/light_solar.c create mode 100644 sw/airborne/modules/meteo/light_solar.h diff --git a/conf/messages.xml b/conf/messages.xml index 5fee9d9122..d09933be9f 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -800,7 +800,28 @@ - + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/modules/light_solar.xml b/conf/modules/light_solar.xml new file mode 100644 index 0000000000..7cf08e80b9 --- /dev/null +++ b/conf/modules/light_solar.xml @@ -0,0 +1,17 @@ + + + +
+ +
+ + + + + + + + + +
+ diff --git a/sw/airborne/modules/meteo/light_solar.c b/sw/airborne/modules/meteo/light_solar.c new file mode 100644 index 0000000000..38b20450a0 --- /dev/null +++ b/sw/airborne/modules/meteo/light_solar.c @@ -0,0 +1,80 @@ +/* + * $Id: light_solar.c $ + * + * Copyright (C) 2011 Martin Mueller + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/** \file light_solar.c + * \brief University of Reading solar radiation sensor interface + * + * This reads the values for intensity from the University of Reading solar sensor. + */ + + +#include "mcu_periph/adc.h" +#include "mcu_periph/uart.h" +#include "messages.h" +#include "downlink.h" +#include "modules/meteo/light_solar.h" + +#ifndef ADC_CHANNEL_LIGHT_SOLAR_UP +#define ADC_CHANNEL_LIGHT_SOLAR_UP ADC_1 +#endif +#ifndef ADC_CHANNEL_LIGHT_SOLAR_DN +#define ADC_CHANNEL_LIGHT_SOLAR_DN ADC_2 +#endif + +#ifndef ADC_CHANNEL_LIGHT_NB_SAMPLES +#define ADC_CHANNEL_LIGHT_NB_SAMPLES 16 +#endif + +#ifndef DOWNLINK_DEVICE +#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE +#endif + +uint16_t up[LIGHT_NB], dn[LIGHT_NB]; +int32_t light_cnt; + +static struct adc_buf buf_light_sol_up; +static struct adc_buf buf_light_sol_dn; + +void light_solar_init( void ) { + adc_buf_channel(ADC_CHANNEL_LIGHT_SOLAR_UP, &buf_light_sol_up, ADC_CHANNEL_LIGHT_NB_SAMPLES); + adc_buf_channel(ADC_CHANNEL_LIGHT_SOLAR_DN, &buf_light_sol_dn, ADC_CHANNEL_LIGHT_NB_SAMPLES); + + light_cnt = 0; +} + +void light_solar_periodic( void ) { + up[light_cnt] = buf_light_sol_up.sum / buf_light_sol_up.av_nb_sample; + dn[light_cnt] = buf_light_sol_dn.sum / buf_light_sol_dn.av_nb_sample; + + /* 10k/10k voltage divider, 10 bits adc, 3.3V max */ + + if (++light_cnt >= LIGHT_NB) { + DOWNLINK_SEND_SOLAR_RADIATION(DefaultChannel, + &up[0], &dn[0], &up[1], &dn[1], &up[2], &dn[2], &up[3], &dn[3], + &up[4], &dn[4], &up[5], &dn[5], &up[6], &dn[6], &up[7], &dn[7], + &up[8], &dn[8], &up[9], &dn[9]); + light_cnt = 0; + } +} + diff --git a/sw/airborne/modules/meteo/light_solar.h b/sw/airborne/modules/meteo/light_solar.h new file mode 100644 index 0000000000..7fbcb1bd01 --- /dev/null +++ b/sw/airborne/modules/meteo/light_solar.h @@ -0,0 +1,14 @@ +#ifndef TEMP_SOLAR_H +#define TEMP_SOLAR_H + +#include "std.h" + +#define LIGHT_NB 10 + +extern uint16_t up[LIGHT_NB], dn[LIGHT_NB]; +extern int32_t light_cnt; + +void light_solar_init(void); +void light_solar_periodic(void); + +#endif