My current setup:
RUMBA electronics, powering:
Two extruders, both hot ends controlled via auto-tuned PID loop
Heated build platform
I'm trying to add an enclosure heater and control the enclosure temperature with the RUMBA instead of a secondary thermostat/controller. The heater's power source will be 120 V AC from the wall, switched by a relay. I intend to control the temperature by treating the heater as a third hot end.
I've already installed a thermistor dangling inside the enclosure and hooked it to the third extruder temperature input of the RUMBA, and have successfully configured my host software (Octoprint) to pretend that it has a third extruder. I hooked a fan to the power output MOSFET for the third extruder hot end and was able to confirm that it receives 12 V when the third hot end is commanded on, and turns off when the temperature is set to zero. Great.
The main complicating factor here is that Marlin uses the same PWM control for all extruders. There's no built-in way to have some extruder hot ends run in regular PWM mode and others in slow PWM mode, or some in regular PWM and others bang-bang. When my enclosure temperature is well below the set point, this isn't an issue, but once it gets close to it, the control is going to start firing rapid on-off signals to the relay, which is no good. I don't want the relay cycling more than once every three seconds or so.
I do not fully understand the guts of temperature.cpp and associated pieces of Marlin. I have close to zero C++ experience, but have worked with C, Java, and several other similar languages enough to not be totally hopeless. I am looking for the quickest and safest way to hack Marlin to achieve a slower control of "extruder #3" so that my relay isn't flickering on and off like crazy.
This is what I'm currently looking at trying, based on studying the latest Marlin source code for a few hours:
Towards the end of temperature.cpp, there is the Timer 0 loop. About 54 lines down from the
ISR(TIMER0_COMPB_vect) line, I find what appears to be the very place where Marlin is commanding the output of the heater pin for extruder #3:
WRITE_HEATER_2(soft_pwm_2 > 0 ? 1 : 0);
Perfect. My idea here is to implement a special counter
RA_counter which only increments when
((pwm_count % 64) == 0), aka every 65 ms, similar to the slow PWM loop
slow_pwm_count. I reset
RA_counter to zero after it reaches 46. Then I add an if statement that prevents the above
WRITE_HEATER_2 command from executing unless
RA_counter == 46. The result should be that Marlin only attempts to make an adjustment to the voltage of extruder #3's heater pin every 46*0.065=3 seconds.
I don't have the relay yet, so I can't test this yet. It arrives Friday, and I plan to play with this over the weekend. I welcome feedback before I proceed to destroy my electronics, printer, burn down my house, and trigger the next great extinction of life on Earth by following the approach I've described above.