Welcome! Log In Create A New Profile

Advanced

Teacup firmware with relay

Posted by destroyer2012 
Teacup firmware with relay
March 04, 2012 11:12PM
I have recently installed the teacup firmware on my custom Gen 2 hardware and it works mostly, but when switching my heated bed on and off (which uses a relay to control mains current), the relay switches way too fast and I'm afraid it will break. Does anyone know of an easy way to change the firmware so it waits like 1 second between issuing commands to the heated bed?

Thanks
Re: Teacup firmware with relay
March 05, 2012 12:26AM
these to configuration.h
#define PWMBITBANG 64000 //this is pwm resolution in ms if this is zero pwm is analog pwm if this above zero then it is bitbang
#define gainpwm 251//value that makes 255x it the max resolution such as 64000 but not over that!
#define HEATER_CURRENT 255 //this can go to 255 in analog in bitbang it can go to set lower to reduce max power
#define mIn_PWM 30000 // for min amount of ontime to keep resistors slightly heated and reduce temp drop when off.

declare

unsigned long pwmcount ;
unsigned long heaterpwmduty; //max amount of on time

in your code look for the heater manager.

in sprinter it is

void manage_heater()
{
if((millis() - previous_millis_heater) < HEATER_CHECK_INTERVAL ){

//code i added
pwmcount++; //this increments for pwmcount
pinMode(HEATER_0_PIN,OUTPUT);
if (heaterpwmduty PWMBITBANG) pwmcount=0; //this is end of pwm resolution so reset to zero
if (pwmcount < heaterpwmduty ) {digitalWrite(HEATER_0_PIN,HIGH);}
else {digitalWrite(HEATER_0_PIN,LOW);}
//end of code added
return;}


when performing an analogwrite do this instead
heaterpwmduty=analogvalue
for example in sprinter i use:
heaterpwmduty= heater_duty*gainpwm; //
it works well enough to keep temp within 2deg c at all times smiling smiley

I can upload the sprinter version i use if you would like. i don't think sprinter officially supports relay PID control

it should give you an idea on how to add it to teacup. sorry so short. cut off by spam filter again sad smiley

you could integrate a time thru loop before i/o change

Edited 3 time(s). Last edit at 03/05/2012 12:32AM by jamesdanielv.
Re: Teacup firmware with relay
March 05, 2012 12:39AM
or it looks like you could just change pins and have bed heater on a pin that does not support PWM, then it will be bang bang mode by default. PWM pins are 3,5,6,9,10,11.don't have the heater pin on one of those pins.

Edited 2 time(s). Last edit at 03/05/2012 12:40AM by jamesdanielv.
Re: Teacup firmware with relay
March 05, 2012 12:50AM
Thanks a lot for those suggestions jamesdanielv, I will see if I can put them to use.

I think my issue is not with the PWM but with the PID control wanting to switch it too fast.

One problem is the teacup firmware is written entirely in C and doesn't use functions such as "analogWrite" or "millis" so I am having some trouble just figuring out what does what. The fact that I have it working for everything but this makes me wary about switching to another firmware, I'm going to see if I can hack it to have a large hysteresis when it is addressing the heated bed.

I haven't looked at sprinter at all but I was under the impression that it was not made with rs485 communication in mind and that is what my setup is currently using. I could rewire everything but it would be a huge pain in the ass for something that seems like it should be an easy fix tongue sticking out smiley.

My current approach is to edit heater_tick(h,t,current_temp,target_temp) in heater.c so that if h corresponds to the heated bed it invokes a bang-bang control with a hysteresis of like 2 degrees. I'm still trying to figure out how the argument h relates to any heater at all, will report what i come up with.

Edited 1 time(s). Last edit at 03/05/2012 12:51AM by destroyer2012.
Re: Teacup firmware with relay
March 05, 2012 02:47AM
Just to clarify my symptoms a bit: During ramping the relay turns on fine (only once) and if I then set the temp back to zero it turns off correctly. When the heated bed reaches the set temperature the relay starts clicking really fast.

I could not figure out how to do the equivalent of millis() without screwing up everything else in the teacup firmware (if you include millis() it will try to redefine "delay" or something and cause an error during compiling).

As far as I can tell what I should do is create a seperate interrupt that triggers every half second or something just to run the relay using bang bang control, but since it is currently set up to manage both the extruder heater and the heated bed within the same loop using the same control system (so I can't do PID for one and bang-bang for the other) it would be rather complex to try to re-code that part.

If I set everything to bang bang it still clicks a lot when the bed reaches the set temperature, possibly due to noise in the temperature reading?

I've tried adding/changing this at the bottom of heater_tick:

if (current_temp >= target_temp+8)
pid_output = BANG_BANG_OFF;
if (current_temp <= target_temp)
pid_output = BANG_BANG_ON;

This should result in only one click on and one click off.. right? It does not. The relay still clicks a lot. I tried defining pid_output to 1000 intially and making the heater_set function not do anything if pid_output isn't set to something reasonable. Still clicking, which is really bizarre since I don't know where else pid_output is being set.

What I really need is a timer that controls how often the pwm is updated ONLY FOR THE HEATED BED. How hard is that?

It seems like buying a solid state relay is easier at this point.. sad smiley
Re: Teacup firmware with relay
March 05, 2012 06:54AM
what pin are you using for bed heater?
Re: Teacup firmware with relay
March 05, 2012 10:34PM
Switched to pin 12, which is not a pwm-capable pin on the arduino diecimila 168 right? According to this [arduino.cc] it is not, so i should be safe there.

Still clicking.
Re: Teacup firmware with relay
March 08, 2012 10:25PM
Just an update:

Bought a couple of these
[search.digikey.com]〈=en&site=us&keywords=Z2521-ND&x=0&y=0

Seemed like the right choice given my bed only draws 0.8 amps and the bigger relays go up in price pretty quick.

Wired them up in parallel (just to be safe!) to power my heated bed.

Temperature control works fine (set to bang bang) and I don't have to worry about the relay wearing out and getting stuck on.

Currently warming up getting ready to print a model sliced with slic3r, using pronterface.Will report on outcome!
Sorry, only registered users may post in this forum.

Click here to login