Welcome! Log In Create A New Profile

Advanced

temp.c and heatbed with relay

Posted by Creo 
temp.c and heatbed with relay
March 03, 2014 02:26PM
I came across an issue and was wondering if someone with better programming skills can help explain the part of temperature.c that handles bed heating?
Here is my info and then my problem.
Info: Prusa i3 with prusa 12v pcb heatbed and RAMBO controller loaded with Erik Zalm's Marlin tweaked for my prusa.
Issue: Had the plastic connector to the RAMBO start to melt and cause intermittent bed heating, so I decided to put it on a relay and ordered the cheap heated bed relay from Makerfarm. Not a SSR but a mechanical automotive style relay soldered to a pcb with screw terminals making connection simple and quick. I already had the bed set to bangbang without BED_LIMIT_SWITCHING defined which I believed would simply set HEATER_BED_PIN to true and output a voltage equal to MAX_BED_POWER which is set to 255. I assumed this would work fine with mechanical relay but when controller trys to heat the bed, the relay is cycling(clicking) about 1-2 times a second?
Digging through the source code I found the bed temperature control section in temperature.c and fixed my issue by changing a part of this section:
#elif !defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct range
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
{
if(current_temperature_bed >= target_temperature_bed)
{
soft_pwm_bed = 0;
}
else
{
soft_pwm_bed = MAX_BED_POWER>>1;
}
}
else
{
soft_pwm_bed = 0;
WRITE(HEATER_BED_PIN,LOW);
}


Changed :
{
soft_pwm_bed = MAX_BED_POWER>>1;
}

to
{
soft_pwm_bed = MAX_BED_POWER;
WRITE(HEATER_BED_PIN,HIGH);
}


...it is now working without cycling, completed a 3hr print without connections getting hot spinning smiley sticking its tongue out

I am not a seasoned programmer and I am ignorant enough to be dangerous.....therefore, can someone let me know
1. are the changes I made going to eventually damage an electrical component on the RAMBO?
2. If changes I made are incorrect, how do I stop the relay from cycling?
3. what is the bit shift operation on the value stored for MAX_BED_POWER supposed to accomplish?


Thanks!
Re: temp.c and heatbed with relay
March 04, 2014 12:15AM
The chips don't do true analog output, so the voltage is full voltage, but pulse-width controlled by the MAX_BED_POWER number interacting with a PWM counter. Marlin's PWM counter actually 0-127, but defines things in terms of 0-255. and divides by two.

1) nope, they won't damage your board. Reducing the cycling will significantly extend the life of the relay.

2) soft_pwm_bed works with the pwm_count=0-127 loop managed by the ISR(TIMER0_COMPB_vect) function called every 1.024ms or so for a period of 131ms. The bed gets turned on when the pwm_count is zero, or less than soft_pwm_bed, and turned off at [github.com] if pwm_count exceeds soft_pwm_count. If you defined "PIDTEMPBED" then the 131ms frequency duty cycle should vary under PID control when you are within 10C of the setpoint and you would get clicking about 14 times per second. Without PIDTEMPBED, it shouldn't click so much, only in response to the temperature. Maybe you do want to define BED_LIMIT_SWITCHING so you get 4C of a deadband (defined as BED_HYSTERESIS in Configuration_adv.h) and aren't clicking back and forth with noise on the temperature measurement.

3) The >>1 divides the value by two, so (255 >>1) == 127, to put the 0-255 range of the variables into the 0-127 range of the pwm_count counter. You could get some of the effect of your code change by setting MAX_BED_POWER 511.
Re: temp.c and heatbed with relay
March 06, 2014 12:27AM
Thanks!

1. Great! Reduced cycling is exactly what I was trying to accomplish.

2. I think I understand, thanks. That is a good idea, I think I will tweak the BED_LIMIT_SWITCHING.

3. The bit shift operation made sense as soon as you explained that Marlin's PWM counter is 0-127. Only thing I don't understand is that when MAX_BED_POWER 255 it still cycles constantly while heating to target temperature even though the line you linked shouldn't be setting HEATER_BED_PIN low since it says less than, not less than or equal?...If MAX_BED_POWER 255 then soft_pwm_bed will be 127 and 127 is not less than 127 which is the highest value pwm_count should ever be….if I understand code and your explanation correctly? Setting MAX_BED_POWER 256 stops it from cycling while heating to target temp.

I also defined BED_LIMIT_SWITCHING and tweaked code in temperature.c for its control. I like how its working now! thumbs up Thanks Dave!

If anyone is interested, here are my changes for using a mechanical relay for bed heating.

1. In Configuration.h define BED_LIMIT_SWITCHING and set MAX_BED_POWER 256.

2. change part of temperature.c to match this:

#else //#ifdef BED_LIMIT_SWITCHING
// Check if temperature is within the correct band
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
{
if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS)
{
soft_pwm_bed = 0;
}
else if(current_temperature_bed < target_temperature_bed - (BED_HYSTERESIS>>1))
{
soft_pwm_bed = MAX_BED_POWER>>1;
}


3. I set BED_HYSTERESIS 2 in Configuration_adv.h


Hey DaveX, any chance you have answers for this http://forums.reprap.org/read.php?13,278355,319175#msg-319175 ? I think what I am looking for is in ConfigurationStore.cpp but I haven't figured that code out yet.
Re: temp.c and heatbed with relay
July 25, 2015 12:05PM
Tried creos solution, but with no luck, bed is still switchning several times per second :0(

I have tried slow pwm seting and it works perfect with bed, what is worse, it slows all hotends switching too :0(

Edited 1 time(s). Last edit at 07/25/2015 12:07PM by zemciko.
Sorry, only registered users may post in this forum.

Click here to login