From be6ca4c857ded39dbb9ed25fbcdc70bff89c7e16 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 12 Aug 2015 21:42:09 +0200 Subject: [PATCH] ARM, AVR: support inverted heater pin signals. Implemented and tested for both platforms. This is quite a big commit. Unlike with the previous changes to now choosable PWM frequencies, all board configuration files and Configtool had to be changed immediately to deal with the additional parameter in DEFINE_HEATER() and keep AVR builds working (and regression tests passing). --- config/board.3drag.h | 11 +++++++---- config/board.cnc-shield-v3.h | 7 +++++-- config/board.gen3.h | 5 ++++- config/board.gen6.h | 7 +++++-- config/board.gen7-arm.h | 13 ++++++++----- config/board.gen7-v1.1-v1.3.h | 9 ++++++--- config/board.gen7-v1.4.h | 9 ++++++--- config/board.nanoheart-v1.0.h | 9 ++++++--- 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 | 9 ++++++--- config/board.sanguinololu-v1.2.h | 9 ++++++--- config/board.sanguish.h | 9 ++++++--- config/board.teensy++-v2.0.h | 11 +++++++---- config/board.teensy-v2.0.h | 11 +++++++---- configtool/addheaterdlg.py | 17 +++++++++++++++-- configtool/board.generic.h | 3 +++ configtool/boardpanel.py | 20 +++++++++++++++----- configtool/data.py | 4 +++- configtool/heaterlist.py | 15 +++++++++++---- configtool/heaterspage.py | 2 +- heater-arm.c | 27 +++++++++++++++++++-------- heater-avr.c | 32 ++++++++++++++++++++++++++------ heater.c | 18 ++++++++++++++++++ heater.h | 2 +- testcases/config.h.Profiling | 9 ++++++--- 27 files changed, 218 insertions(+), 83 deletions(-) diff --git a/config/board.3drag.h b/config/board.3drag.h index ee1cc96..a8528cd 100644 --- a/config/board.3drag.h +++ b/config/board.3drag.h @@ -211,6 +211,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -220,10 +223,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO10, 1) -DEFINE_HEATER(bed, DIO9, 1) -DEFINE_HEATER(fan, DIO8, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO10, 0, 1) +DEFINE_HEATER(bed, DIO9, 0, 1) +DEFINE_HEATER(fan, DIO8, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.cnc-shield-v3.h b/config/board.cnc-shield-v3.h index 42d0d47..1c30c21 100644 --- a/config/board.cnc-shield-v3.h +++ b/config/board.cnc-shield-v3.h @@ -211,6 +211,9 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO3, THERMISTOR_EXTRUDER) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -220,8 +223,8 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO3, THERMISTOR_EXTRUDER) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, AIO2, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, AIO2, 0, 1) #define HEATER_EXTRUDER HEATER_extruder //DEFINE_HEATERS_END diff --git a/config/board.gen3.h b/config/board.gen3.h index 46436eb..2c5a0f2 100644 --- a/config/board.gen3.h +++ b/config/board.gen3.h @@ -204,6 +204,9 @@ DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, AIO0, 0) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -213,7 +216,7 @@ DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, AIO0, 0) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm +// name pin invert pwm //DEFINE_HEATERS_END diff --git a/config/board.gen6.h b/config/board.gen6.h index 3b00851..9c5630e 100644 --- a/config/board.gen6.h +++ b/config/board.gen6.h @@ -206,6 +206,9 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO5, THERMISTOR_EXTRUDER) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -215,8 +218,8 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO5, THERMISTOR_EXTRUDER) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO6, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO6, 0, 1) #define HEATER_EXTRUDER HEATER_extruder //DEFINE_HEATERS_END diff --git a/config/board.gen7-arm.h b/config/board.gen7-arm.h index fe9fc26..62a2668 100644 --- a/config/board.gen7-arm.h +++ b/config/board.gen7-arm.h @@ -164,7 +164,7 @@ //DEFINE_TEMP_SENSORS_START // name type pin additional DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PIO1_0,THERMISTOR_EXTRUDER) -//DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, PIO1_1,THERMISTOR_BED) +DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, PIO1_1,THERMISTOR_BED) // Beta algorithm r0 beta r2 vadc // Steinhart-Hart rp t0 r0 t1 r1 t2 r2 @@ -210,6 +210,9 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PIO1_0,THERMISTOR_EXTRUDER) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... frequency in Hertz (Hz) on ARM based controllers to set PWM frequency of this pin's output. Frequency isn't always accurate, Teacup @@ -228,12 +231,12 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PIO1_0,THERMISTOR_EXTRUDER) Pins which don't allow PWM are always operated in on/off mode. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, PIO0_10, 20000) -//DEFINE_HEATER(bed, PIO0_11, 10) +// name pin invert pwm +DEFINE_HEATER(extruder, PIO0_10, 0, 20000) +DEFINE_HEATER(bed, PIO0_11, 1, 10) #define HEATER_EXTRUDER HEATER_extruder -//#define HEATER_BED HEATER_bed +#define HEATER_BED HEATER_bed //DEFINE_HEATERS_END diff --git a/config/board.gen7-v1.1-v1.3.h b/config/board.gen7-v1.1-v1.3.h index aa77a20..db3387e 100644 --- a/config/board.gen7-v1.1-v1.3.h +++ b/config/board.gen7-v1.1-v1.3.h @@ -215,6 +215,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO2, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -224,9 +227,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO2, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO4, 1) -DEFINE_HEATER(bed, DIO3, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO4, 0, 1) +DEFINE_HEATER(bed, DIO3, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.gen7-v1.4.h b/config/board.gen7-v1.4.h index fc58d84..93df06e 100644 --- a/config/board.gen7-v1.4.h +++ b/config/board.gen7-v1.4.h @@ -216,6 +216,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -225,9 +228,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO4, 1) -DEFINE_HEATER(bed, DIO3, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO4, 0, 1) +DEFINE_HEATER(bed, DIO3, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.nanoheart-v1.0.h b/config/board.nanoheart-v1.0.h index a17f59b..07f2bb7 100644 --- a/config/board.nanoheart-v1.0.h +++ b/config/board.nanoheart-v1.0.h @@ -213,6 +213,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO7, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -222,9 +225,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO7, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO11, 1) -DEFINE_HEATER(bed, DIO3, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO11, 0, 1) +DEFINE_HEATER(bed, DIO3, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.ramps-v1.2.h b/config/board.ramps-v1.2.h index b1e5336..2d2eac4 100644 --- a/config/board.ramps-v1.2.h +++ b/config/board.ramps-v1.2.h @@ -212,6 +212,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -221,10 +224,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO10, 1) -DEFINE_HEATER(bed, DIO8, 1) -DEFINE_HEATER(fan, DIO9, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO10, 0, 1) +DEFINE_HEATER(bed, DIO8, 0, 1) +DEFINE_HEATER(fan, DIO9, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.ramps-v1.3.h b/config/board.ramps-v1.3.h index 255a7bf..5191ccc 100644 --- a/config/board.ramps-v1.3.h +++ b/config/board.ramps-v1.3.h @@ -215,6 +215,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -224,10 +227,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO10, 1) -DEFINE_HEATER(bed, DIO8, 1) -DEFINE_HEATER(fan, DIO9, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO10, 0, 1) +DEFINE_HEATER(bed, DIO8, 0, 1) +DEFINE_HEATER(fan, DIO9, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.rumba.h b/config/board.rumba.h index c97cf90..766b134 100644 --- a/config/board.rumba.h +++ b/config/board.rumba.h @@ -215,6 +215,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO11, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -224,10 +227,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO11, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO2, 1) -DEFINE_HEATER(bed, DIO9, 1) -DEFINE_HEATER(fan, DIO8, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO2, 0, 1) +DEFINE_HEATER(bed, DIO9, 0, 1) +DEFINE_HEATER(fan, DIO8, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.sanguinololu-v1.1.h b/config/board.sanguinololu-v1.1.h index ab512a3..31d66a2 100644 --- a/config/board.sanguinololu-v1.1.h +++ b/config/board.sanguinololu-v1.1.h @@ -213,6 +213,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -222,9 +225,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO13, 1) -DEFINE_HEATER(bed, DIO14, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO13, 0, 1) +DEFINE_HEATER(bed, DIO14, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.sanguinololu-v1.2.h b/config/board.sanguinololu-v1.2.h index c287539..ebca784 100644 --- a/config/board.sanguinololu-v1.2.h +++ b/config/board.sanguinololu-v1.2.h @@ -213,6 +213,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -222,9 +225,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO12, 1) -DEFINE_HEATER(bed, DIO13, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO12, 0, 1) +DEFINE_HEATER(bed, DIO13, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.sanguish.h b/config/board.sanguish.h index e60dc24..0514d3a 100644 --- a/config/board.sanguish.h +++ b/config/board.sanguish.h @@ -213,6 +213,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -222,9 +225,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO3, 1) -DEFINE_HEATER(bed, DIO4, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO3, 0, 1) +DEFINE_HEATER(bed, DIO4, 0, 1) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.teensy++-v2.0.h b/config/board.teensy++-v2.0.h index fde084c..906454b 100644 --- a/config/board.teensy++-v2.0.h +++ b/config/board.teensy++-v2.0.h @@ -211,6 +211,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -220,10 +223,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO15, 1) -DEFINE_HEATER(bed, DIO14, 1) -DEFINE_HEATER(fan, DIO16, 0) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO15, 0, 1) +DEFINE_HEATER(bed, DIO14, 0, 1) +DEFINE_HEATER(fan, DIO16, 0, 0) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.teensy-v2.0.h b/config/board.teensy-v2.0.h index 4d2200c..2f27d50 100644 --- a/config/board.teensy-v2.0.h +++ b/config/board.teensy-v2.0.h @@ -211,6 +211,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. @@ -220,10 +223,10 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name port pwm -DEFINE_HEATER(extruder, DIO10, 1) -DEFINE_HEATER(bed, DIO9, 1) -DEFINE_HEATER(fan, DIO8, 0) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO10, 0, 1) +DEFINE_HEATER(bed, DIO9, 0, 1) +DEFINE_HEATER(fan, DIO8, 0, 0) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/configtool/addheaterdlg.py b/configtool/addheaterdlg.py index c7d2924..753ea16 100644 --- a/configtool/addheaterdlg.py +++ b/configtool/addheaterdlg.py @@ -5,7 +5,7 @@ from configtool.data import BSIZESMALL, offsetChLabel, offsetTcLabel class AddHeaterDlg(wx.Dialog): def __init__(self, parent, names, pins, font, - name = "", pin = "", pwm = "1"): + name = "", pin = "", invert = "0", pwm = "1"): wx.Dialog.__init__(self, parent, wx.ID_ANY, "Add heater", size = (400, 204)) self.SetFont(font) self.Bind(wx.EVT_CLOSE, self.onCancel) @@ -54,6 +54,13 @@ class AddHeaterDlg(wx.Dialog): gsz.Add(lsz, pos = (3, 1)) + self.cbInv = wx.CheckBox(self, wx.ID_ANY, "Invert") + self.cbInv.SetFont(font) + self.cbInv.SetValue(int(invert) != 0) + self.cbInv.SetToolTipString("Invert the pin signal.") + + gsz.Add(self.cbInv, pos = (3, 3)) + self.cbPwm = wx.CheckBox(self, wx.ID_ANY, "PWM") self.cbPwm.SetFont(font) self.cbPwm.SetValue(int(pwm) != 0) @@ -120,12 +127,18 @@ class AddHeaterDlg(wx.Dialog): def getValues(self): nm = self.tcName.GetValue() pin = self.choices[self.chPin.GetSelection()] + + if self.cbInv.IsChecked(): + invert = "1" + else: + invert = "0" + if self.cbPwm.IsChecked(): pwm = "1" else: pwm = "0" - return (nm, pin, pwm) + return (nm, pin, invert, pwm) def onSave(self, evt): self.EndModal(wx.ID_OK) diff --git a/configtool/board.generic.h b/configtool/board.generic.h index 071f8a1..aa5004a 100644 --- a/configtool/board.generic.h +++ b/configtool/board.generic.h @@ -207,6 +207,9 @@ are defined or the order of the definitions differs. The first defined device has the index 0 (zero). + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + Set 'pwm' to ... 1 for using PWM on a PWM-able pin and on/off on other pins. 0 for using on/off on a PWM-able pin, too. diff --git a/configtool/boardpanel.py b/configtool/boardpanel.py index 286a06e..de9cf4a 100644 --- a/configtool/boardpanel.py +++ b/configtool/boardpanel.py @@ -13,7 +13,7 @@ from configtool.data import (defineValueFormat, reCandProcessors, reCandCPUClocks, reFloatAttr, reDefine, reDefineBL, reDefQS, reDefQSm, reDefQSm2, reDefBool, reDefBoolBL, reDefHT, - reDefTS, reDefTT, reSensor, reHeater, + reDefTS, reDefTT, reSensor, reHeater3, reHeater4, reTempTable4, reTempTable7) from configtool.pinoutspage import PinoutsPage from configtool.sensorpage import SensorsPage @@ -468,11 +468,20 @@ class BoardPanel(wx.Panel): return None def parseHeater(self, s): - m = reHeater.search(s) + m = reHeater4.search(s) + if m: + t = m.groups() + if len(t) == 4: + return list(t) + # reHeater3 deprecated, for compatibility with old config files only. + m = reHeater3.search(s) if m: t = m.groups() if len(t) == 3: - return list(t) + t = list(t) + t.insert(2, '0') + return t + # End of deprecated part. return None def parseTempTable(self, s): @@ -604,9 +613,10 @@ class BoardPanel(wx.Panel): m = reStartHeaters.match(ln) if m: fp.write(ln) - fp.write("// name port pwm\n") + fp.write("// name pin invert pwm\n") for s in self.heaters: - sstr = "%-10s%-7s%s" % ((s[0] + ","), (s[1] + ","), s[2]) + sstr = "%-10s%-9s%-8s%s" % ((s[0] + ","), (s[1] + ","), + (s[2] + ","), s[3]) fp.write("DEFINE_HEATER(%s)\n" % sstr) fp.write("\n") for s in self.heaters: diff --git a/configtool/data.py b/configtool/data.py index 1086f86..eb5742a 100644 --- a/configtool/data.py +++ b/configtool/data.py @@ -57,7 +57,9 @@ reHelpTextEnd = re.compile("^\s*\*/") reHelpText = re.compile("/\*\*.*?\*/\r?\n", re.DOTALL) reSensor = re.compile(".*\\(\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*\\)") -reHeater = re.compile(".*\\(\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*\\)") +# reHeater3 deprecated, for compatibility with old config files only. +reHeater3 = re.compile(".*\\(\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*\\)") +reHeater4 = re.compile(".*\\(\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*\\)") reTempTable4 = re.compile(".*\\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d*.?\d*)\s*\\)") reTempTable7 = re.compile(".*\\(\s*(\d+)\s*,\s*(\d*.?\d*)\s*,\s*(\d+)\s*,\s*(\d*.?\d*)\s*,\s*(\d+)\s*,\s*(\d*.?\d*)\s*,\s*(\d+)\s*\\)") diff --git a/configtool/heaterlist.py b/configtool/heaterlist.py index 2b709a3..094c9c5 100644 --- a/configtool/heaterlist.py +++ b/configtool/heaterlist.py @@ -7,7 +7,7 @@ class HeaterList(wx.ListCtrl): self.parent = parent self.currentItem = None wx.ListCtrl.__init__(self, parent, wx.ID_ANY, - size = (95 + 55 + 55 + 4, 100), + size = (95 + 75 + 55 + 55 + 4, 100), style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES) self.SetFont(font) @@ -17,10 +17,12 @@ class HeaterList(wx.ListCtrl): self.InsertColumn(0, "Name") self.InsertColumn(1, "Pin") - self.InsertColumn(2, "PWM") + self.InsertColumn(2, "Invert") + self.InsertColumn(3, "PWM") self.SetColumnWidth(0, 95) - self.SetColumnWidth(1, 55) + self.SetColumnWidth(1, 75) self.SetColumnWidth(2, 55) + self.SetColumnWidth(3, 55) self.SetItemCount(0) @@ -64,7 +66,7 @@ class HeaterList(wx.ListCtrl): def OnGetItemText(self, item, col): if item < 0 or item >= len(self.heaterList): - return "Error - no heaters" + return "Error - no heaters." s = self.heaterList[item] @@ -77,3 +79,8 @@ class HeaterList(wx.ListCtrl): return "True" else: return "False" + elif col == 3: + if int(s[3]): + return "True" + else: + return "False" diff --git a/configtool/heaterspage.py b/configtool/heaterspage.py index 181d19c..ce98559 100644 --- a/configtool/heaterspage.py +++ b/configtool/heaterspage.py @@ -116,7 +116,7 @@ class HeatersPage(wx.Panel, Page): h = self.heaters[self.selection] dlg = AddHeaterDlg(self, nm, [h[1]] + self.getFreePins(), self.font, - name = h[0], pin = h[1], pwm = h[2]) + name = h[0], pin = h[1], invert = h[2], pwm = h[3]) rc = dlg.ShowModal() if rc == wx.ID_OK: ht = dlg.getValues() diff --git a/heater-arm.c b/heater-arm.c index 690245c..27f0f99 100644 --- a/heater-arm.c +++ b/heater-arm.c @@ -1,6 +1,8 @@ /** \file \brief Manage heaters, including PID and PWM, ARM specific part. + + For test cases see the intro comment in heater.c. */ #if defined TEACUP_C_INCLUDE && defined __ARMEL__ @@ -65,16 +67,18 @@ typedef struct { __IO uint32_t* masked_port; }; uint8_t uses_pwm; + uint8_t invert; } heater_definition_t; #undef DEFINE_HEATER -#define DEFINE_HEATER(name, pin, pwm) \ +#define DEFINE_HEATER(name, pin, invert, pwm) \ { \ { pwm && pin ## _TIMER ? \ &(pin ## _TIMER->MR[pin ## _MATCH]) : \ &(pin ## _PORT->MASKED_ACCESS[MASK(pin ## _PIN)]) }, \ - pwm && pin ## _TIMER \ + pwm && pin ## _TIMER, \ + invert ? 1 : 0 \ }, static const heater_definition_t heaters[NUM_HEATERS] = { #include "config_wrapper.h" @@ -127,7 +131,7 @@ void heater_init() { */ // Auto-generate pin setup. #undef DEFINE_HEATER - #define DEFINE_HEATER(name, pin, pwm) \ + #define DEFINE_HEATER(name, pin, invert, pwm) \ if (pwm && pin ## _TIMER) { \ uint32_t freq; \ \ @@ -154,7 +158,7 @@ void heater_init() { /* PWM_SCALE - 1, so match = 255 is full off. */ \ pin ## _TIMER->MR[3] = PWM_SCALE - 1; /* Match 3 at 254. */ \ pin ## _TIMER->MR[pin ## _MATCH] = /* Match pin = duty. */ \ - PWM_SCALE; \ + invert ? 0 : PWM_SCALE; \ /*pin ## _TIMER->CCR = 0; ( = reset value) No pin capture. */ \ pin ## _TIMER->EMR |= ((1 << pin ## _MATCH) /* Connect to pin. */ \ | (0x03 << ((pin ## _MATCH * 2) + 4))); /* Toggle pin on match.*/ \ @@ -164,7 +168,7 @@ void heater_init() { } \ else { \ SET_OUTPUT(pin); \ - WRITE(pin, 0); \ + WRITE(pin, invert ? 1 : 0); \ } #include "config_wrapper.h" #undef DEFINE_HEATER @@ -191,15 +195,22 @@ void heater_set(heater_t index, uint8_t value) { heaters_runtime[index].heater_output = value; if (heaters[index].uses_pwm) { - // Remember, we scale, and duty cycle is inverted. - *heaters[index].match = PWM_SCALE - ((uint32_t)value * (PWM_SCALE / 255)); + uint32_t pwm_value; + + // Remember, we scale, and the timer inverts already. + pwm_value = (uint32_t)value * (PWM_SCALE / 255); + if ( ! heaters[index].invert) + pwm_value = PWM_SCALE - pwm_value; + *heaters[index].match = pwm_value; if (DEBUG_PID && (debug_flags & DEBUG_PID)) sersendf_P(PSTR("PWM %su = %lu\n"), index, *heaters[index].match); } else { *(heaters[index].masked_port) = - (value >= HEATER_THRESHOLD) ? 0xFFFF : 0x0000; + ((value >= HEATER_THRESHOLD && ! heaters[index].invert) || + (value < HEATER_THRESHOLD && heaters[index].invert)) ? + 0xFFFF : 0x0000; } if (value) diff --git a/heater-avr.c b/heater-avr.c index 663f5ac..993b7cf 100644 --- a/heater-avr.c +++ b/heater-avr.c @@ -1,6 +1,8 @@ /** \file \brief Manage heaters, including PID and PWM, AVR specific part. + + For test cases see the intro comment in heater.c. */ #if defined TEACUP_C_INCLUDE && defined __AVR__ @@ -16,13 +18,15 @@ typedef struct { volatile uint8_t *heater_port; ///< pointer to port. DDR is inferred from this pointer too uint8_t heater_pin; ///< heater pin, not masked. eg for PB3 enter '3' here, or PB3_PIN or similar + /// 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) } heater_definition_t; #undef DEFINE_HEATER /// \brief helper macro to fill heater definition struct from config.h -#define DEFINE_HEATER(name, pin, pwm) { &(pin ## _WPORT), pin ## _PIN, \ - pwm ? (pin ## _PWM) : NULL}, +#define DEFINE_HEATER(name, pin, invert, pwm) { \ + &(pin ## _WPORT), pin ## _PIN, invert ? 1 : 0, pwm ? (pin ## _PWM) : NULL}, static const heater_definition_t heaters[NUM_HEATERS] = { #include "config_wrapper.h" @@ -102,10 +106,22 @@ void heater_init() { OCR5B = 0; #endif + /** + - - TODO - - - TODO - - - TODO - - - TODO - - + + This produces a lot of initialisation code for setting up just 2 or 3 + pins. Can't be optimized out, because heaters[] could have been changed + since initialisation. + + A much better strategy for this is the one found in heaters-arm.c: use + the config_wrapper.h magic to initialise only what's needed. The needed + values are likely already in arduino_xxx.h. + */ + // setup pins for (i = 0; i < NUM_HEATERS; i++) { if (heaters[i].heater_pwm) { - *heaters[i].heater_pwm = 0; + *heaters[i].heater_pwm = heaters[i].invert ? 255 : 0; // this is somewhat ugly too, but switch() won't accept pointers for reasons unknown switch((uint16_t) heaters[i].heater_pwm) { case (uint16_t) &OCR0A: @@ -180,7 +196,9 @@ void heater_init() { // set all heater pins to output #undef DEFINE_HEATER - #define DEFINE_HEATER(name, pin, pwm) SET_OUTPUT(pin); WRITE(pin, 0); + #define DEFINE_HEATER(name, pin, invert, pwm) \ + SET_OUTPUT(pin); \ + WRITE(pin, invert ? 1 : 0); #include "config_wrapper.h" #undef DEFINE_HEATER } @@ -198,13 +216,15 @@ void heater_set(heater_t index, uint8_t value) { heaters_runtime[index].heater_output = value; if (heaters[index].heater_pwm) { - *(heaters[index].heater_pwm) = value; + *(heaters[index].heater_pwm) = heaters[index].invert ? + (255 - value) : value; if (DEBUG_PID && (debug_flags & DEBUG_PID)) sersendf_P(PSTR("PWM{%u = %u}\n"), index, *heaters[index].heater_pwm); } else { - if (value >= HEATER_THRESHOLD) + 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); diff --git a/heater.c b/heater.c index 43617ef..cf1bfba 100644 --- a/heater.c +++ b/heater.c @@ -1,6 +1,24 @@ /** \file \brief Manage heaters, including PID and PWM. + + Code for heater_init() and heater_set() is in the platform dependant include + file and should pass six test cases when operating the heater via M106, temp + sensors disabled: + + - PWM used on PWM-able pin, not inverted. + - PWM pin used as on/off pin, not inverted. + - Non-PWM-able pin, not inverted. + - The three above, but inverted. + + In each test it should pass these tests: + + - Heater full on with M106 S255. + - Heater full off with M106 S0. + - Heater 10% on with M106 S25 on PWM pins. + - Heater full off after reset, power supply turned on by other means. + - For testing the inverted cases it's OK to check for behaving the opposite + of the M106 command. */ #include "heater.h" diff --git a/heater.h b/heater.h index 73a41ba..39ffc8c 100644 --- a/heater.h +++ b/heater.h @@ -31,7 +31,7 @@ #undef DEFINE_HEATER -#define DEFINE_HEATER(name, pin, pwm) HEATER_ ## name, +#define DEFINE_HEATER(name, pin, invert, pwm) HEATER_ ## name, typedef enum { #include "config_wrapper.h" diff --git a/testcases/config.h.Profiling b/testcases/config.h.Profiling index 3c78b86..dea3740 100644 --- a/testcases/config.h.Profiling +++ b/testcases/config.h.Profiling @@ -447,6 +447,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_EXTRUDER) * are defined or the order of the definitions differs. The first defined * * device has the index 0 (zero). * * * +* Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin * +* signal for this pin, e.g. for a MOSFET with a driver. * +* * * Set 'pwm' to ... * * 1 for using PWM on a PWM-able pin and on/off on other pins. * * 0 for using on/off on a PWM-able pin, too. * @@ -460,9 +463,9 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_EXTRUDER) #define DEFINE_HEATER(...) #endif -// name port pwm -DEFINE_HEATER(extruder, DIO4, 1) -DEFINE_HEATER(bed, DIO3, 1) +// name pin invert pwm +DEFINE_HEATER(extruder, DIO4, 0, 1) +DEFINE_HEATER(bed, DIO3, 0, 1) /// and now because the c preprocessor isn't as smart as it could be, /// uncomment the ones you've listed above and comment the rest.