diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | LICENSE | 2 | ||||
| -rw-r--r-- | src/temperature.c | 16 | ||||
| -rw-r--r-- | src/temperature.h | 2 |
4 files changed, 13 insertions, 10 deletions
@@ -2,6 +2,3 @@ .ccls a.out out/ -*.zip -fp-info-cache -*.lck @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Akshay Nair +Copyright (c) 2026 Akshay Nair Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/temperature.c b/src/temperature.c index b804fc9..72e4875 100644 --- a/src/temperature.c +++ b/src/temperature.c @@ -37,13 +37,17 @@ uint16_t spi_read16(void) { float temperature_read(void) { THERMO_PORT &= ~(1 << THERMO_CS); - uint16_t v = spi_read16(); + uint16_t out = spi_read16(); THERMO_PORT |= (1 << THERMO_CS); - // invalid temp - if (v & 0x4) - return 999.9; + // thermocouple open (invalid read) D2 bit + if (out & 0b100) + return 0.0; - v >>= 3; - return v * 0.25; + out >>= 3; // Skip D0,D1,D2 + + float temperature = out * THERMO_RESOLUTION; + if (temperature > 100) + temperature *= 1.05; + return temperature; } diff --git a/src/temperature.h b/src/temperature.h index 31fa92a..c15fe22 100644 --- a/src/temperature.h +++ b/src/temperature.h @@ -4,6 +4,8 @@ #define THERMO_PORT PORTA #define THERMO_DDR DDRA +#define THERMO_RESOLUTION 0.25 + #define SPI_DELAY_US 10 void temperature_init(void); |
