From 8d913129910d73265cd1a32c0987092699693925 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Fri, 12 Oct 2012 02:25:40 +0200 Subject: [PATCH] heaters: allow to disable PWM on PWM-able pins. This is not only handy for debugging non-PWM mode, it may also help those who run a heated bed attached to a solid state relay. This way it was found out connecting heaters to non-PWM pins works just fine and did so for a loooong time. Not yet distributed to all the config.h templates. --- config.default.h | 22 +++++++++++++--------- heater.c | 6 +++--- heater.h | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config.default.h b/config.default.h index c45d2fd..0e364ec 100644 --- a/config.default.h +++ b/config.default.h @@ -321,9 +321,6 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_EXTRUDER) * * * Define your heaters here. * * * -* Currently, heaters work on PWM-able pins, only. See the end of this file * -* for PWM-able pin mappings. * -* * * To attach a heater to a temp sensor above, simply use exactly the same * * name - copy+paste is your friend. Some common names are 'extruder', * * 'bed', 'fan', 'motor', ... names with special meaning can be found * @@ -336,18 +333,25 @@ DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1, THERMISTOR_EXTRUDER) * temperature sensor of TT_NONE, then you can control the spindle's rpm * * via temperature commands. M104 S1..255 for spindle on, M104 S0 for off. * * * +* 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. * +* Using PWM usually gives smoother temperature control but can conflict * +* with slow switches, like solid state relays. PWM frequency can be * +* influenced globally with FAST_PWM, see below. * +* * \***************************************************************************/ #ifndef DEFINE_HEATER #define DEFINE_HEATER(...) #endif -// name port -DEFINE_HEATER(extruder, PB3) -DEFINE_HEATER(bed, PB4) -// DEFINE_HEATER(fan, PINB4) -// DEFINE_HEATER(chamber, PIND7) -// DEFINE_HEATER(motor, PIND6) +// name port pwm +DEFINE_HEATER(extruder, PB3, 1) +DEFINE_HEATER(bed, PB4, 1) +// DEFINE_HEATER(fan, PINB4, 1) +// DEFINE_HEATER(chamber, PIND7, 1) +// DEFINE_HEATER(motor, PIND6, 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. diff --git a/heater.c b/heater.c index b473a16..025278a 100644 --- a/heater.c +++ b/heater.c @@ -27,8 +27,8 @@ typedef struct { #undef DEFINE_HEATER /// \brief helper macro to fill heater definition struct from config.h -// #define DEFINE_HEATER(name, port, pin, pwm) { &(port), (pin), &(pwm) }, -#define DEFINE_HEATER(name, pin) { &(pin ## _WPORT), pin ## _PIN, (pin ## _PWM) }, +#define DEFINE_HEATER(name, pin, pwm) { &(pin ## _WPORT), pin ## _PIN, \ + pwm ? (pin ## _PWM) : NULL}, static const heater_definition_t heaters[NUM_HEATERS] = { #include "config.h" @@ -251,7 +251,7 @@ void heater_init() { // set all heater pins to output do { #undef DEFINE_HEATER - #define DEFINE_HEATER(name, pin) WRITE(pin, 0); SET_OUTPUT(pin); + #define DEFINE_HEATER(name, pin, pwm) WRITE(pin, 0); SET_OUTPUT(pin); #include "config.h" #undef DEFINE_HEATER } while (0); diff --git a/heater.h b/heater.h index 56a4306..082baf3 100644 --- a/heater.h +++ b/heater.h @@ -6,7 +6,7 @@ #include "temp.h" #undef DEFINE_HEATER -#define DEFINE_HEATER(name, pin) HEATER_ ## name, +#define DEFINE_HEATER(name, pin, pwm) HEATER_ ## name, typedef enum { #include "config.h"