Problem with switch input on 16f818


Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Problem with switch input on 16f818

    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
    Last edited by tasmod; - 27th December 2011 at 15:34.

Similar Threads

  1. 16f818 from 16f628a
    By andybarrett1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 07:31
  2. Replies: 6
    Last Post: - 9th January 2011, 15:26
  3. Problem getting switch info into FOR..NEXT Start
    By Roddy Wayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th October 2010, 23:02
  4. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  5. Replies: 1
    Last Post: - 7th November 2007, 20:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts