probably fixed a few bugs in calc_temp

master
Paul Goeser 15 years ago
parent a0023a2c5a
commit 4c27482bc7

@ -2,7 +2,8 @@ CFLAGS += -save-temps
CFLAGS += -std=gnu99 -Wall # implements C99, for <util/atomic.h>
# 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

@ -21,5 +21,7 @@ uint8_t softtimer(uint8_t timernum, uint16_t interval);
// SOFTTIMER( <YOUR TIMER NUM>, <YOUR INTERVAL>);
#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

@ -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 */

Loading…
Cancel
Save