diff --git a/conf/messages.xml b/conf/messages.xml index 0542da3bebc..ed2349cd764 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -859,7 +859,24 @@ - + + + + + + + + + + + + + + + + + + diff --git a/conf/modules/temp_tcouple_adc.xml b/conf/modules/temp_tcouple_adc.xml new file mode 100644 index 00000000000..0b443013189 --- /dev/null +++ b/conf/modules/temp_tcouple_adc.xml @@ -0,0 +1,17 @@ + + + +
+ +
+ + + + + + + + + +
+ diff --git a/sw/airborne/modules/meteo/temp_tcouple_adc.c b/sw/airborne/modules/meteo/temp_tcouple_adc.c new file mode 100644 index 00000000000..048f8ea8263 --- /dev/null +++ b/sw/airborne/modules/meteo/temp_tcouple_adc.c @@ -0,0 +1,91 @@ +/* + * $Id: temp_tcouple_adc.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 temp_tcouple_adc.c + * \brief Universitaet Tuebingen thermocouple interface + * + * This reads the values for reference and measurement temperature + * from the Universitaet Tuebingen thermocouple sensor. + */ + + +#include "mcu_periph/adc.h" +#include "mcu_periph/uart.h" +#include "messages.h" +#include "downlink.h" +#include "modules/meteo/temp_tcouple_adc.h" + +#ifndef ADC_CHANNEL_TEMP_REF +#define ADC_CHANNEL_TEMP_REF ADC_4 +#endif +#ifndef ADC_CHANNEL_TEMP_VAL +#define ADC_CHANNEL_TEMP_VAL ADC_3 +#endif + +#ifndef ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES +#define ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES 16 +#endif + +#ifndef DOWNLINK_DEVICE +#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE +#endif + +uint16_t ref[TCOUPLE_NB], val[TCOUPLE_NB]; +float fref[TCOUPLE_NB], fval[TCOUPLE_NB]; +int32_t temp_cnt; + +static struct adc_buf buf_temp_tcouple_ref; +static struct adc_buf buf_temp_tcouple_val; + +void temp_tcouple_adc_init( void ) { + adc_buf_channel(ADC_CHANNEL_TEMP_REF, + &buf_temp_tcouple_ref, + ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES); + adc_buf_channel(ADC_CHANNEL_TEMP_VAL, + &buf_temp_tcouple_val, + ADC_CHANNEL_TEMP_TCOUPLE_NB_SAMPLES); + temp_cnt = 0; +} + +void temp_tcouple_adc_periodic( void ) { + val[temp_cnt] = buf_temp_tcouple_val.sum / buf_temp_tcouple_val.av_nb_sample; + ref[temp_cnt] = buf_temp_tcouple_ref.sum / buf_temp_tcouple_ref.av_nb_sample; + + /* no voltage divider, 10 bits adc, 3.3V max */ + /* T = U * 52.288899706 - 7.977784737996595 */ + fval[temp_cnt] = ((float)(val[temp_cnt] * 3.3) / 1023.) + * 52.288899706 - 7.977784737996595; + fref[temp_cnt] = ((float)(ref[temp_cnt] * 3.3) / 1023.) + * 100. - 13.; + + if (++temp_cnt >= TCOUPLE_NB) { + DOWNLINK_SEND_TEMP_TCOUPLE(DefaultChannel, + &fval[0], &fval[1], &fval[2], &fval[3], + &fref[0], &fref[1], &fref[2], &fref[3], + &val[0], &val[1], &val[2], &val[3], + &ref[0], &ref[1], &ref[2], &ref[3]); + temp_cnt = 0; + } +} + diff --git a/sw/airborne/modules/meteo/temp_tcouple_adc.h b/sw/airborne/modules/meteo/temp_tcouple_adc.h new file mode 100644 index 00000000000..b3636542e4e --- /dev/null +++ b/sw/airborne/modules/meteo/temp_tcouple_adc.h @@ -0,0 +1,14 @@ +#ifndef TEMP_TCOUPLE_ADC_H +#define TEMP_TCOUPLE_ADC_H + +#include "std.h" + +#define TCOUPLE_NB 4 + +extern uint16_t up[TCOUPLE_NB], dn[TCOUPLE_NB]; +extern int32_t tcouple_cnt; + +void temp_tcouple_adc_init(void); +void temp_tcouple_adc_periodic(void); + +#endif