4.6. PICDEM Temperature Controller

• Specification of temperature controller

• Input and output allocation

• Program outline

The PICDEM mechatronics board will now be used as the hardware platform for a temperature controller. Using a ready-made board eliminates the need for detailed hardware design and should be considered if a suitable product is available at a reasonable cost.

Specification

A temperature controller is required to control a greenhouse or similar outdoor enclosure at a temperature of 25–30°C using electric heaters and a cooling fan.

1. Overall function

• Maintain target temperature within +/−2°C, displaying it on the LCD. If the temperature is within specifications, switch on RunOK indicator; if temperature difference exceeds 5°C, switch on flash fault indicator.

2. Startup procedure

• Power up the system, reset the fault indicator.

• Display the set temperature on the LCD for operator adjustment.

• Wait for the start input push button.

3. Overall operation

• Switch on the first heater if the temperature is more than 2°C below the target.

• Switch on the other heater if the temperature is more than 5°C below the target.

• Run fans at a speed proportional to the positive temperature difference: If the fan speed is zero, switch on the fault indicator; if the temperature sensor is out of range, enable the fault mode.

• If the light level indicates direct sunlight, add a positive offset to the fan speed in anticipation of an additional temperature rise. If the light sensor is out of range, enable the fault mode.

The block diagram, Figure 4.13, shows the system I/O requirements.

Figure 4.13. Block Diagram of the Temperature Controller


I/O Allocation

Once the inputs and outputs required have been established, we can provisionally assign them to particular pins (Table 4.7

Table 4.7. PICDEM Board I/O Allocation for Temperature Controller (Excluding LCD)
PinLabelTypeBoardDescription
RA0TempinAnalog inTEMPRange 0–50°C=500–1000 mV
RA1LightinAnalog inLIGHTRange 0–5 V, needs calibration
RA2SetTempAnalog inPOT1Range 0.5–1.00V, set target temp
RA3Vref+Analog inPOT2Adjusted to 1.024V
RA5StartinDigital inSW2Active low, push button, start system
RA6StopinDigital inSW3Active low, push button, shut down
RE3ResetDigital inSW1Active low (hard wired) !MCLR
RD4RunOKDigital outD0Active high, status indicator LED
RD5FaultDigital outD1Active high, status indicator LED
RD6FanPWMDigital outPWM4Active high, DC motor, DRIVE 4
RD7FanEnDigital outN4Active high, DC motor drive enable
RC5FanIntDigital inCCP1DC motor pulse feedback OPT. INT
RD1Heat1Digital outN1Active high, heater 1 on, DRIVE 1
RD2Heat2Digital outN2Active high, heater 2 on, DRIVE 2

), as available in the PICDEM board. The appropriate links can later be made for testing the application.

Implementation

Output half-bridge drivers 1 and 2 control the heaters. In the final system, these are interfaced via contactors if the load operates at high voltage. For test purposes, a 6-V filament lamp is connected to the drive output to represent the heater load. The motor is operated by drive 4, with the PWM input to the bridge providing speed control. All these loads are controlled at the N drive inputs, which operate single-ended in sink mode, since the current drive is needed in only one direction. The P gates can remain disabled. The fan speed is controlled using a CCP module in capture mode. This allows low speeds to be measured accurately.

The temperature sensor is calibrated at 10 mV/°C, with an operating accuracy of ±2°C and offset of 500 mV at 0°C. The temperature range is 0–50°C, so the sensing range is 500–1000 mV. If the second pot is used to provide a reference voltage of 1.024 V, the 10-bit conversion factor is 1 mV per bit, and the temperature is easily calculated in the program by subtracting 500 from the input.

The light sensor needs to be tested to establish the output level when exposed to sunlight and a threshold value incorporated into the program, so that the cooling boost cuts in at an appropriate level. When testing the system, hot and cold air could be applied to the temperature sensor to check basic functionality, but the set temperature input provides a more convenient test input. If the temperature at the sensor is constant (room temperature), adjusting the set input above and below this value has the same effect as the temperature falling and rising.

If the application functions correctly, when the set temperature is adjusted to the actual room temperature, neither the heater nor motor output is on. If the set value is increased, meaning the input temperature is too low, one heater comes on. If increased further, the other heater comes on. If the set value is decreased, the input appears too high and the fan comes on. As the set value is further decreased, the fan speeds up. When the set value is returned to room temperature, all outputs are disabled. If either sensor input is disconnected (the most likely fault mode), the fault output comes on and all other outputs are disabled. The same effect is observed if the motor is stalled, simulating a fan fault.

When the real system is commissioned, the program values may need to be adjusted to optimize the system response. In this kind of feedback system, the system generally needs to respond as quickly as possible without showing instability. The loop delay time (wait for fan) and the PWM calculation might need to be modified accordingly. In commercial temperature controllers, time constant and gain values are adjustable, so that the system response can be optimized in situ.

Listing 4.16 outlines the temperature controller program.

Listing 4.16. Temperature Controller Program Outline

TEMCON temperature control system

Define & Initialize

StartIn=RA5 (0/1) Heat1=RD1 (on/off)

StopIn=RA6 (0/1) Heat2=RD2 (on/off)

LightIn=RA1 (0–255) FanPWM=RD6 (0-255)

TempIn=RA0 (0-255) FanInt=RC5 (0-255)

SetTemp=RA3 (0-255) Fault=RD5 (0/1)

RunOK=RD4 (0/1) Reset=RE3 (0/1)

Sunlit=0-255 (calibrate) FanEn=RD7 (0/1)

Startup

All outputs disabled

Loop

Read, store, display SetTemp

While Start button not pressed

Main Loop

Read InputTemp

If InputTemp out of range

Disable outputs

Wait for reset

Flash fault indicator

If (TempIn-SetTemp<(−2))

Switch on Heat1

Disable Fan

If (TempIn-SetTemp<(−5))

Switch on Heat2

Flash fault indicator

If (TempIn-SetTemp>1))

Read FanInt

Calculate fan speed

Calculate PWM duty cycle

Read LightIn

If LightIn out of range

Indicate fault

Disable outputs

Wait for reset

If (LightIn>Sunlit)

Add offset to PWM duty cycle

Modify FanPWM duty cycle

Enable fan

Disable Heaters

Wait 5 s for fan to start

If (speed=0)

Indicate fault

Disable outputs

Wait for reset

Else enable RunOK

Always

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.237.3