// ****** Hardware Model definitions ******** // Do not change these definitions! The numerical order is important! #define ARDUINO_ 0 #define HWV_1_0 1 #define HWV_1_1 2 #define HWV_1_2 3 // ********* Hardware Model ************ // Uncomment ONE of the following: #define HWMODEL ARDUINO_ // Use this one if you want to build this project around an Arduino //#define HWMODEL HWV_1_0 // Use this one if you want to build this project for a ThermalOptimizer board v1.0 //#define HWMODEL HWV_1_1 // Use this one if you want to build this project for a ThermalOptimizer board v1.1 //#define HWMODEL HWV_1_2 // Use this one if you want to build this project for a ThermalOptimizer board v1.2 // ******** Debug definitions ********** // Leave commented for production! //#define SIMTEMP 437 // Use this to test the program without actual temperature sensors connected. 683 simulates 68.3 Celcius //#define SIMVOLT 141 // Use this to test the program for a specific voltage. 141 simulates 14.1 //#define USEDEFAULT 1 // declutter the EPROM, use the defaults #if HWMODEL == ARDUINO_ #define HWVER "UNO" #endif #if HWMODEL == HWV_1_0 #define HWVER "1.0" #endif #if HWMODEL == HWV_1_1 #define HWVER "1.1" #endif #if HWMODEL == HWV_1_2 #define HWVER "1.2" #endif /* * Voltage measuring * ================= * To bring the system voltage within the range of the ADC's we have to use a resistor divider * We want to be compatible with 24V systems, so we dimensioned the resistor dividers accordingly * ADC1 * _______ | _______ * VCC --|_____|---|----|_____|--- GND * R1 R2 * * In the latest Thermal Optimizer board we use for R1 39k, for R2 7k5. * If R1=39k, and R2=7k5... * If we assume a maximum voltage of 15V, then this would give 2.42V on the input of ADC1, with a load of 0.25mA * If we assume a maximum voltage of 30V, then this would give 4.84V on the input of ADC1, with a load of 0.5mA * * The math: * Voltage = ADC1*AREF/(1024+1) * (R1+R2)/(R2) * * If you build an Arduino based circuit yourself, You can change the values of R1 and R2 in the source code. * */ #define ADCREF 5000UL // Voltage of the 5V power supply in millivolts #if HWMODEL == ARDUINO_ #define R1 10000UL // Ohms #define R2 1800UL // Ohms #endif #if HWMODEL == HWV_1_0 #define R1 10000UL // Ohms #define R2 1880UL // Ohms #endif #if HWMODEL > HWV_1_0 #define R1 39000UL // Ohms #define R2 7500UL // Ohms #endif #if HWMODEL == ARDUINO_ #define TEMPR 4700 // Ohms of the temperature sensor pull up resistor #endif #if HWMODEL == HWV_1_0 #define TEMPR 4700 // Ohms of the temperature sensor pull up resistor #endif #if HWMODEL > HWV_1_0 #define TEMPR 10000 // Ohms of the temperature sensor pull up resistor #endif #define THERMISTOR 5000 // Reference value of the thermistor #define THERMBETA 3950 // Beta value of the thermistor #define TEMPSAMPLES 8 // Number of samples for averaging the temperature with a thermistor // IO ports #define BUTTON 2 // Button needs to be port PD2 or PD3 because of wake up interrupt #define VCCREF A1 // Voltage sense #define ENGINE 16 // Engine contact sense wire #if HWMODEL == ARDUINO_ #define TEMP 14 #else #define TEMP 19 // Temperature sensor (port 19 is ADC 5, conflict if I2C bus is used) #endif #define LED 13 // Conventionally, this port is used to control a LED #if HWMODEL == ARDUINO_ #define HEATER 3 // Heater relay control output #define BACKLIGHT_B0 18 // Display backlight, bit 0 (Port 18 is ADC 4, conflict if I2C bus is used) #define BACKLIGHT_B1 12 // Display backlight, bit 1 #define BACKLIGHT_B2 11 // Display backlight, bit 2 #endif #if HWMODEL == HWV_1_0 #define HEATER 18 // Heater relay control output (Port 18 is ADC 4, conflict if I2C bus is used) #define BACKLIGHT_B0 3 // Display backlight, bit 0, NOT IMPLEMENTED IN HWV 1_0 #define BACKLIGHT_B1 14 // Display backlight, bit 1, NOT IMPLEMENTED IN HWV 1_0 #define BACKLIGHT_B2 11 // Display backlight, bit 2 #endif #if HWMODEL > HWV_1_0 #define HEATER 3 #define BACKLIGHT_B0 18 // Display backlight, bit 0 (Port 18 is ADC 4, conflict if I2C bus is used) #define BACKLIGHT_B1 14 // Display backlight, bit 1 #define BACKLIGHT_B2 11 // Display backlight, bit 2 #endif #if HWMODEL > HWV_1_0 #define OWPULLUP 24 // (ATMEGA328pb only, PE1) PullUp for one wire interface #endif #if HWMODEL > HWV_1_1 #define LUMSENS 25 // (ATMEGA328pb only, PE2) ADC port to sens LED luminance #endif #define AUX 17 // Auxilliary output #define HWV 10 // Hot Water Valve // Interfaces //#define LCDADDR 0x3F // I2C address, uncomment for I2C display (but you have to free up ADC4 (18) and ADC5 (19)) #define LCD_RS 9 // Used only when no I2C is used #define LCD_EN 8 // Used only when no I2C is used #define LCD_D4 4 // Used only when no I2C is used #define LCD_D5 5 // Used only when no I2C is used #define LCD_D6 6 // Used only when no I2C is used #define LCD_D7 7 // Used only when no I2C is used // Constants #define VERSION "1.1" // Software version to display on the screen #define EPROMCHK 0x7875 // EPROM signature so we can detect that the EPROM content is ours. //#define SHORTPRESS 25 // Minimum time in milliseconds to register a button press as valid instead of just a noise spike (not used with touch sensor) #define LONGPRESS 650 // Time in milliseconds to register a key press as a long press. #define MENUTIMEOUT 10 // Timeout in seconds to return to default operation from within the menu. // Defaults after factory reset (can be changed in the menu afterwards) #define BRIGHTNESS 5 // Default LCD backlight brightness, 0 to 7 #define DISPTIMEOUT 0 // LCD backlight timeout in seconds #define NIGHTSENSOR 11 // Darkness sensor value #define VREQ 141 // Required voltage*10 to switch on the heater automatically. #define VFLOAT 135 // Float voltage*10 to switch off the heater automatically #define VOFF 125 // Voltage*10 at which a pause has to be taken to recharge the batteries first #define PAUSE 20 // Duration of the pause in minutes #define TMIN 40 // Antifreeze protection should be initiated below this temperature (Celsius*10) #define TTARGET 400 // Target temperature (Celsius*10) for daily usage #define TSANITY 600 // Temperature (Celsius*10) needed to clear the "sanity alert" #define TMAX 800 // Maximum allowed temperature (Celsius*10) #define TNOSAN 250 // Don't display a sanity alert below this temperature (Celsius*10) #define TSANDAYS 7 // Interval in days between reaching the "sanity temperature" to not raise the "sanity alert" #define PUMPDELTA 25 // Difference in input and boiler temperature in Celsius*10 #define PUMPAFTERRUN 60 // Time in seconds to continue running the pump after PUMPDELTA is no longer met #define HWVTIMER 0 // Time in minutes to enable hot water valve #define HWVPWM 100 // Hot water valve PWM in % (100 is disable) #define HWVBLEED 5 // Time in seconds to open the HWV when the heating element is energized, to bleed out any air. #define HOLDON 5 // Time in seconds to hold on, after switching the boiler on, to give chargers some time to react to the load #define RELAYPWM 100 // Percentage of hold current of the relay // Constants that are not configurable in the menu. #define HOLD_OFF 60 // Seconds to wait after last heater state change before switching it on again. #define TRENDDELTA 3 // Temperature (Celsius*10) difference required to change the trend arrow #define LUMSAMPLES 16 // Samples to average the measured luminance via the LED. // LED mode constants #define LEDM_TOUCH 0 #define LEDM_WARMWATER 1 #define LEDM_HEATING 2 #define LEDM_HWVALVE 3 #define LEDM_LEGIONELLA 4 // Structure definitions struct rom_t { uint16_t epromchk; uint8_t brightness; uint8_t disptimeout; uint16_t vreq; uint16_t vfloat; uint16_t voff; int16_t pause; bool fahrenheit; int16_t tmin; int16_t ttarget; int16_t tsanity; int16_t tmax; int16_t tsandays; int16_t tnosan; uint16_t calibration; int16_t pumpdelta; uint16_t pumpafterrun; uint16_t hwv_timer; bool vmul; uint8_t hwv_pwm; uint8_t pumpMode; uint8_t ledmode; bool lcdglow; uint8_t holdon; uint8_t nightbright; uint8_t nightsensor; uint8_t relaypwm; bool altfunc; }; struct sensors_t { uint16_t epromchk; uint8_t temphwa[2][8]; int16_t thermistor; int16_t thermbeta; bool useDS; }; struct mma_t { uint16_t samples; int16_t avg; int32_t sum; }; struct tempdata_t { int16_t temperature; int16_t failures; int16_t fallback; mma_t mmaTemp; }; struct button_t { const uint8_t button; uint32_t pressed; // Button press duration bool longpressed; }; void fptr_dummy(void); void fptr_brightness(void); void fptr_showvoltage(void); void fptr_showTemp(void); void fptr_showtemps(void); void fptr_vmul(void); void fptr_units(void); void fptr_altfunc(void); void fptr_ledmode(void); void fptr_pumpsource(void); void fptr_lumsens(void); void fptr_versions(void); void fptr_serialnr(void);