Skip to content

Commit

Permalink
Add Universitaet Tuebingen thermocouple sensor.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmm committed Jul 22, 2011
1 parent 813eee7 commit e8249cd
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
19 changes: 18 additions & 1 deletion conf/messages.xml
Expand Up @@ -859,7 +859,24 @@
<field name="speed_sp" type="float"/>
</message>

<!--126 is free -->
<message name="TEMP_TCOUPLE" id="126">
<field name="fval0" type="float"/>
<field name="fval1" type="float"/>
<field name="fval2" type="float"/>
<field name="fval3" type="float"/>
<field name="fref0" type="float"/>
<field name="fref1" type="float"/>
<field name="fref2" type="float"/>
<field name="fref3" type="float"/>
<field name="val0" type="uint16"/>
<field name="val1" type="uint16"/>
<field name="val2" type="uint16"/>
<field name="val3" type="uint16"/>
<field name="ref0" type="uint16"/>
<field name="ref1" type="uint16"/>
<field name="ref2" type="uint16"/>
<field name="ref3" type="uint16"/>
</message>

<message name="SHT_I2C_STATUS" id="127">
<field name="ihumid" type="uint16"/>
Expand Down
17 changes: 17 additions & 0 deletions conf/modules/temp_tcouple_adc.xml
@@ -0,0 +1,17 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="temp_tcouple_adc" dir="meteo">
<header>
<file name="temp_tcouple_adc.h"/>
</header>
<init fun="temp_tcouple_adc_init()"/>
<periodic fun="temp_tcouple_adc_periodic()" freq="60"/>
<makefile target="ap">
<file name="temp_tcouple_adc.c"/>
<define name="ADC_CHANNEL_TEMP_REF" value="ADC_4"/>
<define name="USE_ADC_4"/>
<define name="ADC_CHANNEL_TEMP_VAL" value="ADC_3"/>
<define name="USE_ADC_3"/>
</makefile>
</module>

91 changes: 91 additions & 0 deletions 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;
}
}

14 changes: 14 additions & 0 deletions 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

0 comments on commit e8249cd

Please sign in to comment.