aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-03-17 16:53:30 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-03-17 16:53:30 +0100
commitfd8cae19bdb4ba5e97c810f266f78af1461b51b7 (patch)
tree88b869aa15af8d2709d3eef05661e82c5c079f25
parent7be1c400f99b4cc3df7ee7cc738d88f85e58cb48 (diff)
downloadpx4-firmware-fd8cae19bdb4ba5e97c810f266f78af1461b51b7.tar.gz
px4-firmware-fd8cae19bdb4ba5e97c810f266f78af1461b51b7.tar.bz2
px4-firmware-fd8cae19bdb4ba5e97c810f266f78af1461b51b7.zip
ADC channel mapping fix in sensors app
-rw-r--r--src/modules/sensors/sensors.cpp11
-rw-r--r--src/modules/uORB/topics/sensor_combined.h3
2 files changed, 9 insertions, 5 deletions
diff --git a/src/modules/sensors/sensors.cpp b/src/modules/sensors/sensors.cpp
index b176d7417..6560dec3d 100644
--- a/src/modules/sensors/sensors.cpp
+++ b/src/modules/sensors/sensors.cpp
@@ -1169,16 +1169,19 @@ Sensors::adc_poll(struct sensor_combined_s &raw)
hrt_abstime t = hrt_absolute_time();
/* rate limit to 100 Hz */
if (t - _last_adc >= 10000) {
- /* make space for a maximum of eight channels */
- struct adc_msg_s buf_adc[8];
+ /* make space for a maximum of ten channels (to ensure reading all channels at once) */
+ struct adc_msg_s buf_adc[10];
/* read all channels available */
int ret = read(_fd_adc, &buf_adc, sizeof(buf_adc));
if (ret >= (int)sizeof(buf_adc[0])) {
- for (unsigned i = 0; i < sizeof(buf_adc) / sizeof(buf_adc[0]); i++) {
+
+ /* Read add channels we got */
+ for (unsigned i = 0; i < ret / sizeof(buf_adc[0]); i++) {
/* Save raw voltage values */
- if (i < (sizeof(raw.adc_voltage_v)) / sizeof(raw.adc_voltage_v[0])) {
+ if (i < (sizeof(raw.adc_voltage_v) / sizeof(raw.adc_voltage_v[0]))) {
raw.adc_voltage_v[i] = buf_adc[i].am_data / (4096.0f / 3.3f);
+ raw.adc_mapping[i] = buf_adc[i].am_channel;
}
/* look for specific channels and process the raw voltage to measurement data */
diff --git a/src/modules/uORB/topics/sensor_combined.h b/src/modules/uORB/topics/sensor_combined.h
index ad164555e..918389f38 100644
--- a/src/modules/uORB/topics/sensor_combined.h
+++ b/src/modules/uORB/topics/sensor_combined.h
@@ -99,7 +99,8 @@ struct sensor_combined_s {
float baro_pres_mbar; /**< Barometric pressure, already temp. comp. */
float baro_alt_meter; /**< Altitude, already temp. comp. */
float baro_temp_celcius; /**< Temperature in degrees celsius */
- float adc_voltage_v[4]; /**< ADC voltages of ADC Chan 10/11/12/13 or -1 */
+ float adc_voltage_v[9]; /**< ADC voltages of ADC Chan 10/11/12/13 or -1 */
+ unsigned adc_mapping[9]; /**< Channel indices of each of these values */
float mcu_temp_celcius; /**< Internal temperature measurement of MCU */
uint32_t baro_counter; /**< Number of raw baro measurements taken */