From 24948ea1d41f2a7c96ac09e35d1250909e5726ae Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 14:32:35 -0800 Subject: altos: Store altitude in 32-bits for MicroPeak Needs all 32 bits to store .1 meter resolution Signed-off-by: Keith Packard --- src/micropeak/ao_pins.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/micropeak/ao_pins.h b/src/micropeak/ao_pins.h index 257b8694..187b2544 100644 --- a/src/micropeak/ao_pins.h +++ b/src/micropeak/ao_pins.h @@ -57,6 +57,7 @@ #define I2C_PIN_SDA PINB0 #define AO_CONST_ATTRIB PROGMEM +typedef int32_t alt_t; #define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o])) #define AO_ALT_VALUE(x) ((x) * 10) -- cgit v1.2.3 From defd5d0784a754be30e3295067fbc85a108ad172 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 18:27:49 -0800 Subject: altos: Make sure pa to altitude conversion is done with 32 bits We need 32 bits to hold intermediate values, even if the final altitude is reported in only 16 bits. Signed-off-by: Keith Packard --- src/core/ao_convert_pa.c | 8 ++++---- src/micropeak/ao_pins.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c index 55fe6e7d..fe6e0ef6 100644 --- a/src/core/ao_convert_pa.c +++ b/src/core/ao_convert_pa.c @@ -43,13 +43,13 @@ ao_pa_to_altitude(int32_t pa) if (pa < 0) pa = 0; - if (pa > 120000) - pa = 120000; + if (pa > 120000L) + pa = 120000L; o = pa >> ALT_SHIFT; part = pa & ALT_MASK; - low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part); - high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1); + low = (int32_t) FETCH_ALT(o) * (ALT_SCALE - part); + high = (int32_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1); return (low + high) >> ALT_SHIFT; } diff --git a/src/micropeak/ao_pins.h b/src/micropeak/ao_pins.h index 187b2544..63e9cb1b 100644 --- a/src/micropeak/ao_pins.h +++ b/src/micropeak/ao_pins.h @@ -60,6 +60,6 @@ typedef int32_t alt_t; #define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o])) -#define AO_ALT_VALUE(x) ((x) * 10) +#define AO_ALT_VALUE(x) ((x) * (alt_t) 10) #endif /* _AO_PINS_H_ */ -- cgit v1.2.3 From c233ef67f42c14cb1d0e0542a9523b279f826af5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 18:28:33 -0800 Subject: altos: Use alt_t value to hold displayed height in micropeak Heights are 32 bits (to get .1 meter resolution) in micropeak; make sure we have enough bits while blinking out the computed value. Signed-off-by: Keith Packard --- src/micropeak/ao_report_tiny.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/micropeak/ao_report_tiny.c b/src/micropeak/ao_report_tiny.c index 109af1ed..bdcc131e 100644 --- a/src/micropeak/ao_report_tiny.c +++ b/src/micropeak/ao_report_tiny.c @@ -38,8 +38,8 @@ ao_report_digit(uint8_t digit) __reentrant void ao_report_altitude(void) { - __pdata int16_t agl = ao_max_height; - __xdata uint8_t digits[10]; + __pdata alt_t agl = ao_max_height; + static __xdata uint8_t digits[11]; __pdata uint8_t ndigits, i; if (agl < 0) -- cgit v1.2.3 From d309fcff54fe6904fb860f33c15fcb7d1c96e91b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Dec 2012 14:41:53 -0800 Subject: altos: Increase MicroPeak blink times a bit make the 0 longer (1 sec now), and make the time between digits longer (also 1 sec now) Signed-off-by: Keith Packard --- src/micropeak/ao_report_tiny.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/micropeak/ao_report_tiny.c b/src/micropeak/ao_report_tiny.c index bdcc131e..0e8e287f 100644 --- a/src/micropeak/ao_report_tiny.c +++ b/src/micropeak/ao_report_tiny.c @@ -24,7 +24,7 @@ static void ao_report_digit(uint8_t digit) __reentrant { if (!digit) { - mid(AO_MS_TO_TICKS(600)); + mid(AO_MS_TO_TICKS(1000)); pause(AO_MS_TO_TICKS(300)); } else { while (digit--) { @@ -32,7 +32,7 @@ ao_report_digit(uint8_t digit) __reentrant pause(AO_MS_TO_TICKS(300)); } } - pause(AO_MS_TO_TICKS(600)); + pause(AO_MS_TO_TICKS(1000)); } void -- cgit v1.2.3 From 69447d8ad3f5a1e1f59939477afc7720a437fadc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 11 Dec 2012 23:43:30 -0800 Subject: altos: Tim Van Milligan suggestion for µP -- delay before showing last flight MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gives the user time to move their finger out of the way of the LED. Signed-off-by: Keith Packard --- src/micropeak/ao_micropeak.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c index 10e1d0f9..8ae26ec1 100644 --- a/src/micropeak/ao_micropeak.c +++ b/src/micropeak/ao_micropeak.c @@ -110,6 +110,8 @@ main(void) #endif ao_restore_flight(); ao_compute_height(); + /* Give the person a second to get their finger out of the way */ + ao_delay(AO_MS_TO_TICKS(1000)); ao_report_altitude(); ao_spi_init(); -- cgit v1.2.3 From 07a45c50429389ae7b51e12bc847d34fb1577bc6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 12 Dec 2012 10:57:03 -0800 Subject: altos: Add load-slow target for MicroPeak This sets the programming clock to 1/4 of the 250kHz clock used by the MicroPeak firmware, allowing the device to be reprogrammed. Signed-off-by: Keith Packard --- src/micropeak/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/micropeak/Makefile b/src/micropeak/Makefile index 8cf608bb..0c48ed66 100644 --- a/src/micropeak/Makefile +++ b/src/micropeak/Makefile @@ -11,6 +11,7 @@ DUDECPUTYPE=t85 #PROGRAMMER=stk500v2 -P usb PROGRAMMER=usbtiny LOADCMD=avrdude +LOADSLOW=-i 32 -B 32 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w: CC=avr-gcc OBJCOPY=avr-objcopy @@ -86,6 +87,9 @@ $(PROG).hex: $(PROG) load: $(PROG).hex $(LOADCMD) $(LOADARG)$(PROG).hex +load-slow: $(PROG).hex + $(LOADCMD) $(LOADSLOW) $(LOADARG)$(PROG).hex + ao_product.h: ao-make-product.5c ../Version $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ -- cgit v1.2.3 From a4678cd848da994dc893b75790e4c9a86e54d895 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 12 Dec 2012 11:01:48 -0800 Subject: altos: Log in-flight data for MicroPeak This logs the low 16 bits of the pressure value to the remaining on-chip eeprom. It can be read out with a standard AVR programming dongle. Signed-off-by: Keith Packard --- src/micropeak/ao_micropeak.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c index 8ae26ec1..525cfa42 100644 --- a/src/micropeak/ao_micropeak.c +++ b/src/micropeak/ao_micropeak.c @@ -65,18 +65,40 @@ ao_compute_height(void) } #if !HAS_EEPROM + +#define PA_GROUND_OFFSET 0 +#define PA_MIN_OFFSET 4 +#define N_SAMPLES_OFFSET 8 +#define STARTING_LOG_OFFSET 10 +#define MAX_LOG_OFFSET 512 + +static uint16_t ao_log_offset = STARTING_LOG_OFFSET; + void ao_save_flight(void) { - ao_eeprom_write(0, &pa_ground, sizeof (pa_ground)); - ao_eeprom_write(sizeof (pa_ground), &pa_min, sizeof (pa_min)); + uint16_t n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t); + ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground)); + ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min)); + ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples)); } void ao_restore_flight(void) { - ao_eeprom_read(0, &pa_ground, sizeof (pa_ground)); - ao_eeprom_read(sizeof (pa_ground), &pa_min, sizeof (pa_min)); + ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground)); + ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min)); +} + +void +ao_log_micro(void) +{ + uint16_t low_bits = pa; + + if (ao_log_offset < MAX_LOG_OFFSET) { + ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits)); + ao_log_offset += sizeof (low_bits); + } } #endif @@ -180,6 +202,9 @@ main(void) ao_led_off(AO_LED_REPORT); #if HAS_EEPROM ao_log_micro_data(AO_LOG_MICRO_DATA | pa); +#else + if (sample_count & 1) + ao_log_micro(); #endif pa_avg = pa_avg - (pa_avg >> FILTER_SHIFT) + pa; if (pa_avg < pa_min) -- cgit v1.2.3 From c8866fbae2b00b1d7a7ddf89a3f971a75d3dcd60 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 12 Dec 2012 22:35:05 -0800 Subject: doc: Update MicroPeak doc to include EEPROM and programming info Signed-off-by: Keith Packard --- doc/micropeak.xsl | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/doc/micropeak.xsl b/doc/micropeak.xsl index 284d0fb0..91126ce5 100644 --- a/doc/micropeak.xsl +++ b/doc/micropeak.xsl @@ -37,6 +37,13 @@ Updates for version 1.0 release. + + 1.1 + 12 December 2012 + + Add comments about EEPROM storage format and programming jig. + + @@ -272,6 +279,118 @@ NAR #88757, TRA #12200 serve to further protect the switch from launch forces. +
+ On-board data storage + + The ATtiny85 has 512 bytes of non-volatile storage, separate + from the code storage memory. The MicroPeak firmware uses this + to store information about the last completed + flight. Barometric measurements from the ground before launch + and at apogee are stored, and used at power-on to compute the + height of the last flight. + + + In addition to the data used to present the height of the last + flight, MicroPeak also stores barometric information sampled + at regular intervals during the flight. This information can + be extracted from MicroPeak through any AVR programming + tool. + + + MicroPeak EEPROM Data Storage + + + + + + + Address + Size (bytes) + Description + + + + + 0x000 + 4 + Average ground pressure (Pa) + + + 0x004 + 4 + Minimum flight pressure (Pa) + + + 0x008 + 2 + Number of in-flight samples + + + 0x00a … 0x1fe + 2 + Instantaneous flight pressure (Pa) low 16 bits + + + +
+ + All EEPROM data are stored least-significant byte first. The + instantaneous flight pressure data are stored without the + upper 16 bits of data. The upper bits can be reconstructed + from the previous sample, assuming that pressure doesn't + change by more more than 32kPa in a single sample + interval. Note that this pressure data is not + filtered in any way, while both the recorded ground and apogee + pressure values are, so you shouldn't expect the minimum + instantaneous pressure value to match the recorded minimum + pressure value exactly. + + + MicroPeak samples pressure every 96ms, but stores only every + other sample in the EEPROM. This provides for 251 pressure + samples at 192ms intervals, or 48.192s of storage. The clock + used for these samples is a factory calibrated RC circuit + built into the ATtiny85 and is accurate only to within ±10% at + 25°C. So, you can count on the pressure data being accurate, + but speed or acceleration data computed from this will be + limited by the accuracy of this clock. + +
+
+ MicroPeak Programming Interface + + MicroPeak exposes a standard 6-pin AVR programming interface, + but not using the usual 2x3 array of pins on 0.1" + centers. Instead, there is a single row of tiny 0.60mm × + 0.85mm pads on 1.20mm centers exposed near the edge of the + circuit board. We couldn't find any connector that was + small enough to include on the circuit board. + + + In lieu of an actual connector, the easiest way to connect to + the bare pads is through a set of Pogo pins. These + spring-loaded contacts are designed to connect in precisely + this way. We've designed a programming jig, the MicroPeak + Pogo Pin board which provides a standard AVR interface on one + end and a recessed slot for MicroPeak to align the board with + the Pogo Pins. + + + The MicroPeak Pogo Pin board is not a complete AVR programmer, + it is an interface board that provides a 3.3V regulated power + supply to run the MicroPeak via USB and a standard 6-pin AVR + programming interface with the usual 2x3 grid of pins on 0.1" + centers. This can be connected to any AVR programming + dongle. + + + The AVR programming interface cannot run faster than ¼ of the + AVR CPU clock frequency. Because MicroPeak runs at 250kHz to + save power, you must configure your AVR programming system to + clock the AVR programming interface at no faster than + 62.5kHz, or a clock period of 32µS. + +