Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID settings wrong #221

Open
sevstels opened this issue Jan 7, 2022 · 10 comments
Open

PID settings wrong #221

sevstels opened this issue Jan 7, 2022 · 10 comments

Comments

@sevstels
Copy link

sevstels commented Jan 7, 2022

//Heater PWM modulator have range 0...255
del: PID_SetOutputLimits(pid, 0, 0xffff); <-wrong limit
PID_SetOutputLimits(pid, 0, 0xff);

//default Controller Sample Time is 0.1 seconds
del: SampleTime = 100; <- wrong sampling rate
pid->SampleTime = 250; //250ms loop sample perod

@xnk
Copy link
Member

xnk commented Jan 7, 2022 via email

@sevstels
Copy link
Author

sevstels commented Jan 8, 2022

the original PID code of the controller

That was not the correct my translation to eng.
I meant your original version.

255+248

In my opinion, the system will work properly if the integral component does not have an offset relative to zero.
In this version, the dynamic control range will become larger without too much trouble.

  ///PID_SetOutputLimits(&PID, 0, 255 + 248);
  PID_SetOutputLimits(&PID, -255, 255);
  ......

  PID_Compute(&PID);
  signed short pid_out = (signed short) PID.myOutput;
  
  //cases
  if(pid_out >=0)
  { 
    //---- Heating
    //Heater control
    *pHeat = (unsigned char)pid_out;
    
    //Run at a low fixed speed during heating for now
    *pFan = STP.fan_speed;    
  } 
  else 
  {
    //---- Cooling 
    //Disable heater
    *pHeat = 0;
    
    //Fan control
    if(pid_out<STP.fan_speed){ *pFan = STP.fan_speed;} 
    else{*pFan = (unsigned char)(-1*pid_out);}
  }

@sevstels
Copy link
Author

sevstels commented Jan 8, 2022

In any case. The PID coefficients are is not correct.

PID_SetTunings(&PID, 20, 0.016, 62.5);

Consider the simplest case where only the channel P is used.
This is a simple proportional amplifier that performs the multiplication operation: param x Pk = out.
To heat up the board to 200 degrees, we only need about 600 watts of power.
That would be 600/800*255 = 191 heater PWM control value.

For example we need to go from 30 degrees to 130 degrees. The delta is 100.
If you use Kp = 20. Then after the first calculation cycle you will get control channel overload: 100 x 20 = 2000. And the maximum PWM control value of the heater is 255. But you need add only191, if more correctly: 191x0.8 = 153. You have a gain overload: 2000/153 = 13 times.

With such wrong coefficients, the system goes into "relay control" mode like an ordinary toggle switch. It will oscillate all the time due to loss of stability in the control loop due to excessive loop gain. See the theory of automatic control systems. For example the Nyquist stability criterion.

@mikeanton
Copy link

You only need enough power to make up for the losses in the oven that gets you to 200C. But this says nothing of the time it takes to get there. You would be better with maybe 1800W of power to reach the temperature in a more reasonable period of time. So I'm not sure why you base anything on the power you think is required to reach a certain temperature, as this isn't really all that important. It is more about the power required to get you there in a given period of time. These ovens are generally underpowered, so usually you want the elements to be turned on hard at the start to decrease the risetime, and then back off as the setpoint is reached so as to not overshoot. Planning for a reduced heating rate from the start makes no sense at all.

Overflow of the calculations is generally handled by saturating the output value, as in if it is over 255, then force it to 255.

It is not the same as relay control, since as the temperature approaches the setpoint, the value will be reduced, so with a 10 degree differential, the output value is now 200, and keeps reducing as you get closer to the setpoint. Whether a gain of 20 would be too high or not would need to be determined through measurements.

Also note that strictly proportional control is not what it used, and the I and D terms also play into the equation to help control overshoots, and oscillations. In general, strictly proportional control will never reach the desired setpoint, as you need some output to keep the heaters on to maintain temperature, so the I term at a minimum is requires as well as P. It is the I term that is accumulated due to the error that gives sufficient output to maintain a given temperature.

@sevstels
Copy link
Author

sevstels commented Jan 8, 2022

Anyway. The theory of automatic control systems has long been developed and is explained in detail in universities. The loop gain cannot be more than 1. Otherwise the system loses stability. This mathematics is correct and works even in another galaxy. At an overload of 13 units the stove will ALWAYS WORK WRONG.

https://en.gradient-sg.com/t962/#pid

@sevstels
Copy link
Author

sevstels commented Mar 1, 2022

I took some extra time and compared the quality of the firmware and made short conclusions.
You can see the results graphically.

Two versions were compared:

  1. UnifiedEngineering v0.5.2
  2. S3D v0.6 regular

The operation of the v0.5.2 firmware, due to code errors, is probably a danger to your electrical network due to nearly 1 kilowatt spikes in power consumption. This can cause overheating of conductors and connectors and cause a fire. As I wrote above, due to errors in PID settings - the temperature inevitably oscillates. Thank you for your attention.

@xnk
Copy link
Member

xnk commented Mar 1, 2022 via email

@sevstels
Copy link
Author

sevstels commented Mar 1, 2022

The lack of zero crossing detector gives a maximum irregularity of only a quarter of the power period. Or about +-7 watts. You have an unevenness of about half a kilowatt. When I told you there were errors in the firmware, you didn't want to discuss it and laughed.

Even if you fine tune the PID, the ripple in the power supply will remain. Only the fine sinusoidal oscillation will disappear. You should revise your code again to fix this. Cosmetic "improvements" will not help. For example, the S3D version runs on scmRTOS, which already gives significant advantages and stability in the execution of regulation.

@GitLang
Copy link

GitLang commented Mar 1, 2022

Sev, do you understand how PWM works and how it varies the average power delivered to the load?. I'm pleased to say my oven also toggles between 0 and 2.xkW just as it should.

This can cause overheating of conductors and connectors and cause a fire

That is incorrect. As long as the rms load is within the rated value of the supply, it is fine. No fault, by law here, may damage cable or infrastructure, the fuse or circuit breaker at the distribution box must protect the cable and installation. A typical 3kW domestic outlet here will happily pulse between 0 and 3kW day and night.

I don't know which oven you have, but mine switches the heating elements with a solid state relay which has zero crossing switching.

@sevstels
Copy link
Author

sevstels commented Mar 1, 2022

It's all theory... how and what should be clear to everyone. But in real life it is the opposite. At least because there is oxygen in the atmosphere and there is continuous oxidation of the contacts. That's why there are fires... I hope you will not deny the presence of oxygen and oxidation. In addition to your solid state relay, there are a significant number of connections and contacts in the circuit up to the power distribution station. These contacts or strands have a surface connection resistance and will heat up. And by creating a serious current ripple in this circuit you inevitably provoke a catastrophe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants