/* -------------------------------------------------------- ntc_cout_demo.cpp demonstriert die Verwendung eines abgepeckten cout in Verbindung mit einem NTC-Widerstand 07.03.2026 R. Seelig -------------------------------------------------------- */ #include #include "cout_light.h" #include "v003_adc.h" // Objektinstanz fuer cout_light cout_light cout_serial(Serial); ADC ntc1(PD4); // und Umleiten auf den Namen "cout" ... :-) nicht ganz die feine Art #define cout cout_serial // mittels LookUp-Table Generator aus // www.jjflash.de/ntc_table_v2.html erzeugte Tabelle // und Interpolation /* ------------------------------------------------- Lookup-table fuer NTC-Widerstand R25-Wert: 10.00 kOhm Pullup-Widerstand: 10.00 kOhm Materialkonstante beta: 4020 Aufloesung des ADC: 10 Bit Einheit eines Tabellenwertes: 0.1 Grad Celcius Temperaturfehler der Tabelle: 0.2 Grad Celcius -------------------------------------------------*/ const int ntctable[] = { 1539, 1269, 999, 853, 753, 676, 614, 561, 514, 473, 435, 400, 367, 336, 307, 278, 250, 223, 195, 168, 141, 114, 85, 56, 25, -7, -42, -81, -126, -179, -249, -355, -461 }; /* ------------------------------------------------- ntc_gettemp zuordnen des Temperaturwertes aus gegebenem ADC-Wert. ------------------------------------------------- */ int ntc_gettemp(uint16_t adc_value) { int p1,p2; // Stuetzpunkt vor und nach dem ADC Wert ermitteln. p1 = ntctable[ (adc_value >> 5) ]; p2 = ntctable[ (adc_value >> 5) + 1]; // zwischen beiden Punkten interpolieren. return p1 - ( (p1-p2) * (adc_value & 0x001f) ) / 32; } /* -------------------------------------------------------- setup -------------------------------------------------------- */ void setup() { Serial.begin(115200); cout << F("\n\r --------------------------------------\n\r"); cout << F(" CH32V003 running at 48 MHz \n\r"); cout << F(" 16 kByte Flash, 2 KByte RAM \n\r"); cout << F(" \n\r"); cout << F(" Arduino-Demo: NTC & cout \n\r"); cout << F(" \n\r"); cout << F(" 07.03.2026 \n\r"); cout << F(" --------------------------------------\n\n\r"); } /* -------------------------------------------------------- loop -------------------------------------------------------- */ void loop() { static int counter = 0; int temp; int nachkomma; temp= ntc_gettemp(ntc1.read()); nachkomma= temp % 10; temp /= 10; cout << F("\r Counter: ") << Dec << counter << F(" "); cout << Dec << temp << '.' << Dec << nachkomma << F(" oC "); delay(1000); counter++; }