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(+) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(+) (limited to 'src') 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(+) (limited to 'src') 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(-) (limited to 'src') 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