Linear PID max output scaling based on temperature

  • Hello everyone,

    i'm thinking about switching from my 2014 Rambo Board on a Rostock Max V2 to a Duet 2 Wifi. RIght now i'm using nearly stock Marlin Firmware 1.1.X but i've a minor edit that i need to know if is already present in RRF.

    My printer is born with 12V power supply but i've switched to 24V (25V actually) for getting the heated bed to reach stable 110/120°C in about 10 minutes. The problem i've faced is that my onyx heated bed was not correctly designed and its resistency is lower than it should be to work at reasonable current at 24VDC. If i run it directly connected to the PS at 25VDC i get around 22Amps but, as you all know, resistance is greater at higher temperature, ending with a current of 11/12 Amps at 100°C. What i did in marlin is an horrible hack that allows me to run the heated bed at 25VDC limiting the max PID output based on the current bed temperature. I attach the edit here for better comprension:

    int min_temp = 20;
    int max_temp = 80;
    int min_output = 190;
    int max_output = 255; 
    if (current_temperature_bed >= min_temp && current_temperature_bed <=max_temp) 
      SCALED_MAX_BED_POWER = map(current_temperature_bed,min_temp,max_temp,min_output,max_output);
    else if (current_temperature_bed < min_temp)
      SCALED_MAX_BED_POWER = min_output;
    else if (current_temperature_bed > max_temp)
      SCALED_MAX_BED_POWER = max_output;

    SCALED_MAX_BED_POWER will replace MAX_BED_POWER variable on the PID calculations.
    Don't blame me for the rough code, i'm not a professional developer!

    With this "trick" i can get nearly costant 14Amps on my heated bed at every temperature (15A max power from my board).
    Duet2 can hold up to 18A that is not enough for a cold start for my setup. Within RRF does already exist this type of feature or is something i can easily add my own like i did in Marlin?

    Thanks all

  • Also noticed that a " Firmware developers " section exists. If a mod could move that topic there would be nice! Sorry!

  • administrators

    RRF doesn't have that facility built-in. However, I think you could implement it in the daemon.g file supported by RepRapFirmware 3.01, by writing a simple loop that watches the bed temperature and adjusts the maximum PWM accordingly.

  • So basically i can write code that runs on a different thread that updates the value right? This would be great and allow me to not replace my old bad made bed!

  • @dc42 Hello David, finally i got my Duet2 Wifi connected to my printer (only missing daughter board for E3D PT100). I've created the script in daemon.g and it's working (still missing variable declaration and set btw, any ETA on this?). My problem actually is that UI is reporting a warning at every script execution so basically it's flooding my UI with this message: "Warning: Heater 0 appears to be over-powered. If left on at full power, its temperature is predicted to reach 365C". I undertand that this is caused by BED with too low resistance and not engineered for 24VDC but i know what i'm risking and want to disable the warning. Is it possible?

    Also i leave my script for anyone that maybe will need it:

    ;Actual code without variables
    if sensors.analog[0].lastReading >= 20.0 && sensors.analog[0].lastReading <= 80.0
    	M307 H0 S{(sensors.analog[0].lastReading  - 20.0) * (1 - 0.745) / (80.0- 20.0) + 0.745}
    elif sensors.analog[0].lastReading < 20.0
    	M307 H0 S0.745
    elif sensors.analog[0].lastReading > 80.0
    	M307 H0 S1
    ;Future code when variables will be implemented
    var minTemp = 20.0
    var maxTemp = 80.0
    var minOutput = 0.745
    var maxOutput = 1.0
    var bedTemperature = sensors.analog[0].lastReading
    if bedTemperature >= minTemp && bedTemperature <= maxTemp
    	var pidMaxPWM = (bedTemperature  - minTemp ) * (maxOutput - minOutput ) / (maxTemp - minTemp ) + minOutput
    elif bedTemperature < minTemp 
    	var pidMaxPWM = minOutput 
    elif bedTemperature > maxTemp 
    	var pidMaxPWM = maxOutput
    M307 H0 S{pidMaxPWM}
    ;echo "PID max PWM set to {pidMaxPWM}

    Thank you for the great work!

  • Moderator

    Nothing about any of this is recommended. Just replace the bed.

    However, if you insist, you may be able to have the warnings suppressed by using a M143 for the bed that sets the max temp closer to the temp given by the warning message.

    Please use a thermal cutout fuse on the bed power in case there is a fault situation leading to runaway heating.

  • @Phaedrux i've already installed an 140°C fuse in series with bed power supply (the one that you find on irons) so not worried about my home get on fire 😊 So if i understand i have also to set the max temperature reachable by the bed closer to the one of the warning correct?

  • Moderator

    @MikeS Correct.

    Well just in case anyone else reads this in the future. It's not recommended and ensure you have some thermal protection.

    The warning is there to inform you of the risks. It's up to you how you deal with them.

  • @Phaedrux I confirm that now it isnot throwing the warning anymore. Thank you for your assistance...i'll change the bed as soon as i can find one that fits well with my Rostock Max V2 and it is not made in USA cause of import fees and low quality (already bought 3 of them of various revision and always had something wrong 😢 )

  • I have a 250mm 240VAC heated delta bed (6mm aluminum tool plate with a permanent print surface) I never installed on a delta I have scrapped since. It should about fit the Rostock Max V2. Send me a private message to sort out of we can strike a deal if you're interested in getting it shipped from Germany.

Log in to reply