• 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.
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.
Once the inputs and outputs required have been established, we can provisionally assign them to particular pins (Table 4.7
Pin | Label | Type | Board | Description |
---|---|---|---|---|
RA0 | Tempin | Analog in | TEMP | Range 0–50°C=500–1000 mV |
RA1 | Lightin | Analog in | LIGHT | Range 0–5 V, needs calibration |
RA2 | SetTemp | Analog in | POT1 | Range 0.5–1.00V, set target temp |
RA3 | Vref+ | Analog in | POT2 | Adjusted to 1.024V |
RA5 | Startin | Digital in | SW2 | Active low, push button, start system |
RA6 | Stopin | Digital in | SW3 | Active low, push button, shut down |
RE3 | Reset | Digital in | SW1 | Active low (hard wired) !MCLR |
RD4 | RunOK | Digital out | D0 | Active high, status indicator LED |
RD5 | Fault | Digital out | D1 | Active high, status indicator LED |
RD6 | FanPWM | Digital out | PWM4 | Active high, DC motor, DRIVE 4 |
RD7 | FanEn | Digital out | N4 | Active high, DC motor drive enable |
RC5 | FanInt | Digital in | CCP1 | DC motor pulse feedback OPT. INT |
RD1 | Heat1 | Digital out | N1 | Active high, heater 1 on, DRIVE 1 |
RD2 | Heat2 | Digital out | N2 | Active high, heater 2 on, DRIVE 2 |
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
3.19.14.243