Eddie's Composting Loo fan
controller.
For this project I used an Atmel AVR series micro controller - the AT90S1200. This micro is a single chip computer - all it needs to run is a power supply. It contains an 8 bit RISC processor, 1 KiloByte of flash rom, RC clock source, timer, analog comparator, watch dog timer and general purpose I/O pins. The one I had on hand is faster than needed and cost $7 (we had to buy 14 or so - one tube full). I think the slower ones cost $3-$4. The flash rom is programmable via a serial peripheral port (SPI) port so the chip can be programmed in circuit. Since almost everything is done in the micro the circuit becomes trivial. A 7805 style regulator provides power, 6 pins interface the SPI port to a programmer, an output pin drives a MOSFET which switches power to the fan, some resistors sense battery voltage and one input pin interfaces to a Passive Infra-red (PIR) detector. The PIR detector I used is a battery powered Arlec sensor light. This cost around $22 aus and normally runs off four AA batteries - nominally 6 volts. With the bulb removed the power consumption was quite low. It also runs quite happily on 5 volts. The units has a light detector to prevent the lamp turning on during the day. I disabled this by poking some black foam into the hole the light sensor looks through. I rewired the inside of the sensor unit so that I could insert the controller into the battery compartment and interface the sensor and controller via some of the battery contacts. The sensor was powered by the controller's 5 volts supply. The wire which normally goes to the back of the lamp produces a nice signal for the micro, the signal lasts for 15 seconds from being triggered. The 5 volt supply also powers the programmer. The power supply is a low power 7805 device, this is a cheap fixed voltage 5 volt linear regulator. The nominal 12 volt supply from the battery passes through a reverse voltage protection diode and is filtered by a capacitor (say a 22 uF Tant), the regulator output has a .1 uF ceramic capacitor on it to improve stability. The micro can run on a lower voltage supply but 5 volts is needed during serial programming to generate the correct clock speeds etc. A 5 volt supply also provides the AVR output pin with plenty of voltage for the switching the MOSFET. I doubt it's worth the trouble of setting up a low voltage supply to save a few milliamps of standby current. The MOSFET gate is driven via a resistor and a zener protects against high gate voltages. The zener may not be needed but at 30 cents its a cheap precaution. The MOSFET is run way below its current rating and should not need a heatsink. The micro has one analog comparator. I used this for sensing battery charge state. The battery voltage does not give and accurate indication of the state of charge because we don't know the load on the battery, the voltage drop in the wiring or the battery temperature but setting up an under voltage and high voltage threshold should be huge improvement over no battery state feedback at all. A resistive voltage divider consisting of two 10K resistors between an output pin (set low) and 5 volts gives a reference voltage of about 2.5 volts. It's a little over 2.5 volts because the output doesn't pull down to zero volts but it's close, this goes to one comparator input. A second divider consists of a 10K resistor going to the cathode of the reverse voltage protection diode. Two different resistors go from the other side of the 10K resistor to 2 output pins. One of the two outputs is brought low to change the divider ratio. The pins are never driven high - they are either low voltage or high-impedance. The second divider goes to the second comparator pin. I was aiming to sense thresholds of around 11 and 13 volts. In the prototype this turned out to be around 11.3 and 13.3 volts which is close enough for now. Obviously I could have used trimpots to adjust the thresholds but fixed resistors are simpler, cheaper and won't be fiddled with by people who don't know what they're doing (myself included). The second comparator input also has a zener diode to clamp the voltages within safe limits in case both output port pins go high. Again this may be unnecessary because the outputs probably have internal protection diodes. Minor power savings could be made by turning the dividers off when they're not needed and also by increasing the resistor values. The software is quite simple, it has to be because this is my first program for this type of micro. The internal timer is used to generate all the delays, it is not interrupt driven and simple delay loops could have been used but the timer is easy enough to use and in some future version of the program we may want to do something else during the delay period such as generate a pulse width modulated (PWM) output for fan speed control. The timer is set to it's slowest clock rate - the cpu clock rate divided by 1024. This is very roughly a millisecond per tick. The counter is 8 bits long so the maximum timeout period is (again very roughly) a quarter of a second. Both these delays values are used in the program. The main program loop starts with a test to see if the battery is flat. If it is - it turns off the fan and rechecks till it the voltage rises about 11 volts. If the voltage is above 11 volts it looks for an intruder signal from the PIR, if it finds one it turns on the fan and starts a five minute delay, while timing, the delay is reset to five minutes whenever the PIR signal is there. Hence the fan should run for five minutes after the signal goes away. If no signal was found the program checks if the battery is over 13 volts. If so it turns on the fan for a minimum of 1 minute (aprox). During this minute it checks for a PIR signal and if it find one the program jumps to the PIR delay routine (ie the five minute delay). If the 13 volts threshold was never detected the fan is turned off and the main loop restarted. This is all hard to explain so viewing the program source is a must if you want to understand it. When the prototype was hooked up to the community house electrical system we had some bizarre problems with the electric fence apparently resetting the micro every time the fence was energized. Even when the fence energizer was given it's own battery it would reset the micro under some conditions, there appears to be some sort of inductive coupling from the fence circuit to the house wiring. It's likely the controller could be made less sensitive to interference by improving the power supply filtering by adding more caps and some series resistance or inductance. We have a minor problem with positioning the sensor. This is mainly because the toilet shares the room with a shower/bath. We will possibly have the live with the fan coming on when people are using the shower but placing the sensor on the ceiling looking down may minimize this. Apart from those hitches it works! Well sort of. Here
is the program Loofan.asm
Jumpers. LED SPI Here is the source
code for mutlispeedfan.asm Dave Keenan has placed the circuit and program for an AVR programmer online at http://users.bigpond.net.au/d.keenan/AVR |
Hits since 27/nov/98 =