diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 56c4ba1..720d460 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -2,7 +2,8 @@ CFLAGS += -save-temps CFLAGS += -std=gnu99 -Wall # implements C99, for # this removes dead code and does global linker optimization #CFLAGS += -ffunction-sections -Wl,--gc-sections -Wl,--relax -CFLAGS += -Wall -Os -I. -mmcu=atmega88 -lm -ffunction-sections -fdata-sections -Wl,--relax -ffreestanding +CFLAGS += -Wall -Os -I. -mmcu=atmega88 -lm -ffunction-sections -fdata-sections -Wl,--relax +# -ffreestanding # -ffreestanding breaks compile-time eval, which is used to precompute some values (like in _delay_us) # further optimization: #CFLAGS += --param inline-call-cost=2 diff --git a/firmware/shared/softtimer.h b/firmware/shared/softtimer.h index 936eb26..fc57812 100644 --- a/firmware/shared/softtimer.h +++ b/firmware/shared/softtimer.h @@ -21,5 +21,7 @@ uint8_t softtimer(uint8_t timernum, uint16_t interval); // SOFTTIMER( , ); #define SOFTTIMER(n,a) if(softtimer((n),(a*4))) +//TODO: use a static uint16 in the #define to store softtimer_last, and pass +//it by reference to softtimer(). That way SOFTTIMERNUMS is unnecessary #endif diff --git a/firmware/slavechip/main.c b/firmware/slavechip/main.c index f0fe4da..b5106ff 100644 --- a/firmware/slavechip/main.c +++ b/firmware/slavechip/main.c @@ -42,7 +42,7 @@ int32_t avg_temp(int16_t val, uint8_t channel) { uint16_t calc_temp(int16_t val, uint8_t channel) { float mV = ((float) avg_temp(val, channel))/1000000; - uint16_t temp; + uint16_t temp = 0; if(mV < 0) { /* t in mV E = sum(i=0 to n) c_i t^i. ; n=10 @@ -61,9 +61,8 @@ uint16_t calc_temp(int16_t val, uint8_t channel) { -0.163226974860E-22 }; for(int i=0; i<11; i++) { - temp += coef[i] * pow(mV, i+1); + temp += coef[i] * pow(mV, i); } - return temp; } else { /* t in mV @@ -83,10 +82,13 @@ uint16_t calc_temp(int16_t val, uint8_t channel) { }; float a[] = {0.118597600000E+00, -0.118343200000E-03, 0.126968600000E+03}; for(int i=0; i<10; i++) { - temp += coef[i]*pow(mV, i+1) + a[0] * pow(exp(a[1]*(mV - a[2])), 2); + temp += coef[i]*pow(mV, i) } + // ich glaube das summenzeichen erstreckt sich nicht auf das exp + temp += a[0] * pow(exp(a[1]*(mV - a[2])), 2); } + return temp; } /* initializes the hardware */