summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/ao.h11
-rw-r--r--src/core/ao_convert_volt.c33
-rw-r--r--src/drivers/ao_aprs.c94
-rw-r--r--src/stm/ao_arch.h3
-rw-r--r--src/telemega-v0.1/Makefile1
-rw-r--r--src/telemega-v0.1/ao_pins.h17
-rw-r--r--src/telemega-v1.0/Makefile1
-rw-r--r--src/telemetrum-v2.0/Makefile1
-rw-r--r--src/telemetrum-v2.0/ao_pins.h17
9 files changed, 113 insertions, 65 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index 0b634a79..29ad2603 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -307,6 +307,17 @@ ao_altitude_to_pa(alt_t alt);
#include <ao_serial.h>
#endif
+/*
+ * ao_convert_volt.c
+ *
+ * Convert ADC readings to decivolts
+ */
+
+int16_t
+ao_battery_decivolt(int16_t adc);
+
+int16_t
+ao_ignite_decivolt(int16_t adc);
/*
* ao_spi_slave.c
diff --git a/src/core/ao_convert_volt.c b/src/core/ao_convert_volt.c
new file mode 100644
index 00000000..8556d423
--- /dev/null
+++ b/src/core/ao_convert_volt.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2014 Keith Packard <keithp@keithp.com>
+ *
+ * This program 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; version 2 of the License.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "ao.h"
+
+#define scale(v,p,m) ((int32_t) (v) * (AO_ADC_REFERENCE_DV * ((p) + (m))) / (AO_ADC_MAX * (m)))
+
+int16_t
+ao_battery_decivolt(int16_t adc)
+{
+ return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
+}
+
+int16_t
+ao_ignite_decivolt(int16_t adc)
+{
+ return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
+}
+
diff --git a/src/drivers/ao_aprs.c b/src/drivers/ao_aprs.c
index 96e90f00..56d98437 100644
--- a/src/drivers/ao_aprs.c
+++ b/src/drivers/ao_aprs.c
@@ -488,6 +488,28 @@ static void tncCompressInt(uint8_t *dest, int32_t value, int len) {
}
}
+#if HAS_ADC
+static int tncComment(uint8_t *buf)
+{
+ struct ao_data packet;
+
+ ao_arch_critical(ao_data_get(&packet););
+
+ int16_t battery = ao_battery_decivolt(packet.adc.v_batt);
+ int16_t apogee = ao_ignite_decivolt(AO_SENSE_DROGUE(&packet));
+ int16_t main = ao_ignite_decivolt(AO_SENSE_MAIN(&packet));
+
+ return sprintf((char *) buf,
+ "B:%d.%d A:%d.%d M:%d.%d",
+ battery/10,
+ battery % 10,
+ apogee/10,
+ apogee%10,
+ main/10,
+ main%10);
+}
+#endif
+
/**
* Generate the plain text position packet.
*/
@@ -502,72 +524,8 @@ static int tncPositionPacket(void)
altitude = 0;
altitude = (altitude * (int32_t) 10000 + (3048/2)) / (int32_t) 3048;
-#if 0
- char lat_sign = 'N', lon_sign = 'E';
- uint16_t lat_deg;
- uint16_t lon_deg;
- uint16_t lat_min;
- uint16_t lat_frac;
- uint16_t lon_min;
- uint16_t lon_frac;
-
- if (latitude < 0) {
- lat_sign = 'S';
- latitude = -latitude;
- }
-
- if (longitude < 0) {
- lon_sign = 'W';
- longitude = -longitude;
- }
-
- /* Round latitude and longitude by 0.005 minutes */
- latitude = latitude + 833;
- if (latitude > 900000000)
- latitude = 900000000;
- longitude = longitude + 833;
- if (longitude > 1800000000)
- longitude = 1800000000;
-
- lat_deg = latitude / 10000000;
- latitude -= lat_deg * 10000000;
- latitude *= 60;
- lat_min = latitude / 10000000;
- latitude -= lat_min * 10000000;
- lat_frac = latitude / 100000;
-
- lon_deg = longitude / 10000000;
- longitude -= lon_deg * 10000000;
- longitude *= 60;
- lon_min = longitude / 10000000;
- longitude -= lon_min * 10000000;
- lon_frac = longitude / 100000;
-
-#if 0
- return sprintf ((char *) tncBuffer, "=%02u%02u.%02u%c\\%03u%02u.%02u%cO /A=%06u\015",
- lat_deg, lat_min, lat_frac, lat_sign,
- lon_deg, lon_min, lon_frac, lon_sign,
- altitude);
-#endif
-
- return sprintf ((char *) tncBuffer, "/%02u%02u%02uh%02u%02u.%02u%c/%03u%02u.%02u%c'/A=%06u\015",
- ao_gps_data.hour,
- ao_gps_data.minute,
- ao_gps_data.second,
- lat_deg, lat_min, lat_frac, lat_sign,
- lon_deg, lon_min, lon_frac, lon_sign,
- altitude);
-#endif
buf = tncBuffer;
-#if APRS_TIME
- sprintf ((char *) buf, "/%02u%02u%02uh",
- ao_gps_data.hour,
- ao_gps_data.minute,
- ao_gps_data.second);
- buf += 8;
-#else
*buf++ = '!';
-#endif
/* Symbol table ID */
*buf++ = '/';
@@ -591,7 +549,13 @@ static int tncPositionPacket(void)
buf += 2;
*buf++ = 33 + ((1 << 5) | (2 << 3));
- *buf++ = '\0';
+
+#if HAS_ADC
+ buf += tncComment(buf);
+#else
+ *buf = '\0';
+#endif
+
return buf - tncBuffer;
}
diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h
index 42fe727a..76fa9194 100644
--- a/src/stm/ao_arch.h
+++ b/src/stm/ao_arch.h
@@ -135,6 +135,9 @@ extern const uint32_t ao_radio_cal;
void
ao_adc_init();
+/* ADC maximum reported value */
+#define AO_ADC_MAX 4095
+
#define AO_BOOT_APPLICATION_BASE ((uint32_t *) 0x08001000)
#define AO_BOOT_LOADER_BASE ((uint32_t *) 0x0)
#define HAS_BOOT_LOADER 1
diff --git a/src/telemega-v0.1/Makefile b/src/telemega-v0.1/Makefile
index 35f28b30..28ed7c98 100644
--- a/src/telemega-v0.1/Makefile
+++ b/src/telemega-v0.1/Makefile
@@ -100,6 +100,7 @@ ALTOS_SRC = \
ao_i2c_stm.c \
ao_mpu6000.c \
ao_convert_pa.c \
+ ao_convert_volt.c \
ao_log.c \
ao_log_mega.c \
ao_sample.c \
diff --git a/src/telemega-v0.1/ao_pins.h b/src/telemega-v0.1/ao_pins.h
index daeb9f17..db397c66 100644
--- a/src/telemega-v0.1/ao_pins.h
+++ b/src/telemega-v0.1/ao_pins.h
@@ -250,6 +250,23 @@ struct ao_adc {
#define AO_ADC_SQ9 AO_ADC_TEMP
/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS 56 /* 5.6k */
+#define AO_BATTERY_DIV_MINUS 100 /* 10k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS 100 /* 100k */
+#define AO_IGNITE_DIV_MINUS 27 /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV 33
+
+/*
* Pressure sensor settings
*/
#define HAS_MS5607 1
diff --git a/src/telemega-v1.0/Makefile b/src/telemega-v1.0/Makefile
index b5c1f402..7a0c1195 100644
--- a/src/telemega-v1.0/Makefile
+++ b/src/telemega-v1.0/Makefile
@@ -101,6 +101,7 @@ ALTOS_SRC = \
ao_i2c_stm.c \
ao_mpu6000.c \
ao_convert_pa.c \
+ ao_convert_volt.c \
ao_log.c \
ao_log_mega.c \
ao_sample.c \
diff --git a/src/telemetrum-v2.0/Makefile b/src/telemetrum-v2.0/Makefile
index 0b9e6914..83a364dc 100644
--- a/src/telemetrum-v2.0/Makefile
+++ b/src/telemetrum-v2.0/Makefile
@@ -76,6 +76,7 @@ ALTOS_SRC = \
ao_eeprom_stm.c \
ao_report.c \
ao_convert_pa.c \
+ ao_convert_volt.c \
ao_log.c \
ao_log_metrum.c \
ao_sample.c \
diff --git a/src/telemetrum-v2.0/ao_pins.h b/src/telemetrum-v2.0/ao_pins.h
index 02f0f5e3..1b5cedc7 100644
--- a/src/telemetrum-v2.0/ao_pins.h
+++ b/src/telemetrum-v2.0/ao_pins.h
@@ -190,6 +190,23 @@ struct ao_adc {
#define AO_ADC_SQ4 AO_ADC_TEMP
/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS 56 /* 5.6k */
+#define AO_BATTERY_DIV_MINUS 100 /* 10k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS 100 /* 100k */
+#define AO_IGNITE_DIV_MINUS 27 /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV 33
+
+/*
* GPS
*/