z. Tips on making a fail-safe thermostat with 16-bit digital temperature sensors

Once you have thermostat circuit operational, you have to properly install it and test it. While it is relatively easy to pack the PCB into a plastic casing, there is still work to be done to make a useful fail-safe thermostat.

PIC32MX250F128B microcontroller needs a reliable power source. Though it can also be powered from a USB port, it is advisable to use an independent power supply. This enables the thermostat to operate without support of a PC. PIC32MX250F128B needs a stable 3.3 V= power supply. The adjustable voltage regulator LM317T can provide 3.3 V with proper selection of R1 and R2 resistors. LM317T can operate on input voltage between 5 V= and 15 V=, but it is recommended not to use an input voltage above 7 V to reduce regulator hating and power usage. If you use a higher than 7 V power supply, sufficient cooling must be provided for LM317T, or an intermediate voltage regulator should be used to reduce the power supply voltage below 7 V. Relays should use their own power supply with up to 50 V= accroding to their operating voltage.

An additional 1000 µF capacitor may be added between ground and PIC32MX250F128B power supply to further stabilize voltage for PIC32MX250F128B microcontroller, if you use long power supply lines.

Refrigerators have electrical compressors that pump the refrigerating liquid and draw a lot of draw current when they start to operate. An electrical spark from the compressor’s electrical motor may disturb the temperature sensors operation via I2C bus. It is though important to provide shielding for 4-wire cable that carries I2C bus signals.

PIC32MX250F128B has an internal watchdog counter, which enables automatic the microcontroller restart, if it becomes unresponsive. When the watchdog counter counts down to zero the microcontroller is automatically reset. During normal operation the microcontroller firmware should periodically reset the watchdog counter by setting WDTCLR bit in WDTCON register. This is done automatically at each repetition of the main program loop in the PIC32MX250F128B v2.8.81 firmware, if the watchdog functionality is enabled in

I2C bus devices are usually more sensitive to electromagnetic disturbances than the microcontroller. PIC32MX250F128B firmware v2.8.81 – thermostat edition has an inbuilt safety feature that allows it to perform hardware or software resets of the I2C bus. A software reset is performed by sending a reset general call command (code 6) to all devices on the I2C bus. Each device must decode the command and restart. However, it is a “choice” of each device to restart, or not. Though software reset is inefficient in cases when some external devices are locked and unable to decode it.

Hardware reset is slower, but much more efficient. I2C bus power supply is switched off and the power line is connected to the ground for about a second. This forces all the bus powered I2C devices to shut down. Next, the power is reapplied. The attached devices should start to operate normally, except in case of hardware damage. A leftover relay was may be used to perform the hardware reset function.

The length of the I2C bus (cable) is also important. A longer cable only allows slower speeds. PIC32MX250F128B I2CxBRG register makes it possible to lower the baud rate to about 25 kHz (value 0x308). Communication speed can be additionally lowered by setting peripheral bus clock (PBDIV) ratio. There are 4 settings: 1:1, 1:2, 1:4 and 1:8. The last setting enables one to lower the I2C bus speed to 1/8 of the speed that would be achievable with I2CxBRG register alone. The choice of a resonator crystal or an external oscillator is also important. If you seek the lowest possible I2C bus speed, than the best option is to go for a 4 MHz crystal or a 4 MHz oscillator. Optionally a microcontroller can communicate to the external device at arbitrary low speed programmatically without using the inbuilt hardware support. However, it is important it is important to stress that not all I2C devices support arbitrary bus speeds. The standard speeds are: 100 kHz, 400 kHz and 3.4 MHz.

NOTE: Use thermally shrinkable insulating plastic tube to incase ADT7410 temperature sensor. The sensor contacts must be insulated to prevent short circuit in contact with the refrigerator or supplies stored in it.

ALSO READ:

- 16-bit thermometer and thermostat: DigiTM application with source code

- ADT7410 & PIC32MX250F128B: 16-bit digital thermometer

Themostat testing and operation. Click on the photos to enlarge them.

Temperature sensor in thermally shrinkable insulating plastic tube.