Skip to content

Commit

Permalink
[SOFT-527] Update NTC thermistor curve (#428)
Browse files Browse the repository at this point in the history
It now obeys the experimental curve rather than the theoretical one (commented out). See https://www.desmos.com/calculator/fqoelc5mkj.
  • Loading branch information
vaaranan-y authored Aug 28, 2021
1 parent 41ce080 commit 401a05e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 10 additions & 4 deletions projects/solar/src/sense_temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ static void prv_sense_callback(void *context) {
case NTC_THERMISTOR:
// NTC: T = 1 / ( ( ln(0.56 * V / (3.3 - V)) / 3428 ) + 1/298.15 ) in KELVIN. For Celsius,
// subtract 273.15
converted_reading =
(1 /
((ln(0.56 * converted_reading / (3.3 - converted_reading)) / 3428.0) + 1.0 / 298.15)) -
273.15;
// NEW NTC CURVE (BASED ON EXPERIMENTAL DATA): T = (-14.195)*V^3 + (37.9434)*V^2 - 64.8244V +
// 121.362 (already in celsius)
// converted_reading =
// (1 /
// ((ln(0.56 * converted_reading / (3.3 - converted_reading)) / 3428.0) + 1.0 / 298.15))
// -
// 273.15;
converted_reading = (-14.195) * pow(converted_reading, 3) +
(37.9434) * pow(converted_reading, 2) - 64.8244 * converted_reading +
121.362;

// Convert from Celsius to deciCelsius
converted_reading = converted_reading * 10;
Expand Down
5 changes: 2 additions & 3 deletions projects/solar/test/test_sense_temperature.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "sense_temperature.h"

#include <stdbool.h>

#include "adc.h"
#include "data_store.h"
#include "gpio.h"
#include "log.h"
#include "sense.h"
#include "sense_temperature.h"
#include "test_helpers.h"
#include "unity.h"

Expand All @@ -15,7 +14,7 @@
// The two test variables below are calculated from inputting 0x800 into the relative conversion
// formulae (see sense_temperature.c)
#define TEST_RTD_CONVERTED_READING (-541)
#define TEST_NTC_CONVERTED_READING (272)
#define TEST_NTC_CONVERTED_READING (258)

static SenseCallback s_sense_callbacks[MAX_THERMISTORS];
static void *s_sense_callback_contexts[MAX_THERMISTORS];
Expand Down

0 comments on commit 401a05e

Please sign in to comment.