Skip to content

Commit 70bbd92

Browse files
author
Tobias Frost
committed
Make maximum tip power configurable via Options.
1 parent e4c8bef commit 70bbd92

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

Maiskolben_TFT/Maiskolben_TFT.ino

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ uint16_t charge = 0;
6464
float adc_offset = ADC_TO_TEMP_OFFSET;
6565
float adc_gain = ADC_TO_TEMP_GAIN;
6666

67+
uint8_t maxpower = 40;
68+
6769
#define RGB_DISP 0x0
6870
#define BGR_DISP 0x2
6971

@@ -201,6 +203,7 @@ void setup(void) {
201203
delay(50);
202204
}
203205
EEPROM.update(EEPROM_OPTIONS, (fahrenheit << 2) | (bootheat << 1) | autopower);
206+
EEPROM.update(EEPROM_POWER, maxpower);
204207
EEPROM.update(EEPROM_VERSION, EE_VERSION);
205208
EEPROM.update(EEPROM_INSTALL, EEPROM_CHECK);
206209
EEPROM.put(EEPROM_ADCTTG, adc_gain);
@@ -219,6 +222,8 @@ void setup(void) {
219222
autopower = options & 1;
220223
bootheat = options & 2;
221224
fahrenheit = options & 4;
225+
maxpower = EEPROM.read(EEPROM_POWER);
226+
222227
if (force_menu) optionMenu();
223228
else {
224229
updateRevision();
@@ -346,7 +351,8 @@ void optionMenu(void) {
346351
// mask
347352
{ "Autoshutdown", OPT_BIT_SHUTOFF, 1, 0, 0, (uint8_t *)&autopower },
348353
{ "Heat on boot", OPT_BIT_BHEAT, 1, 0, 0, (uint8_t *)&bootheat },
349-
{ "Fahrenheit", OPT_BIT, 1, 0, 0, (uint8_t *)&fahrenheit },
354+
{ "Fahrenheit", OPT_BIT, 1, 0, 0, (uint8_t *)&fahrenheit },
355+
{ "Pmax", OPT_8BIT_VALUE, 10, 110, 5, &maxpower }
350356
};
351357

352358
// how many chars do fit into a line?
@@ -491,6 +497,7 @@ void optionMenu(void) {
491497
}
492498

493499
EEPROM.update(EEPROM_OPTIONS, (fahrenheit << 2) | (bootheat << 1) | autopower);
500+
EEPROM.update(EEPROM_POWER, maxpower);
494501
updateRevision();
495502
EEPROM.update(EEPROM_VERSION, EE_VERSION);
496503
if (EEPROM.read(EEPROM_VERSION) < 30) {
@@ -983,10 +990,19 @@ void compute(void) {
983990
last_measured = cur_t;
984991

985992
heaterPID.Compute();
986-
if (error != NO_ERROR || off)
993+
994+
// Power limitation.
995+
// Tips are rated for 40W, do not exceed that.
996+
// note t-hat we have inherently only 50% PWM, as we have it on 10ms and then wait with pwm off for another 10ms.
997+
// Formula: P = 0.5 * ( U^2 / ( R )) * (pwm)
998+
float pwm_max = 2 * maxpower / ((v * v) / 2.4);
999+
if (pwm_max > pid_val) pwm_max = pid_val;
1000+
1001+
if (error != NO_ERROR || off) {
9871002
pwm = 0;
988-
else
989-
pwm = min(255,pid_val*255);
1003+
} else {
1004+
pwm = min(255, pwm_max * 255);
1005+
}
9901006
analogWrite(HEATER_PWM, pwm);
9911007
}
9921008

Maiskolben_TFT/definitions.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define VERSION "3.1"
2-
#define EE_VERSION 31
2+
#define EE_VERSION 32
33
#define EEPROM_CHECK 42
44

55
#define BAR_HEIGHT 4 //Should be no bigger than 5
@@ -77,6 +77,14 @@
7777
#define EEPROM_ADCTTG 14
7878
#define EEPROM_ADCOFF (EEPROM_ADCTTG + sizeof(float))
7979

80+
// EEPROM Version 32
81+
#define EEPROM_POWER 20
82+
#define EEPROM_STBYTEMP 21
83+
#define EEPROM_STBYTIME 23
84+
#define EEPROM_MINTEMP 25
85+
#define EEPROM_MAXTEMP 27
86+
87+
8088
#define EEPROM_INSTALL 42
8189
#define REF_T1 275
8290
#define REF_T2 410

0 commit comments

Comments
 (0)