; Controller for composting loo fan. ; This program and the circuit it controls are the copyright of Eddie Matejowsky - 1998 ; It is freeware, you may copy it, build it and use it, I'll even let you make money by ; selling it. In exchange you must acknowledge it as being my design and include this notice ; with any copies you make and include a hardcopy of this notice with any units made for others. ; The main reason for this requirement is to give all users the opportunity to visit my web-site ; for up to date information on this project and related alternate technology projects. ; My website is currently at http://www.ozemail.com.au/~eddiema/ , if this changes ; a web search using my name and a keyword such as "loofan" should locate me. ; My current email address is eddiema@ozemail.com.au ; ; The Controller :- ; Prevents the fan from running when battery is too flat. ; Senses when a person is in the room by using a PIR dectector and turns the fan on for about 5 minutes. ; If battery is over 13 volts turn fan on regardless of the PIR state. ; Fan is controlled via a power MOSFET on B3 ; lower resister in reference divider is attached to port B bit 2 ; lower resister in 11 volt sensing divider is attached to port D bit 6 ; lower resister in 13 volt sensing divider is attached to port B bit 4 ; PIR detector is read by port D bit 5 ;----------------------------------------------------------------- .device AT90S1200 ;Prohibits use of non-implemented instructions .nolist .include "1200def.inc" ;I/O port and bit definitions .list .CSEG .def temp =r16 ; working registers for the program. .def counter1 =r17 .def counter2 =r18 .def counter3 =r19 ;Reset vector (must be the first code generated) rjmp RESET ;To Reset handler ;----------------------------------------------------------------- ; delay routines, note all rountines use one level of stack (we can have 3 levels) DELAY: ldi temp,0 ;Entry point for Max timer delay out TCNT0,temp ;Set the timer value. DENTR: ldi temp,1<11 volts cbi PORTB,PB3 ; Under voltage - Turn fan off rjmp LOOP2 ; the battery is flat retest till it improves. OVER11: cbi DDRD,PB6 ; disable 11 volt divider sbis PIND,PB5 ; Test for PIR output rjmp TEST13 ; No PIR so test if bat >13 volts sbi PORTB,PB3 ; PIR on - turn fan on PIRON: ldi COUNTER2,0 ; set counters for delay - aprox 5 minutes ldi COUNTER3,5 ; we do NOT check for undervoltage once the fan is on ; sbi PORTB,PB3 ; Fan on PIRDEL: rcall DELAY1 ; retriggerable delay, no way out except waiting! sbic PIND,PB5 ; Test for PIR output again rjmp PIRON ; PIR on - restart timing loop dec COUNTER2 ; decrement counter brne PIRDEL ; and loop more if not zero dec COUNTER3 ; decrement counter brne PIRDEL ; and loop more if not zero rjmp LOOP ; Time elasped back to start TEST13: sbi DDRB,PB4 ; enable 13 volt divider rcall DELAY0 ; 1 ms delay to stabilize voltages sbis ACSR,ACO ; Skip if compare set rjmp OVER13 ; we have >13 volts cbi PORTB,PB3 ; Fan off rjmp LOOP OVER13: ldi COUNTER2,0 sbi PORTB,PB3 ; Fan on V13DEL: rcall DELAY1 ; Non retriggerable delay, but can jump to PIR loop sbic PIND,PB5 ; Test for PIR output rjmp PIRON ; PIR on, exit 13volt loop and enter PIR loop dec COUNTER2 ; decrement counter brne V13DEL ; and loop more if not zero rjmp LOOP