Welcome! Log In Create A New Profile

Advanced

Hacking Marlin to control a heated enclosure

Posted by reeseallen 
Hacking Marlin to control a heated enclosure
May 10, 2016 11:13PM
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.
Re: Hacking Marlin to control a heated enclosure
January 10, 2018 11:55PM
i like your idea and that was the direction i was leaning but i agree... it needs to be able to be set to bang like as if it were a heater bed configuration.... would like to control a ceramic heater with a fan and for it to switch on and off quickly and repeatedly would damage the heating unit

also using a azteeg x3 pro control board

Edited 2 time(s). Last edit at 01/11/2018 09:01PM by jl791127.
Re: Hacking Marlin to control a heated enclosure
January 11, 2018 10:07AM
Probably this should be implemented so it can be controlled with GCode.
And the code should wire up the M109 logic to wait for the enclosure to reach temperature.
This is a good idea and will have value to a lot of users.
Sorry, only registered users may post in this forum.

Click here to login