PaxInstruments / t400-firmware

Firmware for the Pax Instruments T400 temperature datalogger
22 stars 5 forks source link

Minimize floating point operations #212

Open charlespax opened 8 years ago

charlespax commented 8 years ago

There are many bast ten floating point operations. If possible, let's make things base 16 and use bit shift math. This should save a bunch of flash space since the floating point library is pretty big.

protological commented 8 years ago

I've looked at the t400 code and I think the floating point operations can be replaced with int16 values. The int16 would have a range of -35535 to 35535, if the values were stored as base 10 with a resolution of 1/10th degree the supported range would be -3553.5C to 3553.5C. The base 10 division and modulo operations would be must faster and take less code space than the floating point.

protological commented 8 years ago

I think I need some more information on the temperature vs microvolt lookup in the code. I see the following functions, where did they come from? If we can eliminate some of these floating point operations the code will be smaller and faster

From GetJunctionVoltage(): i = jTemp/10 + 27; jVoltage = valueLow - TK_OFFSET + (jTemp - (i*10-270)) * (valueHigh - valueLow)/10;

From GetTypKTemp(): LookedupValue = ((float)-270 + (i)*10) + ((10 *(float)(microVolts - valueLow)) / ((float)(valueHigh - valueLow)));

charlespax commented 8 years ago

@protological Can this be closed now that https://github.com/PaxInstruments/t400-firmware/pull/220 is merged?

protological commented 8 years ago

Not all the float operations have been removed. The mentioned algorithms use floating point values. Maybe we need to keep some floats

protological commented 8 years ago

I've managed to reduce the floating point math quite a bit, however there are still a few hold outs

t400.ino void readTemperatures(): lines 271-284

functions.c int32_t celcius_to_microvolts(float celcius): Argument is float and then converted to uint8_t int16_t microvolts_to_celcius(int32_t microVolts): line 517, 525

If we can get some details on the math in these functions I might be able to translate them to integer math operations