Ref to recent post regarding the auto chicken door. Post (switch problems with 16f628) wrong title I know.
Sadly whilst I was away a problem occurred and the door was left closed, leaving 3 of the 4 chickens out. Needless to say Mr Fox had them.
This was not a fault of the circuit etc but a failure of the fishing line used to lift and lower the door. Somehow i think they jostled each other to get in and caused the line to snap, it wasn't a strong line as i didn't expect this. I've some much stronger braided line now.
I've revamped the system and code. The whole arrangement is on a removeable board for testing purposes.
This is where i came across a problem when i attempted to slim down the code.
There are two versions of the same code, although not exact. The hardware is the same.
Code A, chicklcd.bas uses an LCD for testing purposes and the motor 'run time' is set in code.
Code B, chickswit.bas version has the LCD stuff removed and limit switch code added.
The B code general operation is basically the same but just doesn't work without the LCD serout commands added as per code A. Why ??
Code A:-
Code B :-Code:'############################################### '# Automatic chicken coop sliding door. # '# # '# 12 Volt Battery powered. # '# Open when light, close when dark. # '# # '# Uses single microswitch as feed back. # '# # '# Pic 16f818 --- Rob Lane - Dec 2011 # '############################################### include "Modedefs.bas" OSCCON=$60 'set 4mhz internal oscillator '(Set INT_OSC in programmer fuses) ' Define ADCIN parameters Define ADC_BITS 10 'Set number of bits in result Define ADC_SAMPLEUS 50 'Set sampling time in uS Photo var word 'Create photo to store result of ldr input Counter1 var byte 'counter variable 'PIN ASSIGNMENTS LDR var porta.0 MotorUp var portb.4 MotorDown var portb.5 Switch var portb.6 LCD var portb.7 SERout PortB.7,N9600,[254,1] 'lcd CLS pause 10 ' needed after cls command Counter1=1 'Set counter for power up, ' door must be closed in daylight for startup. TRISA=000001 ' Set PORTA TRISB=000000 ' Set PORTB Main: ' serout PortB.7,N9600,[254,1] 'lcd CLS ' pause 10 ' needed after cls command adcin ldr, photo serout lcd,N9600,[254,128] 'lcd line 1 home SERout lcd,N9600,["Photo Value ",#Photo ] serout lcd,N9600,[254,192] 'lcd line 2 home serout lcd,N9600, ["Counter = ",#counter1 ] pause 100 IF Photo <10000 Then checkdown 'darkness IF Photo >30000 Then checkup 'daylight goto Main checkup: if counter1=1 then up goto main up: serout lcd,N9600,[254,192] 'lcd line 2 home SERout lcd,N9600,["Motor UP "] High MotorUp 'start motor up pause 3200 'runtime low motorup counter1=2 sleep 30 goto main checkdown: if counter1=2 then down goto main down: serout LCD,N9600,[254,192] 'lcd line 2 home SERout LCD,N9600,["Motor DOWN "] high MotorDown 'start motor down pause 4500 low motordown counter1=1 sleep 30 goto main end
Sorry, the code looked neatly formatted when I posted but forum seems to alter that.Code:'############################################### '# # '# Automatic chicken coop sliding door. # '# # '# 12 Volt Battery powered. # '# Open when light, close when dark. # '# # '# Uses single microswitch as feed back. # '# # '# Pic 16f818 --- Rob Lane - Dec 2011 # '# # '############################################### OSCCON=$60 'set 4mhz internal oscillator '(Set INT_OSC in programmer fuses) ' Define ADCIN parameters Define ADC_BITS 10 'Set number of bits in result Define ADC_SAMPLEUS 50 'Set sampling time in uS Photo var word 'Create 'photo' to store result of ldr input Counter1 var byte 'flip flop counter variable 'PIN ASSIGNMENTS LDR var porta.0 MotorUp var portb.4 MotorDown var portb.5 Switch var portb.6 pause 1000 Counter1=1 'Set counter for power up, door must 'be closed in daylight for startup. TRISA=000001 ' Set PORTA TRISB=000000 ' Set PORTB '######################################################### Main: ADCIN ldr, photo 'read ldr adc value IF Photo <10000 Then checkdown 'darkness IF Photo >30000 Then checkup 'daylight goto Main '########################################################## checkup: if counter1=1 then up goto main up: High MotorUp 'start motor up pause 1000 'wait 1 sec so micro switch opens stopup: if switch = 1 then pressedup 'check microswitch state goto stopup 'check again till true pressedup: low motorup 'stop motor Counter1=2 'flip flop counter for up/down of door sleep 30 'test mode - sleep 30 secs goto main '########################################################## checkdown: if counter1=2 then down goto main down: high MotorDown 'start motor down pause 1000 stopdown: if switch = 1 then presseddown 'check again goto stopdown presseddown: low MotorDown Counter1=1 sleep 30 goto main end






Bookmarks