From f8c78e63848076a1978ff4c4fa40bdc7623a8332 Mon Sep 17 00:00:00 2001 From: Nico Tonnhofer Date: Wed, 1 Mar 2017 21:46:52 +0100 Subject: [PATCH] heaters: add max heater value You can reduce the max. power of each heater. With the max_pwm value between 1 and 100% you reduce the active pwm. For example you could reduce the power of your hotend. My hotend for example is 12V 30W but connected to 24V. So it has normally 120W. This is very huge. Setting the max_pwm to 25, it has again ~30W. --- config/board.3drag.h | 21 +++++++++--- config/board.cnc-shield-v3-nucleo.h | 4 +-- config/board.cnc-shield-v3.h | 17 ++++++++-- config/board.gen3.h | 15 ++++++++- config/board.gen6.h | 17 ++++++++-- config/board.gen7-arm.h | 19 +++++++++-- config/board.gen7-v1.1-v1.3.h | 19 +++++++++-- config/board.gen7-v1.4.h | 19 +++++++++-- config/board.melzi.h | 21 +++++++++--- config/board.nanoheart-v1.0.h | 19 +++++++++-- config/board.pcbscriber.h | 17 ++++++++-- config/board.ramps-v1.2.h | 21 +++++++++--- config/board.ramps-v1.3.h | 21 +++++++++--- config/board.rumba.h | 21 +++++++++--- config/board.sanguinololu-v1.1.h | 19 +++++++++-- config/board.sanguinololu-v1.2.h | 19 +++++++++-- config/board.sanguish.h | 19 +++++++++-- config/board.sinaptec-at328-02.h | 21 +++++++++--- config/board.teensy++-v2.0.h | 21 +++++++++--- config/board.teensy-v2.0.h | 21 +++++++++--- config/board.tronxy.h | 21 +++++++++--- configtool/addheaterdlg.py | 48 ++++++++++++++++++++++++--- configtool/board.generic.h | 12 +++++++ configtool/board.py | 19 ++++++++--- configtool/data.py | 3 +- configtool/heaterlist.py | 6 +++- configtool/heaterspage.py | 11 +++++- heater-avr.c | 23 +++++++++++-- heater-lpc.c | 23 +++++++++++-- heater.h | 2 +- testcases/board.regtest-no-endstops.h | 4 +-- testcases/config.h.Profiling | 17 ++++++++-- 32 files changed, 471 insertions(+), 89 deletions(-) diff --git a/config/board.3drag.h b/config/board.3drag.h index 46f3c45..0deb584 100644 --- a/config/board.3drag.h +++ b/config/board.3drag.h @@ -237,11 +237,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO10, 0, 1) -DEFINE_HEATER(bed, DIO9, 0, 1) -DEFINE_HEATER(fan, DIO8, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO10, 0, 1, 100) +DEFINE_HEATER(bed, DIO9, 0, 1, 100) +DEFINE_HEATER(fan, DIO8, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.cnc-shield-v3-nucleo.h b/config/board.cnc-shield-v3-nucleo.h index d91576f..712087f 100644 --- a/config/board.cnc-shield-v3-nucleo.h +++ b/config/board.cnc-shield-v3-nucleo.h @@ -235,8 +235,8 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PB_0, THERMISTOR_EXTRUDER) influenced globally with FAST_PWM, see below. */ //DEFINE_HEATERS_START -// name pin invert pwm -DEFINE_HEATER(extruder, PA_5, 0, 10000) +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, PA_5, 0, 10000, 100) #define HEATER_EXTRUDER HEATER_extruder //DEFINE_HEATERS_END diff --git a/config/board.cnc-shield-v3.h b/config/board.cnc-shield-v3.h index 38eb6e7..078dea2 100644 --- a/config/board.cnc-shield-v3.h +++ b/config/board.cnc-shield-v3.h @@ -237,9 +237,22 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO3, THERMISTOR_EXTRUDER) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, AIO2, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, AIO2, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder //DEFINE_HEATERS_END diff --git a/config/board.gen3.h b/config/board.gen3.h index 4dfb42c..6764a97 100644 --- a/config/board.gen3.h +++ b/config/board.gen3.h @@ -231,8 +231,21 @@ DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, AIO0, 0) with slow switches, like solid state relays. PWM frequency can be 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 + +// name pin invert pwm max_pwm //DEFINE_HEATERS_END diff --git a/config/board.gen6.h b/config/board.gen6.h index 1330ac9..dcc9103 100644 --- a/config/board.gen6.h +++ b/config/board.gen6.h @@ -232,9 +232,22 @@ DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO5, THERMISTOR_EXTRUDER) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO6, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO6, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder //DEFINE_HEATERS_END diff --git a/config/board.gen7-arm.h b/config/board.gen7-arm.h index ca87925..2c4da4e 100644 --- a/config/board.gen7-arm.h +++ b/config/board.gen7-arm.h @@ -245,10 +245,23 @@ 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 -DEFINE_HEATER(extruder, PIO0_10, 0, 20000) -DEFINE_HEATER(bed, PIO1_9, 1, 10) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, PIO0_10, 0, 20000, 100) +DEFINE_HEATER(bed, PIO1_9, 1, 10, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.gen7-v1.1-v1.3.h b/config/board.gen7-v1.1-v1.3.h index 58d6b90..8187c52 100644 --- a/config/board.gen7-v1.1-v1.3.h +++ b/config/board.gen7-v1.1-v1.3.h @@ -241,10 +241,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO2, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO4, 0, 1) -DEFINE_HEATER(bed, DIO3, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO4, 0, 1, 100) +DEFINE_HEATER(bed, DIO3, 0, 1, 100) #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 e1d85bd..ab3e385 100644 --- a/config/board.gen7-v1.4.h +++ b/config/board.gen7-v1.4.h @@ -242,10 +242,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO4, 0, 1) -DEFINE_HEATER(bed, DIO3, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO4, 0, 1, 100) +DEFINE_HEATER(bed, DIO3, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.melzi.h b/config/board.melzi.h index 37aaf30..e12a710 100644 --- a/config/board.melzi.h +++ b/config/board.melzi.h @@ -241,11 +241,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO13, 0, 1) -DEFINE_HEATER(bed, DIO12, 0, 1) -DEFINE_HEATER(fan, DIO4, 0, 0) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO13, 0, 1, 100) +DEFINE_HEATER(bed, DIO12, 0, 1, 100) +DEFINE_HEATER(fan, DIO4, 0, 0, 100) #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 788836b..2070cf8 100644 --- a/config/board.nanoheart-v1.0.h +++ b/config/board.nanoheart-v1.0.h @@ -239,10 +239,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO7, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO11, 0, 1) -DEFINE_HEATER(bed, DIO3, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO11, 0, 1, 100) +DEFINE_HEATER(bed, DIO3, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.pcbscriber.h b/config/board.pcbscriber.h index 1fb1f73..875af5b 100644 --- a/config/board.pcbscriber.h +++ b/config/board.pcbscriber.h @@ -258,9 +258,22 @@ with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(drill, DIO16, 0, 0) + +// name pin invert pwm max_pwm +DEFINE_HEATER(drill, DIO16, 0, 0, 100) #define HEATER_DRILL HEATER_drill //DEFINE_HEATERS_END diff --git a/config/board.ramps-v1.2.h b/config/board.ramps-v1.2.h index f1cdfa7..d0d6322 100644 --- a/config/board.ramps-v1.2.h +++ b/config/board.ramps-v1.2.h @@ -238,11 +238,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO10, 0, 1) -DEFINE_HEATER(bed, DIO8, 0, 1) -DEFINE_HEATER(fan, DIO9, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO10, 0, 1, 100) +DEFINE_HEATER(bed, DIO8, 0, 1, 100) +DEFINE_HEATER(fan, DIO9, 0, 1, 100) #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 7bb57ce..9f2c329 100644 --- a/config/board.ramps-v1.3.h +++ b/config/board.ramps-v1.3.h @@ -243,11 +243,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO14, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO10, 0, 1) -DEFINE_HEATER(bed, DIO8, 0, 1) -DEFINE_HEATER(fan, DIO9, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO10, 0, 1, 100) +DEFINE_HEATER(bed, DIO8, 0, 1, 100) +DEFINE_HEATER(fan, DIO9, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.rumba.h b/config/board.rumba.h index c3f1490..433985d 100644 --- a/config/board.rumba.h +++ b/config/board.rumba.h @@ -241,11 +241,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO11, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO2, 0, 1) -DEFINE_HEATER(bed, DIO9, 0, 1) -DEFINE_HEATER(fan, DIO8, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO2, 0, 1, 100) +DEFINE_HEATER(bed, DIO9, 0, 1, 100) +DEFINE_HEATER(fan, DIO8, 0, 1, 100) #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 e0a9889..fd5b8a2 100644 --- a/config/board.sanguinololu-v1.1.h +++ b/config/board.sanguinololu-v1.1.h @@ -239,10 +239,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO13, 0, 1) -DEFINE_HEATER(bed, DIO14, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO13, 0, 1, 100) +DEFINE_HEATER(bed, DIO14, 0, 1, 100) #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 9a2e6e3..20d0317 100644 --- a/config/board.sanguinololu-v1.2.h +++ b/config/board.sanguinololu-v1.2.h @@ -239,10 +239,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO12, 0, 1) -DEFINE_HEATER(bed, DIO13, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO12, 0, 1, 100) +DEFINE_HEATER(bed, DIO13, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.sanguish.h b/config/board.sanguish.h index 0578fca..7c25c59 100644 --- a/config/board.sanguish.h +++ b/config/board.sanguish.h @@ -239,10 +239,23 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO3, 0, 1) -DEFINE_HEATER(bed, DIO4, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO3, 0, 1, 100) +DEFINE_HEATER(bed, DIO4, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.sinaptec-at328-02.h b/config/board.sinaptec-at328-02.h index 6149b6f..f646e1d 100644 --- a/config/board.sinaptec-at328-02.h +++ b/config/board.sinaptec-at328-02.h @@ -240,11 +240,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO3, 0, 1) -DEFINE_HEATER(bed, DIO6, 0, 1) -DEFINE_HEATER(fan, DIO5, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO3, 0, 1, 100) +DEFINE_HEATER(bed, DIO6, 0, 1, 100) +DEFINE_HEATER(fan, DIO5, 0, 1, 100) #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 0d6d4ea..c5d217f 100644 --- a/config/board.teensy++-v2.0.h +++ b/config/board.teensy++-v2.0.h @@ -237,11 +237,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO15, 0, 1) -DEFINE_HEATER(bed, DIO14, 0, 1) -DEFINE_HEATER(fan, DIO16, 0, 0) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO15, 0, 1, 100) +DEFINE_HEATER(bed, DIO14, 0, 1, 100) +DEFINE_HEATER(fan, DIO16, 0, 0, 100) #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 f910a78..2e718e2 100644 --- a/config/board.teensy-v2.0.h +++ b/config/board.teensy-v2.0.h @@ -237,11 +237,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO10, 0, 1) -DEFINE_HEATER(bed, DIO9, 0, 1) -DEFINE_HEATER(fan, DIO8, 0, 0) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO10, 0, 1, 100) +DEFINE_HEATER(bed, DIO9, 0, 1, 100) +DEFINE_HEATER(fan, DIO8, 0, 0, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/config/board.tronxy.h b/config/board.tronxy.h index 2c782be..f672d10 100644 --- a/config/board.tronxy.h +++ b/config/board.tronxy.h @@ -239,11 +239,24 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO6, THERMISTOR_BED) with slow switches, like solid state relays. PWM frequency can be 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 -DEFINE_HEATER(extruder, DIO13, 0, 1) -DEFINE_HEATER(bed, DIO12, 0, 1) -DEFINE_HEATER(fan, DIO4, 0, 1) + +// name pin invert pwm max_pwm +DEFINE_HEATER(extruder, DIO13, 0, 1, 100) +DEFINE_HEATER(bed, DIO12, 0, 1, 100) +DEFINE_HEATER(fan, DIO4, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/configtool/addheaterdlg.py b/configtool/addheaterdlg.py index 753ea16..a663931 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 = "", invert = "0", pwm = "1"): + name = "", pin = "", invert = "0", pwm = "1", max_pwm = "100"): wx.Dialog.__init__(self, parent, wx.ID_ANY, "Add heater", size = (400, 204)) self.SetFont(font) self.Bind(wx.EVT_CLOSE, self.onCancel) @@ -14,6 +14,7 @@ class AddHeaterDlg(wx.Dialog): self.choices = pins self.nameValid = (name != "") + self.maxPWMValid = (max_pwm != "") sz = wx.BoxSizer(wx.VERTICAL) gsz = wx.GridBagSizer() @@ -50,10 +51,26 @@ class AddHeaterDlg(wx.Dialog): else: self.chPin.SetSelection(i) lsz.Add(self.chPin) - self.chPin.SetToolTipString("Choose a pin for this heater.") + self.chPin.SetToolTipString("Choose a pin for this heater.") gsz.Add(lsz, pos = (3, 1)) + lsz = wx.BoxSizer(wx.HORIZONTAL) + st = wx.StaticText(self, wx.ID_ANY, "Max PWM:", size = (80, -1), + style = wx.ALIGN_RIGHT) + st.SetFont(font) + lsz.Add(st, 1, wx.TOP, offsetChLabel) + + self.tcMaxPWM = wx.TextCtrl(self, wx.ID_ANY, max_pwm) + self.tcMaxPWM.SetFont(font) + self.tcMaxPWM.Bind(wx.EVT_TEXT, self.onMaxPWM) + lsz.Add(self.tcMaxPWM) + self.tcMaxPWM.SetToolTipString("Enter max. PWM value in [%]. Typically \n" + "between 40 and 100. Standard is 100.\n" + "Valid values 1 to 100.") + + gsz.Add(lsz, pos = (5, 1)) + self.cbInv = wx.CheckBox(self, wx.ID_ANY, "Invert") self.cbInv.SetFont(font) self.cbInv.SetValue(int(invert) != 0) @@ -118,8 +135,29 @@ class AddHeaterDlg(wx.Dialog): def onChoice(self, evt): pass + def onMaxPWM(self, evt): + tc = evt.GetEventObject() + w = tc.GetValue().strip() + if w == "": + self.maxPWMValid = False + else: + if int(w) > 0 and int(w) <= 100: + self.maxPWMValid = True + else: + self.maxPWMValid = False + + if self.maxPWMValid: + tc.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) + else: + tc.SetBackgroundColour("pink") + tc.Refresh() + + self.checkDlgValidity() + if evt is not None: + evt.Skip() + def checkDlgValidity(self): - if self.nameValid: + if (self.nameValid and self.maxPWMValid): self.bSave.Enable(True) else: self.bSave.Enable(False) @@ -138,7 +176,9 @@ class AddHeaterDlg(wx.Dialog): else: pwm = "0" - return (nm, pin, invert, pwm) + max_pwm = self.tcMaxPWM.GetValue() + + return (nm, pin, invert, pwm, max_pwm) def onSave(self, evt): self.EndModal(wx.ID_OK) diff --git a/configtool/board.generic.h b/configtool/board.generic.h index 3e1550d..9400995 100644 --- a/configtool/board.generic.h +++ b/configtool/board.generic.h @@ -233,6 +233,18 @@ with slow switches, like solid state relays. PWM frequency can be 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/board.py b/configtool/board.py index 69fcb0d..211489e 100644 --- a/configtool/board.py +++ b/configtool/board.py @@ -12,7 +12,7 @@ from configtool.data import (defineValueFormat, reDefine, reDefineBL, reDefQS, reDefQSm, reDefQSm2, reDefBool, reDefBoolBL, reDefHT, reDefTS, reDefTT, reSensor, reHeater3, reHeater4, - reTempTable4, reTempTable7) + reHeater5, reTempTable4, reTempTable7) class Board: def __init__(self, settings): @@ -303,11 +303,19 @@ class Board: return None def parseHeater(self, s): + m = reHeater5.search(s) + if m: + t = m.groups() + if len(t) == 5: + return list(t) + # reHeater4 deprecated, for compatibility with old config files only. m = reHeater4.search(s) if m: t = m.groups() if len(t) == 4: - return list(t) + t = list(t) + t.insert(5, '100') + return t # reHeater3 deprecated, for compatibility with old config files only. m = reHeater3.search(s) if m: @@ -315,6 +323,7 @@ class Board: if len(t) == 3: t = list(t) t.insert(2, '0') + t.insert(5, '100') return t # End of deprecated part. return None @@ -392,10 +401,10 @@ class Board: m = reStartHeaters.match(ln) if m: fp.write(ln) - fp.write("// name pin invert pwm\n") + fp.write("// name pin invert pwm max_pwm\n") for s in self.heaters: - sstr = "%-10s%-9s%-8s%s" % ((s[0] + ","), (s[1] + ","), - (s[2] + ","), s[3]) + sstr = "%-10s%-9s%-8s%-7s%s" % ((s[0] + ","), (s[1] + ","), + (s[2] + ","), s[3] + ",", s[4]) 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 e5f23fa..4c459c9 100644 --- a/configtool/data.py +++ b/configtool/data.py @@ -61,9 +61,10 @@ 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*\\)") -# reHeater3 deprecated, for compatibility with old config files only. +# reHeater3 and reHeater4 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*\\)") +reHeater5 = re.compile(".*\\(\s*(\w+)\s*,\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 094c9c5..28c7b4f 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 + 75 + 55 + 55 + 4, 100), + size = (95 + 75 + 55 + 55 + 95 + 4, 100), style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES) self.SetFont(font) @@ -19,10 +19,12 @@ class HeaterList(wx.ListCtrl): self.InsertColumn(1, "Pin") self.InsertColumn(2, "Invert") self.InsertColumn(3, "PWM") + self.InsertColumn(4, "Max PWM [%]") self.SetColumnWidth(0, 95) self.SetColumnWidth(1, 75) self.SetColumnWidth(2, 55) self.SetColumnWidth(3, 55) + self.SetColumnWidth(4, 95) self.SetItemCount(0) @@ -84,3 +86,5 @@ class HeaterList(wx.ListCtrl): return "True" else: return "False" + elif col == 4: + return s[4] diff --git a/configtool/heaterspage.py b/configtool/heaterspage.py index ce98559..b4ea085 100644 --- a/configtool/heaterspage.py +++ b/configtool/heaterspage.py @@ -14,6 +14,8 @@ 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)) @@ -24,6 +26,13 @@ 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) @@ -116,7 +125,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], invert = h[2], pwm = h[3]) + name = h[0], pin = h[1], invert = h[2], pwm = h[3], max_pwm = h[4]) rc = dlg.ShowModal() if rc == wx.ID_OK: ht = dlg.getValues() diff --git a/heater-avr.c b/heater-avr.c index c8a6dc8..7bc8a0d 100644 --- a/heater-avr.c +++ b/heater-avr.c @@ -21,12 +21,26 @@ 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 } 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 /// \brief helper macro to fill heater definition struct from config.h -#define DEFINE_HEATER(name, pin, invert, pwm) { \ - &(pin ## _WPORT), pin ## _PIN, invert ? 1 : 0, pwm ? (pin ## _PWM) : NULL}, +#define DEFINE_HEATER(name, pin, invert, pwm, max_value) { \ + &(pin ## _WPORT), \ + pin ## _PIN, \ + invert ? 1 : 0, \ + pwm ? (pin ## _PWM) : NULL, \ + HEATER_MAX_VALUE(max_value)\ + }, static const heater_definition_t heaters[NUM_HEATERS] = { #include "config_wrapper.h" @@ -195,7 +209,7 @@ void heater_init() { // set all heater pins to output #undef DEFINE_HEATER - #define DEFINE_HEATER(name, pin, invert, pwm) \ + #define DEFINE_HEATER(name, pin, invert, pwm, max_value) \ SET_OUTPUT(pin); \ WRITE(pin, invert ? 1 : 0); #include "config_wrapper.h" @@ -214,6 +228,9 @@ void heater_set(heater_t index, uint8_t value) { if (index >= NUM_HEATERS) return; + #ifdef MAX_PWM_ACTIVE + value = (uint8_t)((heaters[index].max_value * value + 128) / 256); + #endif heaters_runtime[index].heater_output = value; if (heaters[index].heater_pwm) { diff --git a/heater-lpc.c b/heater-lpc.c index 5c96d49..46736d0 100644 --- a/heater-lpc.c +++ b/heater-lpc.c @@ -51,7 +51,11 @@ frequency, so you should bother about PWM_SCALE only of you need frequencies below 3 Hz. */ -#define PWM_SCALE 255 +#ifndef MAX_PWM_ACTIVE + #define PWM_SCALE 255 +#else + #define PWM_SCALE 1020 +#endif /** \struct heater_definition_t @@ -66,17 +70,26 @@ 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 -#define DEFINE_HEATER(name, pin, invert, pwm) \ +#define DEFINE_HEATER(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!*/ \ pwm && pin ## _TIMER, \ invert ? 1 : 0 \ }, @@ -131,7 +144,7 @@ void heater_init() { */ // Auto-generate pin setup. #undef DEFINE_HEATER - #define DEFINE_HEATER(name, pin, invert, pwm) \ + #define DEFINE_HEATER(name, pin, invert, pwm, max_value) \ if (pwm && pin ## _TIMER) { \ uint32_t freq; \ \ @@ -196,7 +209,11 @@ 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; diff --git a/heater.h b/heater.h index 92e81ca..c78af97 100644 --- a/heater.h +++ b/heater.h @@ -30,7 +30,7 @@ #undef DEFINE_HEATER -#define DEFINE_HEATER(name, pin, invert, pwm) HEATER_ ## name, +#define DEFINE_HEATER(name, pin, invert, pwm, ...) HEATER_ ## name, typedef enum { #include "config_wrapper.h" diff --git a/testcases/board.regtest-no-endstops.h b/testcases/board.regtest-no-endstops.h index 4e81311..6c175fc 100644 --- a/testcases/board.regtest-no-endstops.h +++ b/testcases/board.regtest-no-endstops.h @@ -67,8 +67,8 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO2, THERMISTOR_BED) #define DEFINE_HEATER(...) #endif -DEFINE_HEATER(extruder, DIO4, 0, 1) -DEFINE_HEATER(bed, DIO3, 0, 1) +DEFINE_HEATER(extruder, DIO4, 0, 1, 100) +DEFINE_HEATER(bed, DIO3, 0, 1, 100) #define HEATER_EXTRUDER HEATER_extruder #define HEATER_BED HEATER_bed diff --git a/testcases/config.h.Profiling b/testcases/config.h.Profiling index 558ae70..df4f4f2 100644 --- a/testcases/config.h.Profiling +++ b/testcases/config.h.Profiling @@ -541,9 +541,22 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO0, THERMISTOR_EXTRUDER) */ //#define HEATER_PIN xxxx +/** \def HEATER_MAX_ACTIVE + Enable heater_max 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 heater_max to 25%. + + heater_max values are allowed between 1 and 100. +*/ + +//DEFINE_HEATERS_START +// #define HEATER_MAX_ACTIVE + // name pin invert pwm -DEFINE_HEATER(extruder, DIO4, 0, 1) -DEFINE_HEATER(bed, DIO3, 0, 1) +DEFINE_HEATER(extruder, DIO4, 0, 1, 100) +DEFINE_HEATER(bed, DIO3, 0, 1, 100) /// 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.