Needless to say, when the pi crashes while the HVAC system is heating or cooling, it may continue to do so until (hopefully) a fail safe in the HVAC system itself stops the process. This could cause some serious problems or damage, and I'm sure there are other applications where this is not desired.
Luckily, I stumbled on a comment in another post that just looked what I was after. And I decided to try to implement that solution.
The basic idea is that when Debian or the CPU of the Pi crashes, a GPIO pin may get stuck.
By using PWM pulses as kind of hart-beat, when the CPU or Debian crashes, it will no longer send out PWM pulses. I cannot find a verification for that fact, but it seems very logical. Anyway, by using the PWM feature of the GPIO drivers to drive a relays with some additional hardware, we can hopefully be sure that the relays will not get stuck in a position due to a driving GPIO pin being stuck.
The original post I found is : http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=45365&p=359936&hilit=ltspice#p359936
Tage, the contributor, put me on the right track, so I started to implement his solution.
I used his schematic as a starting point, while learning LTSpice myself. Unfortunately, I cannot use SMD components in my application, and the p-channel MOSFET he is using, the BSS84, or an equivalent, is not available in a through-hole package. I searched hi and low and could only find an alternative in the LP0701N3-G, and I could only locate that at Mouser.com. They are now on order, but, my interest was peaked and I did not want to wait.
Instead of using the p-channel MOSFET in what I would call a voltage level design, I changed the circuit to a current level design with a simple PNP transistor, the 2N3906.
The LTSpice results are here: (use your magnifier settings to view the picture. The limit on file sizes in posts is a real pain!!!)
Dark blue trace is output, green is base of Q2 and light-blue is the collector of Q1. (note that I used a VCC of 4.7 Volt, to test the dependence of the circuit with lower voltages)
The resulting output has dips in it, but that is only because I adjusted the values in LTSpice to the real parts I used, and this is mostly due to toleration in the HFE of the 2N3906 and other components. The parts you may have to adjust are C2 (470NF) and R3 (12K) to get the best results. Note that the base current of the 2N3906 is charging C2 through R3, not really by R2 as in the voltage (BSS84) solution from Tage does. The relays load is also a determining factor for the base current. I use a very tiny relays, the V23026A1001B201, which has a coil resistance of 370 Ohm for the 5Volt version. I could not find the inductance value so I just put in 100mH but it did not matter match for the simulation.
The scope picture is taken from the real circuit, again using the values that are in the simulation schematic. Top trace (A) is from the output, the bottom trace (B) is taken from the right side of R1.
(a high voltage on the output (A) means that the relays is powered, a low means it's off)
I happened to use the following pins on the GPIO connector to power my circuit: VCC (5V) is pin 2 on the GPIO connector, GND is pin 9 and the PWM pulses are coming from GPIO-22 on pin 15 straight to R1.
To get this output, I used the following Python code on the Pi:
Code: Select all
#!/usr/bin/env python2.7 import RPi.GPIO as GPIO from time import sleep PIN = 22 # GPIO pin 22 = pin 15 GPIO.setmode(GPIO.BCM) GPIO.setup(PIN, GPIO.OUT) HVAC = GPIO.PWM(PIN, 100) # channel 12, 100 Hz HVAC.start(50) # dutycycle 50% (0=DC) sleep (0.1) #raw_input('Press return to stop:') # use raw_input for Python 2 HVAC.stop() GPIO.cleanup()
With a frequency of 100Hz, and a sleep time of 0.1 seconds, you get 10 pulses, which is what is used in the simulation and for the real thing.
I would be very interested to hear from those that have other ideas and maybe have enhancements.