#define EEPROM_DEBUG /* bug fix where Blinking RED would not change led_color back --> global/local definiton ToDo: Different PCB-Layout, sodass RGB LED beim Flashen nicht leuchten. Changelog: 18.02.17: CHANGE: Add EEPROM_DEBUG defined block. Need to be compiled with -O3 Flag INFO: ledcolor==3 block is obsolete. Could be removed to save space 23.06.17: CHANGE: comment out ledcolor==3 block reduce brighness to 100 for green and red INFO: MicroCore 1.0.2 creates very small binary, suspious 25.05.18: CHANGE: reduce the used flash ADDED: max red temp per session FIXED: lowered red, green led intensity */ // ATMEL ATTINY13_20 / ARDUINO // //Clock frequency: Default internal clock (9.6MHz / 8 = 1.2MHz) //BOD 4.3V //GCC -Os LTO enabled --> 746 Bytes //Global variables: 7 Bytes // avrdude -c usbasp -p attiny13 // Fuse 0x6A 0xF9 // Fuse 0x3F // // // +--------+ // [ RST (PB5) |1* 8| (VCC) Power ] // [ Temp (PB3) |2 7| (PB2) RED ] // [ NC (PB4) |3 6| (PB1) GREEN ] // [ Ground (GND) |4 5| (PB0) BLUE ] // +--------+ // //Fuse Settings //CKSEL1..0: 11 - 128kHz --> HVSP!! //SUT1..0 : 10 - 14CK+64ms //CKDIV8 : 0 - CLK divided by 8 -> 16kHz --> HVSP!! //PIN assignment const byte tempPin = 3; //this sets the temp pin const byte red = 2; //this sets the red led pin const byte green = 1; //this sets the green led pin const byte blue = 0; //this sets the blue led pin /* NTC table and info 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit measurement takes place at the engine oil tank drain bolt VDO Werte ***DEPRECATED** 55 °C @ 2k Ohm == 0,587V (120EA) 65 °C @ 2k Ohm == 0,423V (87EA) 70 °C @ 2k Ohm == 0,361V (74EA) 75 °C @ 2k Ohm == 0,309V (63EA) 80 °C @ 2k Ohm == 0,265V (55EA) 90 °C @ 2k Ohm == 0,195V (40EA) 100 °C @ 2k Ohm == 0,150V (30EA) 120 °C @ 2k Ohm == 0,089V (18EA) Koso linear NTC 10k @ 25 °C (guess) 50 °C @ 2k Ohm == 3,41 V (696EA) 55 °C @ 2k Ohm == 3,24 V (662EA) 65 °C @ 2k Ohm == 2,88 V (589EA) 70 °C @ 2k Ohm == 2,72 V (556EA) 75 °C @ 2k Ohm == 2,54 V (518EA) 80 °C @ 2k Ohm == 2,36 V (482EA) 90 °C @ 2k Ohm == 2,06 V (420EA) 100 °C @ 2k Ohm == 1,75 V (359EA) --------------------------------- 110 °C @ 2k Ohm == (300EA) (guess) Handbuch definiert Oeltemperatur zwischen 55 - 65 ° C. Hier wird der Bereich zwischen 50 und 90 °C als GRUEN definiert zwischen 100 und 110 °C als ROT definiert Ab 110 °C beginnt der Notfallmodus http://www.xt-660.de/forum/viewtopic.php?p=173806#p173806 weitere XT660Z Werte Messwerte Bei rund 6-9 ° Aussentemperatur bleibt Die Anzeige auf blau Bei rund 10-15° Aussentemperatur springt die Anzeige zwischen kalt und warm. Lediglich Stadtverkehr bzw. Stand zeigt warm an. Ggf. untere Grenze herabsetzen bei rund 15-25° Aussentemperatur stabil. Hoechstwert 504EA ~ 78° ggf. obere Grenze nach unten verschieben. bei rund 27° Aussentemperatur im Stau rote Anzeige. Hoechstwert 379EA ~ 95°. vmtl kein Lüfter an 1.6.18: maximaler Wert bisher: 0x019D = 413EA */ #ifdef EEPROM_DEBUG //use EEPROM to sav maximum temperature #include #endif const unsigned int threshold_cold = 690; //threshold for color change from blue to green const unsigned int threshold_hot = 360; //threshold for color change from green to red const unsigned int threshold_emerg = 300; //threshold for color change from red to red blink static byte ledcolor; //Memory for the current LED Color. TODO: Change assignment to something other static unsigned int temp_set; //Memory for the used temperature value /* function to update and read unsigned integer into EEPROM */ #ifdef EEPROM_DEBUG unsigned int eepromReadInt(byte address) { unsigned int value = 0x0000; value = value | (EEPROM.read(address) << 8); value = value | EEPROM.read(address + 1); return value; } void eepromUpdateInt(byte address, unsigned int value) { EEPROM.update(address, (value >> 8) & 0xFF ); EEPROM.update(address + 1, value & 0xFF); } #endif void setup() { //this sets the I/O pins pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); pinMode(tempPin, INPUT); //LED initialize digitalWrite(blue, HIGH); delay(500); digitalWrite(blue, LOW); delay(100); digitalWrite(green, HIGH); delay(500); digitalWrite(green, LOW); delay(100); digitalWrite(red, HIGH); delay(500); digitalWrite(red, LOW); delay(100); ledcolor = 0; //temp_set = 0; //temperature reference temp_set = analogRead(tempPin); //clean current red max value eepromUpdateInt(4, 0); } void loop() { unsigned int temp_curr; //Memory for the measured temperature value unsigned int diff; //Memory for the difference between measured and used temperature value unsigned int diff_sum; //Memory for aggregated difference //clean for a new measurement row diff = 0; diff_sum = 0; //logic part //while the meaesured difference in a row is smaller than 5 (<1°C) units, do nothing. Avoids massive flickering //Change it to 10 units, if the steadyness is too low while (diff_sum <= 10) { //read current temperature temp_curr = analogRead(tempPin); //avoid abs() function. Get a positive difference if (temp_curr <= temp_set) { diff = temp_set - temp_curr; } else { diff = temp_curr - temp_set; } //if emergency_mode is active and //otherwise it is not blinking if (ledcolor == 4) { digitalWrite(red, HIGH); /* Not needed digitalWrite(green, LOW); digitalWrite(blue, LOW); */ delay(500); digitalWrite(red, LOW); } //Sum up the positive difference but use small steps diff_sum = (diff_sum + diff) >> 1; delay(500); } //overwrite the used temperature value with the measured value temp_set = temp_curr; #ifdef EEPROM_DEBUG //save max temp into first four bytes of EEPROM unsigned int val = eepromReadInt( 0 ); if (temp_set < val) { eepromUpdateInt(0, temp_set); } #endif //LED Color decicion. if (temp_curr >= threshold_cold ) { ledcolor = 2; //BLUE } else if (temp_curr < threshold_cold and temp_curr >= threshold_hot ) { ledcolor = 1; //GREEN } else if (temp_curr < threshold_hot and temp_curr >= threshold_emerg ) { ledcolor = 0; //RED } else if (temp_curr < threshold_emerg) { ledcolor = 4; //RED_BLINK } else { ledcolor = 3; //ERROR - Should not be reached } //LED power off to change state digitalWrite(red, LOW); digitalWrite(blue, LOW); digitalWrite(green, LOW); //set the output as ledcolor says switch (ledcolor) { case 0: //if ledcolor equals 0 then the led will turn RED analogWrite(red, 100); #ifdef EEPROM_DEBUG //save red temp into EEPROM val = eepromReadInt( 4 ); if (temp_set < val) { eepromUpdateInt(4, temp_set); } #endif break; case 1: //if ledcolor equals 1 then the led will turn GREEN analogWrite(green, 100); break; case 2: //if ledcolor equals 2 then the led will turn BLUE //digitalWrite(blue, HIGH); //keep blue less bright analogWrite(blue, 100); break; // case 3: //if ledcolor equals 3 then the led will turn WHITE (COMMENT -> OFF) // /*digitalWrite(red, LOW); // digitalWrite(green, LOW); // digitalWrite(blue, LOW);*/ // analogWrite(red, 100); // analogWrite(green, 100); // analogWrite(blue, 100); // break; case 4: //if ledcolor equals 4 then the led will BLINK RED digitalWrite(red, HIGH); delay(500); digitalWrite(red, LOW); break; } delay(500); }