From fb83d2de5727768e90c367db42d46a56f1fcadc6 Mon Sep 17 00:00:00 2001 From: Nico Tonnhofer Date: Sat, 11 Mar 2017 18:18:14 +0100 Subject: [PATCH] heaters: rework max heater value remove the define USE_MAX_HEATER this will cost only neglabile space when not enabled on AVR. --- config/board.3drag.h | 11 ------- config/board.cnc-shield-v3.h | 11 ------- config/board.gen3.h | 11 ------- config/board.gen6.h | 11 ------- config/board.gen7-arm.h | 11 ------- config/board.gen7-v1.1-v1.3.h | 11 ------- config/board.gen7-v1.4.h | 11 ------- config/board.melzi.h | 11 ------- config/board.nanoheart-v1.0.h | 11 ------- config/board.pcbscriber.h | 11 ------- config/board.ramps-v1.2.h | 11 ------- config/board.ramps-v1.3.h | 11 ------- config/board.rumba.h | 11 ------- config/board.sanguinololu-v1.1.h | 11 ------- config/board.sanguinololu-v1.2.h | 11 ------- config/board.sanguish.h | 11 ------- config/board.sinaptec-at328-02.h | 11 ------- config/board.teensy++-v2.0.h | 11 ------- config/board.teensy-v2.0.h | 11 ------- config/board.tronxy.h | 11 ------- configtool/board.generic.h | 11 ------- configtool/heaterspage.py | 9 ------ heater-avr.c | 54 ++++++++++++++------------------ heater-lpc.c | 23 +++----------- 24 files changed, 27 insertions(+), 290 deletions(-) diff --git a/config/board.3drag.h b/config/board.3drag.h index 79cf83d..3b6d7d2 100644 --- a/config/board.3drag.h +++ b/config/board.3drag.h @@ -234,17 +234,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.cnc-shield-v3.h b/config/board.cnc-shield-v3.h index c275a73..5b5fb18 100644 --- a/config/board.cnc-shield-v3.h +++ b/config/board.cnc-shield-v3.h @@ -234,17 +234,6 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO3, THERMISTOR_EXTRUDER) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.gen3.h b/config/board.gen3.h index 8a60432..703a37d 100644 --- a/config/board.gen3.h +++ b/config/board.gen3.h @@ -228,17 +228,6 @@ DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, AIO0, 0) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.gen6.h b/config/board.gen6.h index 0e8a5e4..883bae9 100644 --- a/config/board.gen6.h +++ b/config/board.gen6.h @@ -229,17 +229,6 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO5, THERMISTOR_EXTRUDER) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.gen7-arm.h b/config/board.gen7-arm.h index 44c48db..afee8dc 100644 --- a/config/board.gen7-arm.h +++ b/config/board.gen7-arm.h @@ -242,17 +242,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, PIO1_0,THERMISTOR_BED) Pins which don't allow PWM are always operated in on/off mode. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.gen7-v1.1-v1.3.h b/config/board.gen7-v1.1-v1.3.h index c68bdef..e4e0b62 100644 --- a/config/board.gen7-v1.1-v1.3.h +++ b/config/board.gen7-v1.1-v1.3.h @@ -238,17 +238,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO2, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.gen7-v1.4.h b/config/board.gen7-v1.4.h index 3b5d1ac..a6574ff 100644 --- a/config/board.gen7-v1.4.h +++ b/config/board.gen7-v1.4.h @@ -239,17 +239,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.melzi.h b/config/board.melzi.h index 61e6f8c..e8c4738 100644 --- a/config/board.melzi.h +++ b/config/board.melzi.h @@ -238,17 +238,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.nanoheart-v1.0.h b/config/board.nanoheart-v1.0.h index b4a4a5a..d98fb98 100644 --- a/config/board.nanoheart-v1.0.h +++ b/config/board.nanoheart-v1.0.h @@ -236,17 +236,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO7, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.pcbscriber.h b/config/board.pcbscriber.h index ebfc35f..4ef416a 100644 --- a/config/board.pcbscriber.h +++ b/config/board.pcbscriber.h @@ -255,17 +255,6 @@ influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.ramps-v1.2.h b/config/board.ramps-v1.2.h index 7d87083..a31c59e 100644 --- a/config/board.ramps-v1.2.h +++ b/config/board.ramps-v1.2.h @@ -235,17 +235,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.ramps-v1.3.h b/config/board.ramps-v1.3.h index eacadf1..fafd2a0 100644 --- a/config/board.ramps-v1.3.h +++ b/config/board.ramps-v1.3.h @@ -240,17 +240,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.rumba.h b/config/board.rumba.h index 458b569..ede906b 100644 --- a/config/board.rumba.h +++ b/config/board.rumba.h @@ -238,17 +238,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO11, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.sanguinololu-v1.1.h b/config/board.sanguinololu-v1.1.h index 7200168..22c2a93 100644 --- a/config/board.sanguinololu-v1.1.h +++ b/config/board.sanguinololu-v1.1.h @@ -236,17 +236,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.sanguinololu-v1.2.h b/config/board.sanguinololu-v1.2.h index f6278fc..d069182 100644 --- a/config/board.sanguinololu-v1.2.h +++ b/config/board.sanguinololu-v1.2.h @@ -236,17 +236,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.sanguish.h b/config/board.sanguish.h index c8af81e..bd59c50 100644 --- a/config/board.sanguish.h +++ b/config/board.sanguish.h @@ -236,17 +236,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.sinaptec-at328-02.h b/config/board.sinaptec-at328-02.h index af66a0e..7879aec 100644 --- a/config/board.sinaptec-at328-02.h +++ b/config/board.sinaptec-at328-02.h @@ -237,17 +237,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.teensy++-v2.0.h b/config/board.teensy++-v2.0.h index 609c86c..513fb27 100644 --- a/config/board.teensy++-v2.0.h +++ b/config/board.teensy++-v2.0.h @@ -234,17 +234,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.teensy-v2.0.h b/config/board.teensy-v2.0.h index 1391be9..20ce6d0 100644 --- a/config/board.teensy-v2.0.h +++ b/config/board.teensy-v2.0.h @@ -234,17 +234,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/config/board.tronxy.h b/config/board.tronxy.h index cfb9648..dd52954 100644 --- a/config/board.tronxy.h +++ b/config/board.tronxy.h @@ -236,17 +236,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -// #define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START // name pin invert pwm max_pwm diff --git a/configtool/board.generic.h b/configtool/board.generic.h index 5177e2e..5ceb7d3 100644 --- a/configtool/board.generic.h +++ b/configtool/board.generic.h @@ -230,17 +230,6 @@ influenced globally with FAST_PWM, see below. */ -/** \def MAX_PWM_ACTIVE - Enable max_pwm value. - - When you have a heater which has very huge power, you can reduce it. - For example you have a 40W 12V heater and want to use it at 24V. At 24V - the heater has 120W. To reduce it again to 40W set the max_pwm to 25%. - - max_pwm values are allowed between 1 and 100. -*/ -#define MAX_PWM_ACTIVE - //DEFINE_HEATERS_START //DEFINE_HEATERS_END diff --git a/configtool/heaterspage.py b/configtool/heaterspage.py index b4ea085..0feddfa 100644 --- a/configtool/heaterspage.py +++ b/configtool/heaterspage.py @@ -14,8 +14,6 @@ class HeatersPage(wx.Panel, Page): self.font = font self.id = idPg - self.labels = {'MAX_PWM_ACTIVE':"Activate max. PWM [%]"} - sz = wx.GridBagSizer() sz.AddSpacer((30, 30), pos = (0, 0)) @@ -26,13 +24,6 @@ class HeatersPage(wx.Panel, Page): sz.Add(self.lb, pos = (1, 1)) sz.AddSpacer((20, 20), pos = (1, 2)) - k = 'MAX_PWM_ACTIVE' - cb = self.addCheckBox(k, self.onCheckBox) - cb.SetToolTipString("Enable all max. PWM [%] values.") - - sz.Add(cb, pos = (2, 1)) - sz.AddSpacer((20, 20), pos = (2, 2)) - bsz = wx.BoxSizer(wx.VERTICAL) self.bAdd = wx.Button(self, wx.ID_ANY, "Add", size = BSIZESMALL) diff --git a/heater-avr.c b/heater-avr.c index aa09664..7d5dac2 100644 --- a/heater-avr.c +++ b/heater-avr.c @@ -21,17 +21,9 @@ typedef struct { /// Wether the heater pin signal needs to be inverted. uint8_t invert; volatile uint8_t *heater_pwm; ///< pointer to 8-bit PWM register, eg OCR0A (8-bit) or ORC3L (low byte, 16-bit) - #ifdef MAX_PWM_ACTIVE - uint16_t max_value; - #endif + uint16_t max_value; } heater_definition_t; -#ifdef MAX_PWM_ACTIVE - #define HEATER_MAX_VALUE(max_value) (max_value * 64 + 12) / 25) /* scale 100% = 256 */ -#else - #define HEATER_MAX_VALUE(dummy) -#endif - #undef DEFINE_HEATER_ACTUAL /// \brief helper macro to fill heater definition struct from config.h #define DEFINE_HEATER_ACTUAL(name, pin, invert, pwm, max_value) { \ @@ -39,7 +31,7 @@ typedef struct { pin ## _PIN, \ invert ? 1 : 0, \ pwm ? (pin ## _PWM) : NULL, \ - HEATER_MAX_VALUE(max_value)\ + ((max_value * 64 + 12) / 25) \ }, static const heater_definition_t heaters[NUM_HEATERS] = { @@ -225,31 +217,31 @@ void heater_init() { anything done by this function is overwritten by heater_tick above if the heater has an associated temp sensor */ void heater_set(heater_t index, uint8_t value) { - if (index >= NUM_HEATERS) - return; + if (index < NUM_HEATERS) { - #ifdef MAX_PWM_ACTIVE - value = (uint8_t)((heaters[index].max_value * value + 128) / 256); - #endif - heaters_runtime[index].heater_output = value; + heaters_runtime[index].heater_output = value; - if (heaters[index].heater_pwm) { - *(heaters[index].heater_pwm) = heaters[index].invert ? - (255 - value) : value; + if (heaters[index].heater_pwm) { + + value = (uint8_t)((heaters[index].max_value * value) / 256); - if (DEBUG_PID && (debug_flags & DEBUG_PID)) - sersendf_P(PSTR("PWM{%u = %u}\n"), index, *heaters[index].heater_pwm); - } - else { - if ((value >= HEATER_THRESHOLD && ! heaters[index].invert) || - (value < HEATER_THRESHOLD && heaters[index].invert)) - *(heaters[index].heater_port) |= MASK(heaters[index].heater_pin); - else - *(heaters[index].heater_port) &= ~MASK(heaters[index].heater_pin); - } + *(heaters[index].heater_pwm) = heaters[index].invert ? + (255 - value) : value; - if (value) - power_on(); + if (DEBUG_PID && (debug_flags & DEBUG_PID)) + sersendf_P(PSTR("PWM{%u = %u}\n"), index, *heaters[index].heater_pwm); + } + else { + if ((value >= HEATER_THRESHOLD && ! heaters[index].invert) || + (value < HEATER_THRESHOLD && heaters[index].invert)) + *(heaters[index].heater_port) |= MASK(heaters[index].heater_pin); + else + *(heaters[index].heater_port) &= ~MASK(heaters[index].heater_pin); + } + + if (value) + power_on(); + } } #endif /* defined TEACUP_C_INCLUDE && defined __AVR__ */ diff --git a/heater-lpc.c b/heater-lpc.c index 2b1fd30..871d142 100644 --- a/heater-lpc.c +++ b/heater-lpc.c @@ -51,11 +51,7 @@ frequency, so you should bother about PWM_SCALE only of you need frequencies below 3 Hz. */ -#ifndef MAX_PWM_ACTIVE - #define PWM_SCALE 255 -#else - #define PWM_SCALE 1020 -#endif +#define PWM_SCALE 255 /** \struct heater_definition_t @@ -70,26 +66,18 @@ typedef struct { /// Pointer to the port for non-PWM pins. __IO uint32_t* masked_port; }; - #ifdef MAX_PWM_ACTIVE uint16_t max_value; - #endif uint8_t uses_pwm; uint8_t invert; } heater_definition_t; -#ifdef MAX_PWM_ACTIVE - #define HEATER_MAX_VALUE(max_value) (max_value * 64 + 12) / 25), /* scale 100% = 256 */ -#else - #define HEATER_MAX_VALUE(dummy) -#endif - #undef DEFINE_HEATER_ACTUAL #define DEFINE_HEATER_ACTUAL(name, pin, invert, pwm, max_value) \ { \ { pwm && pin ## _TIMER ? \ &(pin ## _TIMER->MR[pin ## _MATCH]) : \ &(pin ## _PORT->MASKED_ACCESS[MASK(pin ## _PIN)]) }, \ - HEATER_MAX_VALUE(max_value) /*no comma here!*/ \ + ((max_value * 64 + 12) / 25), \ pwm && pin ## _TIMER, \ invert ? 1 : 0 \ }, @@ -144,7 +132,7 @@ void heater_init() { */ // Auto-generate pin setup. #undef DEFINE_HEATER_ACTUAL - #define DEFINE_HEATER_ACTUAL(name, pin, invert, pwm, max_value) \ + #define DEFINE_HEATER_ACTUAL(name, pin, invert, pwm, ...) \ if (pwm && pin ## _TIMER) { \ uint32_t freq; \ \ @@ -209,11 +197,8 @@ void heater_set(heater_t index, uint8_t value) { uint32_t pwm_value; // Remember, we scale, and the timer inverts already. - #ifdef MAX_PWM_ACTIVE pwm_value = (uint32_t)((heaters[index].max_value * value) * (PWM_SCALE / 255) / 256); - #else - pwm_value = (uint32_t)value * (PWM_SCALE / 255); - #endif + if ( ! heaters[index].invert) pwm_value = PWM_SCALE - pwm_value; *heaters[index].match = pwm_value;