From 78a17d36ed1766744e0c5fe45540d21748fd1974 Mon Sep 17 00:00:00 2001 From: Paul Goeser Date: Mon, 14 Feb 2011 00:01:57 +0100 Subject: [PATCH 1/2] offset-compensation test (not yet working) --- firmware/slavechip/main.c | 16 ++++++++++++++++ firmware/slavechip/muxer.c | 16 ++++++++++++++++ firmware/slavechip/muxer.h | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/firmware/slavechip/main.c b/firmware/slavechip/main.c index ae317b3..ca905ba 100644 --- a/firmware/slavechip/main.c +++ b/firmware/slavechip/main.c @@ -26,6 +26,8 @@ void baz() { * - multiplexer: * C3: inhibit * C0-C2: muxer select + * - offset measurement + * D0-D3 offset compensation * * * amp 0 is on muxer channel 2 @@ -47,6 +49,7 @@ void hardinit() { spi_init(); muxer_init(); + offset_measure_init(); i2c_init(); @@ -96,6 +99,19 @@ int __attribute__((noreturn)) main(void) { dbgLog("temp: %6li (%li µV, %li mK)\n",temp,nV/1000, mK); } + SOFTTIMER(3,4000){ + static uint8_t toggle; + if(toggle){ + offset_measure_start(0); + toggle=0; + dbgLog("measuring offset\n"); + } else { + offset_measure_stop(); + toggle=1; + dbgLog("stopping offset-measuring\n"); + } + } + } } diff --git a/firmware/slavechip/muxer.c b/firmware/slavechip/muxer.c index 53fecd4..4dbe6f7 100644 --- a/firmware/slavechip/muxer.c +++ b/firmware/slavechip/muxer.c @@ -14,3 +14,19 @@ void muxer_set(uint8_t channel){ //TODO: delays, check everything, mask in register } + +void offset_measure_init(){ + DDRD |= 0x0f; // first 4 pins as output + PORTD = 0x00; // turn everything off +} + +void offset_measure_start(uint8_t channel){ + if(channel >3){ + return; + } + PORTD = (1< Date: Mon, 14 Feb 2011 01:05:50 +0100 Subject: [PATCH 2/2] offset-compensation tested, F_CPU fixed --- firmware/Makefile.inc | 2 +- firmware/masterchip/Makefile | 2 ++ firmware/slavechip/Makefile | 1 + firmware/slavechip/muxer.c | 6 +++--- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 03314b8..3466c3b 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -1,4 +1,4 @@ -DEFINES += -DF_CPU=16000000 +#DEFINES += -DF_CPU=16000000 CFLAGS += -save-temps CFLAGS += -std=gnu99 -Wall # implements C99, for # this removes dead code and does global linker optimization diff --git a/firmware/masterchip/Makefile b/firmware/masterchip/Makefile index 6630a39..f8b9ce8 100644 --- a/firmware/masterchip/Makefile +++ b/firmware/masterchip/Makefile @@ -1,6 +1,8 @@ # masterchip-makefile include ../Makefile.inc +DEFINES += -DF_CPU=16000000 + COMPILE = avr-gcc $(CFLAGS) $(DEFINES) OBJECTS = usbdrv/usbdrvasm.o usbdrv/usbdrv.o main.o display.o lcd/lcd.o usb.o softtimer.o spi.o spi_proto.o spi_pointers.o diff --git a/firmware/slavechip/Makefile b/firmware/slavechip/Makefile index 0e0fe40..0d9d531 100644 --- a/firmware/slavechip/Makefile +++ b/firmware/slavechip/Makefile @@ -1,5 +1,6 @@ include ../Makefile.inc +DEFINES += -DF_CPU=8000000 COMPILE = avr-gcc $(CFLAGS) $(DEFINES) OBJECTS = main.o mcp_adc.o i2c_simple.o softtimer.o spi_proto.o spi.o spi_pointers.o muxer.o debug.o diff --git a/firmware/slavechip/muxer.c b/firmware/slavechip/muxer.c index 4dbe6f7..39c3a3d 100644 --- a/firmware/slavechip/muxer.c +++ b/firmware/slavechip/muxer.c @@ -17,16 +17,16 @@ void muxer_set(uint8_t channel){ void offset_measure_init(){ DDRD |= 0x0f; // first 4 pins as output - PORTD = 0x00; // turn everything off +// PORTD = 0x00; // turn everything off } void offset_measure_start(uint8_t channel){ if(channel >3){ return; } - PORTD = (1<