Hi everyone,
Newby to posting forum, but been a lurker for quite some time.
I have a problem using a 16f628A and a switch input. This is for a chicken coop motorised sliding door with a LDR as input.
I have a microswitch fed +5v via a 10k resistor to ground, the mid junction of which is connected to PortB.6. Typical manual type stuff.
There is only one microswitch which is fixed position, the door has two switch stops fitted so the switch is monitored in seperate up/down routines.
This switch state is monitored in a loop as it is a limit switch for the motor. However it's action is very slow in operation, taking a few iterations of the loop to act, causing the motor to overrun.
My question is should the INTCON be set as 000000 to prevent the interupt feature on this pin and make the pin a digital input, or am I missing something?
At the moment the project is built and installed but now running the motor on a time setting rather than a limit switch.
Code:
'# Automatic chicken coop sliding door. #
'# #
'# 12 Volt Battery powered. #
'# Open when light, close when dark. #
'# Sleep approx. 4 hours between to conserve #
'# power and to prevent retriggering. #
'# #
'# 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
Counter1=1 'Set counter for power up, door must
'be closed in daylight for first powerup.
TRISA=%00000001 ' Set PORTA
TRISB=%01000000 ' Set PORTB
input switch
'INTCON=%00000000
Main:
ADCIN ldr, photo 'read ldr adc value
IF Photo <20000 Then checkup 'daylight
IF Photo >30000 Then checkdown 'darkness
'sleep 300 'about 5 minutes low power
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
if switch = 1 then pressedup 'check switch state
goto up 'check again
pressedup:
low motorup 'stop motor
Counter1=2 'flip flop counter for up/down of door
'sleep 14400 'sleep 4 hours
goto main
checkdown:
if counter1=2 then down
goto main
down:
high MotorDown 'start motor down
pause 1000
if switch = 1 then presseddown 'check again
goto down
presseddown:
low MotorDown
Counter1=1
'sleep 14400
goto main
end
Bookmarks