From 4e95cb47a70a36fe7b7f999f2b662f0927dfcf27 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 23 May 2022 19:11:39 +1000 Subject: [PATCH] NTC thermistor --- source/Core/BSP/Magic/BSP.cpp | 127 +++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/Magic/BSP.cpp b/source/Core/BSP/Magic/BSP.cpp index 8a67734e..64011ad5 100644 --- a/source/Core/BSP/Magic/BSP.cpp +++ b/source/Core/BSP/Magic/BSP.cpp @@ -21,9 +21,133 @@ void resetWatchdog() { //#TODO } -uint16_t getHandleTemperature(uint8_t sample) { +#ifdef TEMP_NTC +// Lookup table for the NTC +// Stored as ADCReading,Temp in degC +static const int32_t NTCHandleLookup[] = { + // ADC Reading , Temp in C x10 + // 64179, -400, // + // 64001, -390, // + // 63813, -380, // + // 63618, -370, // + // 63415, -360, // + // 63204, -350, // + // 62983, -340, // + // 62757, -330, // + // 62518, -320, // + // 62271, -310, // + // 62012, -300, // + // 61748, -290, // + // 61473, -280, // + // 61186, -270, // + // 60891, -260, // + // 60585, -250, // + // 60268, -240, // + // 59941, -230, // + // 59604, -220, // + // 59255, -210, // + 58896, -200, // + 58526, -190, // + 58145, -180, // + 57752, -170, // + 57349, -160, // + 56934, -150, // + 56510, -140, // + 56073, -130, // + 55626, -120, // + 55167, -110, // + 54699, -100, // + 54220, -90, // + 53729, -80, // + 53229, -70, // + 52717, -60, // + 52200, -50, // + 51667, -40, // + 51128, -30, // + 50582, -20, // + 50025, -10, // + 49455, 0, // + 48883, 10, // + 48302, 20, // + 47712, 30, // + 47116, 40, // + 46510, 50, // + 45902, 60, // + 45286, 70, // + 44666, 80, // + 44044, 90, // + 43412, 100, // + 42783, 110, // + 42148, 120, // + 41500, 130, // + 40860, 140, // + 40222, 150, // + 39576, 160, // + 38935, 170, // + 38289, 180, // + 37640, 190, // + 36989, 200, // + 36353, 210, // + 35705, 220, // + 35060, 230, // + 34422, 240, // + 33792, 250, // + 33160, 260, // + 32534, 270, // + 31910, 280, // + 31291, 290, // + 30677, 300, // + 30069, 310, // + 29466, 320, // + 28867, 330, // + 28277, 340, // + 27693, 350, // + 27115, 360, // + 26544, 370, // + 25981, 380, // + 25426, 390, // + 24880, 400, // + 24339, 410, // + 23806, 420, // + 23281, 430, // + 22767, 440, // + 22259, 450, // + // 21761, 460, // + // 21268, 470, // + // 20787, 480, // + // 20313, 490, // + // 19848, 500, // + // 19392, 510, // + // 18945, 520, // + // 18507, 530, // + // 18076, 540, // + // 17655, 550, // + // 17242, 560, // + // 16838, 570, // + // 16442, 580, // + // 16052, 590, // + // 15672, 600, // + +}; +#endif +uint16_t getHandleTemperature(uint8_t sample) { int32_t result = getADCHandleTemp(sample); + // Tip is wired up with an NTC thermistor + // 10K NTC balanced with a 10K pulldown + // NTCG163JF103FTDS +#ifdef TEMP_NTC + // vout = + // For now not doing interpolation + for (uint32_t i = 0; i < (sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t))); i++) { + if (result > NTCHandleLookup[(i * 2) + 0]) { + return NTCHandleLookup[(i * 2) + 1]; + } + } + return 45 * 10; +#endif +#ifdef TEMP_TMP36 +#warn This is not shipped in production result -= 10240; // remove 0.5V offset // 10mV per C // 204.7 counts per Deg C above 0C @@ -33,6 +157,7 @@ uint16_t getHandleTemperature(uint8_t sample) { result = 0; } return result; +#endif } uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {