@@ -64,6 +64,8 @@ uint16_t charge = 0;
6464float adc_offset = ADC_TO_TEMP_OFFSET;
6565float 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
0 commit comments