I want to design a PI controller in C code for controlling the system Pressure using the Current of a proportional solenoid valve. The valve is normally open, which lets the hydraulic fluid back to the tank, thus creating no pressure in the system (0 bars). If we increase the value of current, the valve starts getting proportionally closed, which in turn keeps increasing pressure. The current values of the valve increase from 0 to 2000mA. If the target pressure setpoint for a certain functionality is 35 bars, the current needed to achieve this pressure value is 400mA. The controller should set the current to 400mA based on this pressure setpoint value and measure the actual value of pressure and the increase it to the desired target setpoint of 35 bars. It is difficult for me to understand how such a controller should be designed in software. Can someone please help me with the approach for implementing this?

According to my understanding, I think the code should have an error and an integral term. It should also have values for KI and KP:

Error = SetpointPressure – ActualPressure; Integrator = Integrator + Ki * Error;

1

There are 1 best solutions below

2
Camilo Gomez On

Suppose you have all variables scaled in percentage (0-100%)

/*wt = setpoint  yt = process variable   ut = control action*/
ut = qPID_Control( &instance, wt, yt ); /* compute the control action */
/* action to the Final Control Element (FCE) should be inverse */
ut = 100.0f - ut;

just follow the same principle and scale the units according to your needs

you can use this C-code PID control library, is so robust and includes anti-windup and derivative filter https://github.com/kmilo17pet/qlibs