1
\$\begingroup\$

I'm currently building & programming a controller for an electrical central heating. The system has the following hardware components:

  • heater
  • pump
  • temperature sensors

To control the temperature in the heating system, the heater and the pump have to be turned on. Both are controlled by PWM.

I decided to use a PID (Proportional Integral Derivative) controller because it's commonly used in many solutions.

The first test I did was already successful with the following settings:

  • SetPoint 55°C
  • P 10
  • I 2
  • D 10 test1

The target temperature of 55°C is never reached, but I'm very happy with the stable heater results. The heater is using around 80% power which results in a stable temperature output.

I performed more tests to see if I can tune the settings to reach the SetPoint, but I discovered that the heater control becomes more unstable (fluctuates between 50% and 100%) with these settings:

  • SetPoint 55°C
  • P 82
  • I 25
  • D 70 test2

This can be explained because I'm using the output of the PID to control the heater. So the closer it gets to the setpoint, the smaller the PID output. But to keep the temperature at 55°C, the heater probably needs to be at 90% power. So how do I finetune the system? I'm thinking about:

  • put the SetPoint to 60°C and try if the PID stabilize around 55°C
  • use a bias (for example heater = 50% + PID output)

My PID controller uses the following formula:

heater = kp_gain * pid_error + (kd_gain * (pid_error - pid_error_old) / 55) + (ki_gain * (pid_error + pid_error_old) / 55);

What I'm looking for is to reach the setpoint of 55°C with a stable heater output (my guess it would be around 90%). How can I achieve this?

\$\endgroup\$
6
  • \$\begingroup\$ Did you follow a particular tuning procedure to arrive at these values? \$\endgroup\$ Commented Jul 13, 2021 at 7:40
  • 1
    \$\begingroup\$ Also your integral term looks suspicious -- it's supposed to integrate errors over the entire time, not just the last two samples. \$\endgroup\$ Commented Jul 13, 2021 at 7:44
  • \$\begingroup\$ @DamienD I have no tuning procedure. I just make a wild guess and perform a new test. \$\endgroup\$
    – spf
    Commented Jul 13, 2021 at 7:54
  • \$\begingroup\$ wild guesses cause more confusion. \$\endgroup\$
    – user16222
    Commented Jul 13, 2021 at 7:55
  • \$\begingroup\$ Look up PID tuning after fixing the mistake in your controller code. There are some more rigorous methods :) \$\endgroup\$ Commented Jul 13, 2021 at 8:21

1 Answer 1

1
\$\begingroup\$

You might want to translate those I/D "gains" into times (eg. seconds) and perhaps a percentage of full scale output for P to gain some insight into the way it works. The sample time figures into the equations.

Your I formula is either incorrect or has misleading variable names- the error must be integrated (otherwise it will never be nulled out).

I doubt you need or want derivative action. Most likely you'll need smoothing in some form if you expect to use it.

You can follow some systematic way of tuning such as Ziegler-Nichols (1942) but first your control algorithm has to be functional.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I will look into the sample times and I will improve the I formula. \$\endgroup\$
    – spf
    Commented Jul 13, 2021 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.