21
SINGLE SET POINT CONTROLLER WITH REMOTE INHIBIT CAPABILITY

Project 7

In this project, we take the dual temperature thermometer we have made and turn it into an adjustable programmable single-point controller that can control one property (not necessarily a temperature) in a process. The instrument can be controlled remotely. See Figure 21.1.

Any controller needs the following basic properties to be both useful and easy to use:

1. Have a set point that can be adjusted with ease

2. Have a detector for the property being measured

3. Have an output signal that is made available after 1 and 2 are compared

4. Have an input that can inhibit the operation of the controller from a remote location

Our dual temperature controller already has two inputs. One of these can easily be converted into a control point with the addition of a simple 5000 Ohms potentiometer. We also need to add a couple of connections for an output signal and we need to have a way to inhibit the operation of the system should we require it. This can be done with a simple Single Pole Single Throw (SPST) switch that can be located remotely wherever we want.

It can also be useful to have a switch that reverses the operation of the controller (in other words, that turns the outgoing signal on on an increasing rather than decreasing value, and vice versa). This is bought to your attention so you are aware of this feature, but it will not be undertaken on this project. It is simple enough to add a switch to do so.

THE CONTROL STATEMENT

“If the signal at the detector is less than (or more than) the
control point, and if the inhibit signal is not CLOSED, then
provide an output signal on the output line.”

f0294-01

Figure 21.1 A single set point controller with inhibit. (When this board is mounted on a box, the temperature setter and the inhibit switch can be mounted on the box side or they can be mounted at remote locations.)

This is typical for most single-point controllers like a residential thermostat, a small hot water heater controller, or any number of similar on/off controllers. More importantly having the “remote inhibit” capability allows this controller to be controlled by another instrument (remotely).

Let’s create the output on PORTA.5 and the inhibit signal on PORTA.3 because these are the two lines we have available on the board as it is. We have kept PORTA.4 free because this is the line that is used for some of the counter inputs in the PIC 16F877A. (In our case, PORTA.5 also just happens to be free.)

The additions to the hardware circuitry on the dual temperature sensor are shown in Figure 21.2.

In the software, we have to read the two analog signals, the set point and the controlled point, and make the necessary comparison. Then, based on the calculation, we need to turn the output signal on if the inhibit signal is not present. (Open in our case.)

The set point adjustment device is a potentiometer placed between 5 volts and ground. We read the wiper position of this potentiometer to get a reading between 0 and 255 as we have done many times before. This reading can be converted to the set point we need mathematically. (Remember that in the metronome project the 0–255 wiper position was converted to a number between 40 and 208.)

On the controller input, the variable we are reading can be any signal that can be converted into a resistance or a voltage. The conversion is to the equivalent of a 0-to 5-volt signal and is read into the microcontroller just as we did with the temperature readings. However, it does not have to be a temperature. What we are really

f0295-01

Figure 21.2 A single-point programmable controller. (Made from the dual thermometer device.)

reading is a voltage. Knowing the range of the signal we will be reading allows us to design a suitable electronic network to give us the range we need to feed into the microcontroller.

The input does not have to be a voltage or a resistance either. It can be a frequency that we can read with the COUNT and PULSIN commands. Similarly, the output does not have to be an on-off signal. It can just as easily be a pulse width modulated (PWM) signal or a frequency if that is desired.

With the preceding in mind, we will develop the thermostatic controller based on (1) the LM34 sensor because we already have the sensor and (2) discuss a thermistor-based controller because thermistors are inexpensive and give us an opportunity to read in a signal another way.

THE LM34-BASED CONTROLLER

The code development for using the LM34 is shown in Programs 21.1 and 21.2. The code uses the same nomenclature as was used for the dual thermostat instrument, but it modifies the code that was developed. The specific code for reading the two inputs does not have to be modified because in either case we are reading the equivalent of two potentiometers. We need to add code in the main loop to

1. Read the inhibit signal

2. Read the two inputs

3. Make the necessary comparisons

4. Output the result of the decision-making process as discussed earlier

Program 21.1 Inhibit code (Single-point programmable controller)

IF INHIBIT=1 THEN         ; if the inhibit switch is ON
   PORTB.1=0              ; turn OFF the signal
ELSE                      ; else
  IF VAL1 > VAL2 THEN     ; make comparison of the two values
     PORTB.1=0            ; turn OFF signal
  ELSE                    ; else
     PORTB.1=1            ; turn ON the signal
  ENDIF                   ; end of comparison
ENDIF                     ; end of inhibit comparison

THERMISTOR-BASED CONTROLLER CONSIDERATIONS

In order to use a thermistor, we need to add some hardware to make it easier to read the thermistor. The goal is to get a usable range of readings from the thermistor in the temperature range we are interested in. Thermistors with a high resistance and a high rate are easier to use because we need a minimum resistance of the total network to be 2k ohms or higher across the 5 volts we are using across the bridge.

The thermistor I used had the following properties:

Resistance at 70°F

1000 ohms

Delta

25 ohms per degree Fahrenheit in positive direction

Low temperature of interest

32°F

High temperature of interest

300°F

Under ideal conditions, the bridge we design would provide a signal close to 0 volts at 32° and close to 5 volts at 300°F. The network would have an overall (lower) resistance of about 5k ohms so we don’t overload the power supply. A simple network is not going to be able to do this, but a usable network is possible.

From the preceding data we can calculate that the thermistor has about 50 ohms resistance at 32°F and about 6750 ohms at 300°F. If we put a 5000 ohms resistance in series with it, the thermistor can be connected to the PIC, as shown in Figure 21.3. The analog signal value we will read on the A-to-D conversion will be from 146 to 252.

 

(50/5050)*255 = 2.52

255 − 3 = 252

at 32°F

and

(6750/11750)*255 = 146.49

255 − 146 = 109

at 300°F

f0297-01

Figure 21.3 Circuitry for a thermistor connection to PIC. (Thermistor resistance can increase or decrease with temperature.)

As always, we need a resistance of about 5000 ohms in series with the thermistor so the circuit will not short across the power supply by drawing too much current when the thermistor is at its cold extreme.

In the usual case, the resistance in the circuit should be selected to match the ambient temperature resistance of the thermistor. This will give a reading of 127 or the wiper middle position at the ambient temperature. The resistance can be varied to raise and lower the ambient temperature reading. The total resistance of the resistance and the thermistor should be at least 5000 ohms for most applications.

The sensitivity of the readings will be best if the effect of the change in resistance of the thermistor is such that the range expected is approximately the same as the pot value; however, as mentioned earlier, the total resistance should not get below about 4k ohms to keep from overwhelming the power supply

Some other reliable method should be available to confirm that your instrument is providing accurate values for the temperatures being measured.

Other devices are used in a similar way. If a device provides a voltage, the voltage can be divided or amplified to be at a suitable level and then connected between ground and the input port pin. A reference voltage does not necessarily need to be connected to the PIC. Select and connect the Vdd source to suit.

READING THERMOCOUPLES

Thermocouples provide extremely low voltages and almost no current so we have to approximate the conditions provided by a Wheatstone bridge to read them. Alternatively, op amps that amplify the signal can be used. The industry provides a number of ICs that allow each of the types of thermocouples to be read into a PIC-type microcontroller with relative ease.

Program 21.2 Single-point controller: full program (This program runs on the board that fits on the box from All Electronics. See Figure 21.1 for an illustration.)

CLEAR                            ; clear all memory locations
DEFINE OSC 4                     ; system osc speed
DEFINE LCD_DREG PORTD            ; define LCD connections
DEFINE LCD_DBIT 4                ; data starting bit
DEFINE LCD_BITS 4                ; number of data bits
DEFINE LCD_RSREG PORTE           ; select register port
DEFINE LCD_RSBIT 0               ; select register bit
DEFINE LCD_EREG PORTE            ; enable register
DEFINE LCD_EBIT 1                ; enable bit
DEFINE LCD_LINES 2               ; lines in display
DEFINE LCD_COMMANDUS 2000        ; delay in micro seconds
DEFINE LCD_DATAUS 50             ; delay in micro seconds
LOW PORTE.2                      ; puts LCD in write only mode
DEFINE ADC_BITS 8                ; set number of bits in result
DEFINE ADC_CLOCK 3               ; set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50           ; set sampling time in us
VAL0 VAR BYTE                    ; create to store result
VAL1 VAR WORD                    ; create to store result
TRISA=%00111111                  ; set PORTA
TRISB=%00001000                  ; set PORTB
TRISD=%00000000                  ; set PORTD
TRIS =%00000000                  ; set PORTE
ADCON1=%00000010                 ; set analog pin selections
                                 ;
PAUSE 500                        ; pause to start up LCD
LCDOUT $FE, $01, “CLEAR”         ; display Clear message
PAUSE 500                        ; pause to see message
LCDOUT $FE, $01                  ; clear the screen
PORTB.2=0                        ; ground this
OPTION_REG.7=0                   ; pull all PORTB inputs high
LOOP:                            ; main loop
ADCIN 0, VAL0                    ; read channel 0 potentiometer
ADCIN 3, VAL1                    ; read channel 3 temp
VAL1=10*VAL1/5                   ; calculate VAL1
LCDOUT $FE,$80,”TMP=“,DEC3 VAL1  ; display information
LCDOUT $FE,$C0,”SET=“,DEC3 VAL0  ; display information
IF VAL1>=VAL0 AND PORTB.3=1 THEN ; compare to setting
  PORTD.3=0                      ; set PORTD.3=0
ELSE                             ; or
  PORTD.3=1                      ; set PORTD.3=1
ENDIF                            ; end decision
IF PORTB.3=0 THEN                ; see if inhibit is on.
  PORTD.2=0                      ; set PORTD.2=0
ELSE                             ; or
  PORTD.2=1                      ; set PORTD.2=0
ENDIF                            ; end decision
PAUSE 10                         ; delay 0.01 seconds
GOTO LOOP                        ; go back to loop and repeat
                                 ; operation
END                              ; end of program