Showing results for 
Search instead for 
Did you mean: 

PSoC™ 5, 3 & 1

New Contributor
3 Replies
Valued Contributor II

The capabilities of the analog PSoC part were demonstrated by odissey1 in the project
it's here:    Annotation library for CY8CKIT-059 Prototyping Kit (PSoC Creator 3.3 )
The demo project shows all-analog PID control of the levitationg globe, implemented in CY8CKIT-059 PSoC 5LP

another project for PSoC4:
PID controller project for the PSoC 4 CY8CKIT-049 42xx.
Generates PWM commands to control 3 motors.

Searching the forum will reveal a few more threads


Contributor II

Best is to write the PID routine yourself. The PID itself isn't quite complex, however it's most often the implementation which lacks and makes it not perform well.

For this you need to separate the 3 process terms:

P: the proportional part consisting of the error (setpoint - measured value): output = error * factor (P setting)

I: the integral part consisting of the accumulated value of the error (accumulated error = accumulated error + error): output = accumulated error * factor (I setting)

😧 the differential part consisting of the change in error (delta error = error - previous error): output = delta error * factor (D setting).

What I often do is convert the 3 process outputs to a range of -100% to +100%. In other words the P, I and D output can individually control the output from fully counteract to fully contribute. The output values will be added together (resulting in a range of -300% to +300%) and will be limited to -100% to + 100%. Next this PID output value has to be converted to the usable range of what you want to control. Let's say you have a PWM which ranges from 0% to 100%, then the output would be: 50% + (PID output / 2).

The loop would simply look like:
PIDerror = Psetpoint - Pmeasured
PIDerrorAccumulated +=PIDerror
PIDerrorDelta = PIDerror - PIDerrorPrevious, PIDerrorPrevious = PIDerror
Pout = PIDerror * Psetting (make sure the Pout is in a range of -100 to +100 and limited)
Iout = PIDerrorAccumulated * Isetting (again make sure Iout is in the range of -100 to + 100)
Dout = PIDerrorDelta * Dsetting
PIDout = Pout + Iout + Dout (and limit to -100 to + 100)
PWMout = 50 + (PIDout / 2)

A good practice is also to stop adding the PIDerror to PIDerrorAccumulated when Iout comes near -100 or +100 (in order to avoid wind-up).

I strongly suggest to write the loop yourself and get a grip of the process values. It's not that hard and it's great fun too. The tuning can be rather hard but as soon as you manage to log the process values into graphs, the best setting can be determined (even with trial and error).


Honored Contributor II

This  may be useful: PID without PHD