1
0
forked from me/IronOS

NTC lookup cleaned up and shrunk + linear interpolate

This commit is contained in:
Ben V. Brown
2021-04-28 21:06:29 +10:00
parent 7c54b24209
commit fe2469fdb5

View File

@@ -3,6 +3,7 @@
#include "BSP.h" #include "BSP.h"
#include "I2C_Wrapper.hpp" #include "I2C_Wrapper.hpp"
#include "Model_Config.h" #include "Model_Config.h"
#include "Utils.h"
#include "Pins.h" #include "Pins.h"
#include "Setup.h" #include "Setup.h"
#include "history.hpp" #include "history.hpp"
@@ -13,76 +14,31 @@ volatile uint8_t pendingPWM = 0;
uint16_t totalPWM = 255; uint16_t totalPWM = 255;
const uint16_t powerPWM = 255; const uint16_t powerPWM = 255;
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0}; history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); } void resetWatchdog() {
HAL_IWDG_Refresh(&hiwdg);
}
#ifdef TEMP_NTC #ifdef TEMP_NTC
// Lookup table for the NTC // Lookup table for the NTC
// Stored as ADCReading,Temp in degC // Stored as ADCReading,Temp in degC
static const uint16_t NTCHandleLookup[] = { static const uint16_t NTCHandleLookup[] = {
// ADC Reading , Temp in C // ADC Reading , Temp in C
11292, 600, //
12782, 550, //
14380, 500, //
16061, 450, //
17793, 400, //
19541, 350, //
21261, 300, //
22915, 250, //
24465, 200, //
25882, 150, //
27146, 100, //
28249, 50, //
29189, 0, // 29189, 0, //
29014, 1, // };
28832, 2, // const int NTCHandleLookupItems = sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t));
28644, 3, //
28450, 4, //
28249, 5, //
28042, 6, //
27828, 7, //
27607, 8, //
27380, 9, //
27146, 10, //
26906, 11, //
26660, 12, //
26407, 13, //
26147, 14, //
25882, 15, //
25610, 16, //
25332, 17, //
25049, 18, //
24759, 19, //
24465, 20, //
24164, 21, //
23859, 22, //
23549, 23, //
23234, 24, //
22915, 25, //
22591, 26, //
22264, 27, //
21933, 28, //
21599, 29, //
21261, 30, //
20921, 31, //
20579, 32, //
20234, 33, //
19888, 34, //
19541, 35, //
19192, 36, //
18843, 37, //
18493, 38, //
18143, 39, //
17793, 40, //
17444, 41, //
17096, 42, //
16750, 43, //
16404, 44, //
16061, 45, //
// 15719, 46, //
// 15380, 47, //
// 15044, 48, //
// 14710, 49, //
// 14380, 50, //
// 14053, 51, //
// 13729, 52, //
// 13410, 53, //
// 13094, 54, //
// 12782, 55, //
// 12475, 56, //
// 12172, 57, //
// 11874, 58, //
// 11580, 59, //
// 11292, 60, //
};
#endif #endif
// These are called by the HAL after the corresponding events from the system // These are called by the HAL after the corresponding events from the system
@@ -96,10 +52,13 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
} }
} }
uint16_t getHandleTemperature() { uint16_t getHandleTemperature() {
return 250; // TODO int32_t result = getADC(0);
return Utils::InterpolateLookupTable(NTCHandleLookup,NTCHandleLookupItems, result);
} }
uint16_t getTipInstantTemperature() { return getADC(2); } uint16_t getTipInstantTemperature() {
return getADC(2);
}
uint16_t getTipRawTemp(uint8_t refresh) { uint16_t getTipRawTemp(uint8_t refresh) {
if (refresh) { if (refresh) {
@@ -217,11 +176,22 @@ void unstick_I2C() {
HAL_I2C_Init(&hi2c1); HAL_I2C_Init(&hi2c1);
} }
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; } uint8_t getButtonA() {
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; } return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ?
1 : 0;
}
uint8_t getButtonB() {
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ?
1 : 0;
}
void BSPInit(void) {} void BSPInit(void) {
}
void reboot() { NVIC_SystemReset(); } void reboot() {
NVIC_SystemReset();
}
void delay_ms(uint16_t count) { HAL_Delay(count); } void delay_ms(uint16_t count) {
HAL_Delay(count);
}