Split thermistor functions into separate logical units and add TODO
This commit is contained in:
@@ -14,11 +14,6 @@
|
||||
#define TW_MR_SLA_NACK 0x48 // SLA+R transmitted, NACK received
|
||||
#define TW_MR_DATA_ACK 0x50 // Data received, ACK returned
|
||||
|
||||
// NTC conversion constants
|
||||
#define NTC01 1.009249522e-3
|
||||
#define NTC02 2.378405444e-4
|
||||
#define NTC03 2.019202697e-7
|
||||
|
||||
// TODO: Error handling and recovery besides watchdog timer.
|
||||
// TODO: Add more documentation from the atmel data sheet.
|
||||
// TODO: ADS1115 continuous mode instead of single-shot?
|
||||
@@ -477,7 +472,7 @@ static bool I2C_ADS1115_IsReady(void)
|
||||
return reg & BIT(15);
|
||||
}
|
||||
|
||||
word I2C_ADS1115_Read(int channel)
|
||||
word I2C_ADS1115_ReadRaw(int channel)
|
||||
{
|
||||
word config;
|
||||
word os, mode, rate, gain, mux;
|
||||
@@ -563,21 +558,3 @@ word I2C_ADS1115_Read(int channel)
|
||||
|
||||
return I2C_ADS1115_ReadRegister(0x00);
|
||||
}
|
||||
|
||||
float I2C_ADS1115_ReadThermistor(int channel)
|
||||
{
|
||||
word raw;
|
||||
float r1, t;
|
||||
float logr2;
|
||||
|
||||
// TODO: Improve readability
|
||||
// https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
|
||||
|
||||
raw = I2C_ADS1115_Read(channel);
|
||||
|
||||
r1 = (float) raw / 264.8f * 0.05f;
|
||||
logr2 = log(10000.0f / (5.0f / r1 - 1.0f));
|
||||
t = 1.0f / (NTC01 + NTC02 * logr2 + NTC03 * pow(logr2, 3));
|
||||
|
||||
return t - 273.15f; // Convert fahrenheit to celsius
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ int I2C_AHT20_Init(void);
|
||||
int I2C_AHT20_Read(float *temp, float *rhum);
|
||||
|
||||
// ADS1115 analog to digital converter
|
||||
word I2C_ADS1115_Read(int channel);
|
||||
float I2C_ADS1115_ReadThermistor(int channel);
|
||||
word I2C_ADS1115_ReadRaw(int channel);
|
||||
|
||||
#endif // MAD_CORE_BUS_I2C_H
|
||||
|
||||
Reference in New Issue
Block a user