# Algorithm for converting PID analog output signal to discrete ON/OFF

W

#### Will Knowles

In the process of constructing a gas-phase reactor for our research at Rice University, we have everything in place to control temperature except the MISSING LINK. The reactor is wrapped in heat tape, which is wired to a solid state relay (can only take on/off signals). Our DCS system has a digital output board to send the on/off signal to the SSR.

Our DCS reads a thermocouple, performs a PID control calculation, calculates a new output value (analog signal). The MISSING LINK is an algorithm to convert the PID output to a digital signal.

This is nearly identical to using an air conditioner to control the temperature in your house... essentially converting a desired temperature to a square wave to turn the AC on/off. However in our case, our time constants are much shorter and we can't allow much over/undershoot.

Any suggestions or leads you can offer will be greatly appreciated!

B

#### Bill Clemons

I suppose it depends on whether your output board can successfully negotiate pulse width modulation. If that's the case (as often is with SSR outputs), then take your output signal (0-100%) and apply it to some duty cycle function. You mentioned you are using a DCS. Likely there is a built in timer function which you can parse into an on/off signal proportioned to your PID output. Finally, write your discrete output to your output channel.

Out of the box PWM SSR PID control reading thermocouple can be had for about 600.00 USD in a 1/4 DIN panel mount. Likely, less if you're not too picky about the interface.

M

#### matt hyatt

Why not take the AO, convert it to a voltage (current across a resistor) and use this as a PWM signal through a FET to control the SSR?

Just an idea. Would probably work very well.

drop me a note if you need some input.

Matt Hyatt
Technical Consultants
[email protected]

D

#### david mertens

The standard approach to your problem is to define a fixed time e.g. 1 minute and then to set the output to ON for x% of the time with x being the output of the PID controller. (x = 0 -> no heating, x = 25% -> 15 seconds heating, x = 50% -> 30 seconds heating, x = 100% -> 1 minute heating). This is done every timebase (1 minute in our example). The timebase should be selected in a way as to give a good controlling resolution, if you set the timebase too short, your switching devices will be wear out and the heating cable will probably only heat up locally, not over its entire length. When you set the timebase too long then it will be difficult to get a good control as the product temperature will overshoot the target.

Kind regards and good luck

H

#### Hoffeldt, Herman

Hi Will

What type of DCS are you using. I have seen a quite good algorithm on a Moore Apacs DSC. The output signal of the pid (0-100%) is converted to a frequency signal. Eg, 0% = 0 pulses/min, 50% = 10 pulses/min, 100% = 20 pulses/min. The output of this block then went through a bistable( ie
kept the signal output high for say 4 seconds ). This output is then passed to the solid state relay. I found that this works very well.

The second method is to use a counter that ramps up to say 100 counts. The speed of incrementing the counter is determined by a timer that pulse the counter say every 0.5 seconds. The value of this counter is then directly compared with the output of the PID block, and if the
(counter_value > PID_OUTPUT) set SSR = OFF, else set SSR = ON. I have used this type of algorithm a lot with PLC's. It is easy, and use little processing power since you only need one timer and one counter to do all you solid state controls. For each PID output, you only need to do a comparison, and that is it.

Herman

J

#### Johan Bengtsson

The solution is PWM (Pulse Width Modulation)

Basically you turn on the output, wait a moment, turn it off, wait a moment and repeats this. The amount of time on compared to the entire cycle should equal the analog value.

Select a cycle time

For each cycle:
1. Get the analog value, scale it to 0-1
2. turn on output (unless analog value equals 0)
3. multiply analog value with the cycle time, and wait that amount of time
4. turn off output (unless analog value equals 1)
5. wait the remaining time until the comple cycle time is reached
6. goto 1

Example:
cycle time = 4s

1. Get analog value, for example 75% -> 0.75
2. turn on output
3. wait 0.75*4=3s
4. turn off output
5. wait 4-3=1s
6. goto 1

This gives output on 3 of 4 seconds, that's 75% of the time and thereby 75% of the maximum power.

/Johan Bengtsson

Do you need education in the area of automation?
> ----------------------------------------
> P&L, Innovation in training
> Box 252, S-281 23 Hässleholm SWEDEN
> Tel: +46 451 74 44 00, Fax: +46 451 898 33
> E-mail: [email protected]
> Internet: http://www.pol.se/
> ----------------------------------------

U

#### U.

What about pulse-width-modulating the heater signal?
You need to decide on a period for your signal (5 sec, 1 min, etc) and a 0-100% range for the signal from the PID. 0% will give an all off signal, 100% will give an all on signal. 50% will make a pulse with equal on and off time. Anything else should produce a pulse with ON time strictly proportional to the % output from your PID. (Remember to check your PID's 'Wind-Up' function...) I don't have the algorithm but if you have 2 timer resources (1 for the constant period, 1 for the varying pulse width) you should do fine. I guess this approach is for an ideal heater, not taking into account the lag in the heater, which now also a part of your process model.

J

#### Joe Markham

This is often done by implementing a 'duty cycle'. This is done by taking a period of time and then mapping the output of the PID to the percent of that period that the heater is on.

For example, if the cycle time is 10 seconds, and the PID output is 25%, the heater would be on for 2.5 seconds, then off for 7.5 seconds.

Generally, the PID loop is only solved once per cycle. Note that the cycle time and the tuning of the PID will interact, so you want to pick a cycle time, then tune the PID. The length of the cycle sill directly affect how closely you can control the temperature.

Good luck!

J

#### JF

We have a similar process but with 4 staged digital outputs in Honeywell TDC3000. We use a logic block to read in the PID output value and set the digital outputs ON/OFF based on comparison with numerics. If the PID output is over 20%, DO #1 is set on; 40% for #2, 60% for #3 and 80% for #4. There's a 5% deadband for each comparison.

If one digital output doesn't maintain temperature at setpoint, you might consider multiple circuits of heat tape. Using a logic point as described also allows for other inputs, such as high temperature or pressure shutdown.

- JF

P

#### Profhet

Expertune might be a spot to go, and seeing that your an educational institute, they might give u a free copy or help you out.

B

#### Bob Welker

1. Define a suitably short duration time base. Ten seconds ought to do, but it can be shorter if desired.
2. Define 100% PID output as an on-time equal to the time base.For instance, 10 seconds on = 100% output.
3. Define 0% PID output as an on-time equal to zero.
4. For everything in between multiply the PID output % by the time base, and use this as the on-time. For instance, 50% output equals 5 seconds on-time, 25% output equals 2.5 seconds on, etc.

This technique is called time proportioned PID output.

A

#### Anonymous

> In the process of constructing a gas-phase reactor for our research at Rice University, we have everything in place to control temperature except the MISSING LINK. The reactor is wrapped in heat tape, which is wired to a solid state relay (can only take on/off signals). Our DCS system has a digital output board to send the on/off signal to the SSR.
> Our DCS reads a thermocouple, performs a PID control calculation, calculates a new output value (analog signal). The MISSING LINK is an algorithm to convert the PID output to a digital signal.
>
> This is nearly identical to using an air conditioner to control the temperature in your house... essentially converting a desired temperature to a square wave to turn the AC on/off. However in our case, our time constants are much shorter and we can't allow much over/undershoot.
>
> Any suggestions or leads you can offer will be greatly appreciated!

Try transforming your PID analog control to a discrete signal by using say z transforms or if you donot like this try converting it to a pulse width modulated signal.

A

#### Anonymous

Well, I assume you want to maintain a target value of X. Add comparisons that energize the coil (turn on a bit)if your analog is between those target analog values. You can calculate dead bands for control or your DCS may provide such instructions.

S

#### Steve Myres, PE

Solid state relays are available which will accept an analog signal and switch the load accordingly. In this instance you will need to have an analog output from your DCS.

Another approach is to take the output of the PID loop, expressed as a percentage and multiply by some time base which you select. So for a 30% power output, turn on the SSR for the first 3 seconds of a 10 second timebase, or the first 6 seconds of a 20 second timebase.

The key to doing this approach well is the selection of your timebase. From a purely mechanical and temperature control perspective, the shorter the timebase the better. A very short timebase will give smaller steps in the power dissipation, thus giving better temperature control, and minimize the mechanical fatigue effects on the heating element, which grows when the power is flowing and shrinks when the power is turned off.

But, if the solid state relay is of a zero crossing type, it can only change state every 8.3ms, and this will limit the resolution of your control action if you choose a small timebase like a tenth of a second or something like that. If it is the random turn on type, you can ignore this issue.

So you have to look at the thermal storage capacity of your heating elements and heated system, how much accuracy you need, and make a choice that takes both factors into effect. I'm picturing a "reactor" as being a vessel with pretty substantial walls, and heat tracing tape doesn't change temperature very quickly, like an infrared emitter, so a timebase somewhere around 10 seconds may work out OK for you.

J

#### John Shaw

You can turn the power to the heat tape on and off in a time proportioning control. In this scheme you first choose a cycle time that is much shorter than the time constant of the reactor. Then the output of the PID algorithm (0 to 100%) is converted to percentage of time that is on. For example if the cycle time is 10 seconds and the PID output is 50%, the digital output will turn on for 5 seconds and then turn off for 5 seconds. If the PID output is 85%, the output will turn on for 8.5 seconds and then turn off for 1.5 seconds.

Some DCSs provide built in functions to do this function. In others you can connect various function blocks together or write a separate program to do the conversion. It depends upon the type of DCS. You can check with the vendor.

John Shaw
www.jashaw.com/pid
www.controlviews.com

J

#### JimU

You want to do "time proportional control". Scratch around in your DCS documentation to see if this can be easily done. Otherwise you'll have to cob something together to achieve the same effect.

A

#### Alberto

We have an application in which the output of a PID is used to control the duty cycle of a pulse with modulated signal turning the heater On and OFF With a fast frequency, you can get tight control.

T

#### Tim Jackson

The simple answer is to run a 256 step cyclic counter to switch the output on whenever it resets, and another counter running to 1..255 according to the analogue value which switches it off when it runs out, also reset by the first counter.

With an SSR this means that you get a cycle time of 2.13s (US) or 2.56s (UK) for 8-bit resolution which might generate too much ripple if you don't have much thermal mass.

I've got an algorithm written in assembler code for an MC6809 microprocessor which does a very neat job of this. It uses a coarse time clock to determine the immediate output pulse duration, then modulates this from cycle to cycle to achieve precise control on a longer timescale. It is part of a software DC drive emulator that I use in my industrial control panels.

I use it with a 1800hz clock to generate thyristor phase control on a 10ms cycle but it would also work with a 60Hz clock and zero-point switching on, say, a 3Hz cycle.

This achieves 8-bit analog resolution with much less ripple than associated with a long-sequence burst-fire method.

If you email me I can send you the code and/or a long description of the algorithm, if you want to try to adapt it for use on your DSP.

[email protected]