mirror of https://github.com/arendst/Tasmota.git
Save 1k code space by using TaylorSeries log function
Save 1k code space by using TaylorSeries log function
This commit is contained in:
parent
5515a97be6
commit
052cfbc11d
|
@ -680,6 +680,24 @@ float FastPrecisePowf(const float x, const float y)
|
||||||
return (float)FastPrecisePow(x, y);
|
return (float)FastPrecisePow(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double TaylorLog(double x)
|
||||||
|
{
|
||||||
|
// https://stackoverflow.com/questions/46879166/finding-the-natural-logarithm-of-a-number-using-taylor-series-in-c
|
||||||
|
|
||||||
|
double z = (x + 1) / (x - 1); // We start from power -1, to make sure we get the right power in each iteration;
|
||||||
|
double step = ((x - 1) * (x - 1)) / ((x + 1) * (x + 1)); // Store step to not have to calculate it each time
|
||||||
|
double totalValue = 0;
|
||||||
|
double powe = 1;
|
||||||
|
double y;
|
||||||
|
for (int count = 0; count < 10; count++) {
|
||||||
|
z *= step;
|
||||||
|
y = (1 / powe) * z;
|
||||||
|
totalValue = totalValue + y;
|
||||||
|
powe = powe + 2;
|
||||||
|
}
|
||||||
|
return 2 * totalValue;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t SqrtInt(uint32_t num)
|
uint32_t SqrtInt(uint32_t num)
|
||||||
{
|
{
|
||||||
if (num <= 1) {
|
if (num <= 1) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ void AdcEverySecond(void)
|
||||||
int adc = AdcRead(2);
|
int adc = AdcRead(2);
|
||||||
// Steinhart-Hart equation for thermistor as temperature sensor
|
// Steinhart-Hart equation for thermistor as temperature sensor
|
||||||
double Rt = (adc * ANALOG_NTC_BRIDGE_RESISTANCE) / (1024.0 * ANALOG_V33 - (double)adc);
|
double Rt = (adc * ANALOG_NTC_BRIDGE_RESISTANCE) / (1024.0 * ANALOG_V33 - (double)adc);
|
||||||
double T = ANALOG_NTC_B_COEFFICIENT / (ANALOG_NTC_B_COEFFICIENT / ANALOG_T0 + log(Rt / ANALOG_NTC_RESISTANCE));
|
double T = ANALOG_NTC_B_COEFFICIENT / (ANALOG_NTC_B_COEFFICIENT / ANALOG_T0 + TaylorLog(Rt / ANALOG_NTC_RESISTANCE));
|
||||||
adc_temp = ConvertTemp(TO_CELSIUS(T));
|
adc_temp = ConvertTemp(TO_CELSIUS(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue