Loading... Please wait...

PID Controller for the CUWIN


This sample program illustrates an implementation of a PID controller for the CUWIN 5000/6000 series. The attached Visual Studio solution is a .Net Compact Framework 3.5 solution, but if you want to use it on the CUWIN 3000/4000 series, just copy the files into a .Net Compact Framework 2.0 solution. No modification should be needed.

There are two projects in this solution. PIDControllerSample is the test project that contains the UI code, and PIDControl is the project that contains the PID controller functionality.

Creating a PID Controller

To create a new PIDController, you must pass a delegate for reading the process value (PV) and another delegate for writing the controller output (CO).

_pidController = new PIDController(ReadInput, WriteOutput);

private double ReadInput()
	//Return process value

private void WriteOutput(double value)
	//send controller output

The set point can be set using the PIDController.SetPoint property.

_pidController.SetPoint = 0.0d;

PIDController operates on a timer, so once you call PIDController.Start() it will periodically call ReadInput and WriteOutput . By default PIDController uses System.Threading.Timer and its frequency can be set using the PIDController.DeltaTimeInSeconds property. But you can also pass it your own timer by implementing the IPIDTimer interface. The PIDControllerSample project includes an implementation of IPIDTimer that wraps the System.Windows.Forms.Timer.

Tuning the PID Controller

There are two classes in the PIDControl project that can be used for tuning the PIDController. PIDController.IdealTuner is for tuning according to the Ideal form (Kp, Ki, Kd) and PIDController.StandardTuner is for Tuning according to the Standard form (Kp, Ti, Td).

_idealTuner = new PIDController.IdealTuner(_pidController);
_idealTuner.Kp = 0.0d;
_idealTuner.Ki = 0.0d;
_idealTuner.Kd = 0.0d;

_standardTuner = new PIDController.StandardTuner(_pidController);
_standardTuner.Kp = 0.0d;
_standardTuner.Ti = 0.0d;
_standardTuner.Td = 0.0d;

Additional Features

Because a valve cannot be more off than all the way off, and cannot be more on that all the way on, you can constrain the output using PIDController.OutputMinimum and PIDController.OutputMaximum.

_pidController.OutputMinimum = -1000.0d;
_pidController.OutputMaximum = 1000.0d;

To mitigate Derivative Kick, PIDController's derivative term can be based on PV (Deriviative on Measurement) or on the error (Derivative On Error). Set the PIDContoller.DerivativeOn property accordingly.

_pidController.DerivativeOn == DerivativeOn.Error;
_pidController.DerivativeOn == DerivativeOn.Measurement;

Download Source Code


What's News


Contact Us

Toll-Free : (888) 9CUBLOC, (888) 928 2562
Office : (571) 322-5010
Fax : (571) 322-5011

14 Pidgeon Hill Dr. #310 Sterling VA 20165
Office Hours: Mon-Fri 8:30am-5:00pm EST

Sales: sales@comfiletech.com
TechSupport: support@comfiletech.com

Copyright 2017 COMFILE Technology,Inc. All Rights Reserved.