DEV2: Description of dead time heater

I think there is a copy/paste mistake in the description of the dynamic dead time control:

Could you please offer what the variables in

 HEAT_MANAGER_DYN_DEAD_TIME(HeaterExtruder1, 'E', 0, TempExt1, PWMExtruder1, 260, 255, 50, 5, 2000, 150, 1, 1, 1, 1, 1, false)
HEAT_MANAGER_DYN_DEAD_TIME(name, tp, index, input, output, maxTemp, maxPwm, sampleTime, decVariance, decPeriod, time1, up1, down1, time2, up2, down2, hotPlugable)
I do not understand these:

time1, up1, down1, time2, up2, down2

I found this description:
Dynamic Dead Time 

 The normal dead time assumes same time for heating and cooling. Reality is that these
 differ. They even differ over temperatures, especially cooling at high temperatures
 is much faster then for lower temperatures. So what we really need are 2 sets - one for
 the high temperatures and one for the lower ones, then we can interpolate timings.

 deadUp is time to stop heating until the curve slows down.
 deadDown is time to start heating until you will see a raise.

From this I would have expected

Is it correct to determine
1. The deadtime at low temperatures using this: , for example at 180°C --> meaning I set a constant PWM and wait till stable temperature. Than I set PWM to 255 and watch the curve.
2. The deadtime at high temperatures in the same way, for example at 230°C

Each of it has to be done for increasing and decreasing temperature. So you in the deacreasing curve you simply switch of the heater and the graph including its linear extrapolations is basivally flipped up/down. Is that right?


  • This is more or less the same dead time as described in the link you described. Now are the variables not constant e.g. with a strong heater it goes faster up then then cooling goes down. But the hotter you are the bigger is the temperature gradient and cooling gets faster. So instead of having 1 fixed dead time I have 2 - one for rising and one for dropping. Then I doubled these and extrapolate them so we can cover a range of temperatures with optimized dead times.

    So to measure temperatures go to the temperature until it is stabalized and then go to pwm 255(up) or 0(down) depending on time you measure.

    Problem is to get the stable temperature first. When you are on PID it would be easy though to do the measurements.

    But somehow that controller is not really that convincing as I hoped. At least in my tests.

    Maybe there should be better tests to calibrate that. But this system always needs an error to enable/disable heater so it is not possible to stabilize. It is more a bang-bang with improved timings to reduce the swing fast and as good as possible and then stay with some minimal swing.
  • Yes, I understand. So what are exactly the parameters time1, up1, down1, time2, up2, down2 ?
  • Yes, I understand. So what are exactly the parameters time1, up1, down1, time2, up2, down2 ?
    That was a small error. They've been corrected to temp1, timeUp1, timeDown1, temp2, timeUp2, timeDown2.
  • edited October 2020
    Just for others who might read this:

    One can find this calculation code in heatmanager.cpp:

    scale = (targetTemperature - temp1) / (temp2 - temp1);
    deadUp = scale * deadUp2 + (1.0 - scale) * deadUp1;
    deadDown = scale * deadDown2 + (1.0 - scale) * deadDown1;

    I compared it the following way for deadUp:

    calculate the slope using the differential quotient:

    use linear function:
    y=a x + b , put in one point:
    deadUp1=a*temp1+b ,

    solve b:
    b= deadUp1-a*temp1

    Put in in linear function:
    y= a*targetTemperature+deadUp1-a*temp1

    Because I was lazy I have compared it using a TI CAS with solve(y(targetTemperature)=deadUp(targetTemperature),targetTemperature) and it answered "true", meaning that these linear function are identical.
    So I did useless work. Mathematically it is the same like the original code.

    That means the two calibration points can be anywhere. It inter- and EXTRApolates the parameters. I was not sure if the values deadUp1/2 additionally give the maximum and minimum value of deadUp and DeadDown. So the calculated deadUp/Down can be larger/smaller than both values of calibration. But I see no limitation to valued between deadUp1 and deadUp2 and so on.

    I will try to calibrate it and send my results later (maybe at the weekend). I think it should be faster than PID, but less stable, as described above.
  • Is there any command to set the PWM of the heater pin without temperature control?

    I tried the following to manage to set the PWM of the heater without regulation:
    Make the heater pin usused:
    IO_OUTPUT(IOExtr1, HEATER_3_PIN) //karlranseier
    //IO_OUTPUT(IOExtr1, HEATER_0_PIN) //karlranseier

    Link the fan to heater pin:
    //IO_OUTPUT(IOFan1, ORIG_FAN_PIN) //karlranseier
    IO_OUTPUT(IOFan1,  HEATER_0_PIN) //karlranseier

    M106 P0 S45 --> Wait for a stable temperature (don't look at it, it will take longer than)
    M106 P0 S255 --> wait till it looks linear or becomes too hot
    Make screenshot of time-temperature-graph

    M106 P0 S0 cool down below stable temp

    M106 P0 S45 --> wait till stable temperature
    M106 P0 S0
    Make screenshot of time-temperature-graph

    M106 P0 S70 --> Wait for a stable temperature (don't look at it, it will take longer than)
    M106 P0 S255 --> wait till it looks linear or becomes too hot

    M106 P0 S0 cool down below stable temp
    M106 P0 S70 --> Wait for a stable temperature (don't look at it, it will take longer than)
    M106 P0 S0

    Undo changes in configuration_io.h

    Yes, a better graph would give better results, but I am sure this will have nearly no effect on the regulation.
    The upper graphs were taken during calibration with PWM defined output.
    The lower graph is with regulation. The stability is better than 0.5%. That's fine for me. I think it is the fastest regulation when changing temperature or filamentflux.
  • That gives me new ideas. First there is no easy way but we could add a M303 to help calibration.

    But I see also how stable temperature stays with fixed pwm. So if we measure for 10%..20%..100% and store temperature we could have a base pwm for each temperature. Just like the I term in PID controller. Then we do the up/down swings just with using 120% or 80% of the base pwm to compensate filament speed and cooler fan. Also we could also add tests with fan on/off as well. Then we are more or less directly setting correct pwm and use only some control to react on the error. Maybe combining it with pid would also be good.
  • edited October 2020
    Great idea! If you are already planning the calibration I would suggest the parameters: start value, increment, end value, T-Max, waiting time to run something like
    1. Set PWM
    2. Wait "waiting time", stop if T is above T-Max
    3. Measure Temperature
    4. Increase PWM by increment, if value will be below end value
    5. go to 1

    Do not allow operation if T-Max is not set.

    So we result in a combination of a regulation and control (german: Steuerung ohne Rückmeldung und Regelung mit Rückmeldung). Never tried that.

    Keep in mind that I did not move the printhead (no changing airflow) and did not extrude filament. Still the changes will not be dramatic.
  • Start value must be 0 pwm. We need to know the way up to t max which limits anything. Increment is ok if we want more stages. Procedure is more or less what I was thinking of.

    For users with heated chamber there might be another unknown. A hotter chamber will reduce required energy.

    Also we might be able to compute the energy needed to heat up extruder to old temperature when we start extruding x mm/s. We know material added per second and can correlate this with extra energy in pwm pulses. Then we add that depending on E speed of current moves. Should also reduce swinging introduction.

    When combining this with PID so we can really settle at a nearly perfect solution we need some delayed pid start. We must wait until temperature is nearly stable and then start with pid. Would then probably overswing but since we start with much smaller errors and have less influence the overswings will be much smaller. Same with combining it with dead time.
  • When switching to PID mode you could set the I value to the corresponding PWM. I did that before and it worked very well. In my case I have set a heating current. Than switched on PID where targettemperature was set to actual value and I was calculated. It will start to regulate only when T differs from targetvalue.
  • You are correct in principle with copy pwm to I. The problem is when to copy. Normally we say PID starts at -20°C of target temperature. When we do that there it will increase I a while until we are at target temperature and is then already higher causing it's part of overshoot.

    The best would be a combination. Full power until T-20 then using dead time for exact disable time. When we are close to target temperature or temps start to fall we set I to precomputed pwm and then switch to PID. So dead time prevents first overshoot and we start with theoretical ideal values. Then we also only need one dead time value for coming from top.

    At least if we increase temperature. For lowering temperature it would be other way around. No power until we know we need power and then already set correct PWM. when starting to raise or cross set temp. we switch to PID.

    Causes lots of variables to measure but would give a fast switching controller with fast pid converging. Already thinking when I get the time for this one:-)
  • edited October 2020
    I think you should not make it too complicated.
    1. Fast heat up
    2. Fast reaction
    3. High stability

    So I would start with the first solution as you described:
    - Set to MaxPWM (fast heat up)
    - If T is in range TTarget+/-"TregulationCorridor"-> Do DynDeadTime as you described: Calibrated PWM (stability) +/- 20%  (fast reaction due to deadtime regulation)
    - If T is above TMax: Error.

    Skip PID. In my opinion wou will change the heat up only.  You could change the parameters for faster regulation / no overshoot. There are enough "official" combinations.
    A fast approximation for setting up dead time could be to measure after a delay of two times longer than roughly expected dead time. Than do a scond measurement after 5 additional seconds and extrapolate when the linear curve hits the start temperature.
  • Hard to say. Maybe you are right or pid is the easier solution. I guess I really have to write this to see how much correction is required with preset start pwm.
  • edited October 2020
    Repetier said:
    Start value must be 0 pwm. We need to know the way up to t max which limits anything. Increment is ok if we want more stages. Procedure is more or less what I was thinking of.
    Why does it have to start at 0 PWM? Who is interested in the temperature range of 20-140°C for the nozzle? It's better to have a higher resolution at the desired temperature range. Assuming you know roughly which PWM corresponds to the lowest and highest temperature, you can calibrate 150-270°C (Delta T=120°C). If add 20-150°C (Delta T=130°C) you need more than double the time for nothing.
  • Someone will enter lower temperatures. Then it still has to work. Plus it makes math faster if we can say we have a value every x pwm change. Then I don't need to store position and value - only step width and values. But I think we need to make step width fixed at compile time. We need to store it all in eeprom so space needs to be known at compile time. Anyhow - lets do some testings first then I can also say if it is more or less linear or not. The more linear it is the less I need to measure. Also if it is quadratic we could also get a regression curve through points. I think it would be best to get a approximate equation at all. Then only a few points more then factors are required to minimize the error.
  • edited October 2020
    I agree.
    I will do the testing with the "change heater / fan" trick maybe in the evening and will report here.
    Edit: If it is linear (what I do not expect), we need one calibration point, because we know at 0 PWM there is zero heating/room temperature. I would expect that the behaviour can be determined by two or three calibration points, if it is somehow logarithmic or so. I will check that.
  • Here we go:

    In thje log-log plot there is a fine linear behaviour, meaning this can be described by a simple potential function.  With three points one can calculate this slope very easy.

    The file tooke 2.5 hours, between each data point was roughly a small beer.

  • You have a high power extruder as it seems. 244°C at 95 pwm. But you already see that it is not fully linear. Quadratic trend matches quite good here. And with lower powered extruders it will flatten a bit more on the right I guess. Good thing is we already have LeastSquareQuadraticRegression1D to get a regression quadratic equation. And since the curve is for a first approximation small deviations are not that problematic. So guess we should start with quadratic first.
  • edited October 2020
    General comment:
    A different heater will NOT change the curve. It will just change the value on the x-axis. Every PWM corresponds to a certain Power (in W). It will not change the curvature if you have to set PWM=200 or PWM=100 for a desired value. In fact in both cases you for example P=15W or so.

    Mathematical description:
    I would assume a behaviour like
    T(x)=a x^b+c
    where x is the PWM value. T is the Temperature; a,b,c consants which will be determined.

    c is T(0), that's simply the offset to clarify, that we do not start at (0|0), but (0|21) for example.

    T(x)=a x^b+T(0) | -T(0)
    T(x)-T(0)= ax^b | define DT(x)=T(x)-T(0)
    DT(x)=ax^b formula (I)

    Measure two points:
    In my case I use the following:
    T(95)=244 --> DT(95)=223=DT(x2), with x2=95
    T(40)=108 --> DT(40)=87 =DT(x1), with x1=40

    To determine the exponent, one can use the slope in a log-log-plot, determined via the differential coefficient:
    b= Slope=(y2-y2)/(x2-x1)
    in log-log-Plot:
    b=(log(T(x2)-log(T(x1) ) / (log (x2)-log(x1)) (this is the first thing which needs to be calculated during calibration)
    = (log( 223)-log(87))/(log(95)-log(40))
    = 0.8382

    To determine a put in b and (x2|T(x2)) in formula (I):
    DT(x2)= a x2^0.8382
    223=a *95^0.8382 | : 95^0.8382

    or in general:
    a=DT(x2)/x2^b (this is the second thing which needs to be calculated during calibration)

    Put a and b in (I):
    DT(x)=4.90 x^0.8382
    You can find this now in the excel file:

    The upper formula describes the temperature at a given PWM. Lets find x:

    DT(x)=4.9 x^0.8382 | : 4.9
    DT(x)/4.9 = x^0.8382 | ^1/0.8382
    (DT(x)/4.9)^(1/0.8382) =x

    x=((Tdesired-Troom)/4.9)^(1/0.8382) (this is the calucation of the PWM in dependence of room temperature and desired temperature)

    So there we are. Measuring T(0PWM), T(40PWM) and T(95PWM) as calibration is fine. The deaviation is 4°C. Combined with a regulation dyndeadtime that could be fine.
  • I think this easy calibration of the combined regulation and control would be a nice try.
Sign In or Register to comment.