What am I missing here? If..Then


Results 1 to 4 of 4

Threaded View

  1. #1

    Default What am I missing here? If..Then

    What am I missing here? I'm trying to set a couple of software limit switches using the feedback potentiometer on a linear actuator. The extend and retract logic works fine, but the analog input variable in the IF..AND..THEN doesn't seem to do anything. The linear actuator will run full stroke, rather than stopping at about 20% and 80% of travel. I set up a LED o/p to come on at about 80% of stroke, and it works OK. I would appreciate any input.

    BrianB

    Code:
    define  OSC 4
    Define	ADC_BITS	8	' Set number of bits in result
    Define	ADC_CLOCK	3	' Set clock source (3=rc)
    Define	ADC_SAMPLEUS	50	' Set sampling time in uS
    
    ANSEL = %11110000 ' Set analog pins
    ANSELH = %00001111
    TRISA = %00001100 ' Set port A
    TRISB = %00110000 ' Set port B 
    TRISC = %11001111 ' Set port C 
    
    AN11 var byte   'Cylinder 1 Feedback Pot.
    SW1EXT var bit  'Extend Switch
    SW2RET var Bit  'Retract Switch
    J var byte
    
    'Initialize Variables and Ports
    PORTA=0
    PORTB=0
    PORTC=0
    
    MAIN:
    'Poll Switches
    If PortA.3=0 then
        pause 20
        if PORTA.3=0 then
            SW1EXT=1
        endif
    Else
        SW1EXT=0
    ENDIF
    If PortA.2=0 then
        pause 20
        if PORTA.2=0 then
            SW2RET=1
        endif
    else
        SW2RET=0
    endif
    adcin 11, AN11 'Cylinder 1 Pot
    IF AN11>200 then 'LED for Cylinder 1 Pot 80% Stroke Indicator
        PORTA.1=1
    else
        PORTA.1=0
    ENdif
    IF (SW1EXT=1) and (AN11<200) then 'Extend Cylinder 1
        PORTC.4=1
        PORTB.7=0
        PORTC.5=1
    endif
    IF (SW2RET=1) and (AN11>50) then 'Retract Cylinder 1
        PORTC.4=0
        PORTB.7=1
        PORTC.5=1
    endif
    if SW1EXT=0 and SW2RET=0 then 'Stop Cylinder 1
        PORTC.4=0
        PORTB.7=0
        PORTC.5=0
    endif
    if SW1EXT=1 and SW2RET=1 then 'Stop Cylinder 1
        PORTC.4=0
        PORTB.7=0
        PORTC.5=0
    endif
    for J=1 to 50 'Heartbeat
    pause 1
    NExt J
    toggle PORTA.0
    
    goto main
    Last edited by Darrel Taylor; - 22nd May 2007 at 00:36. Reason: Added [code][/code] tags.

Similar Threads

  1. Missing a bit
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2009, 19:54
  2. I am missing something, what is wrong with this code?
    By manta_z in forum mel PIC BASIC
    Replies: 3
    Last Post: - 27th April 2009, 00:15
  3. PIC18F4550 Error[128] Missing Arguments
    By damalu in forum mel PIC BASIC
    Replies: 9
    Last Post: - 17th November 2008, 22:47
  4. MCP23016 missing D7 on I2CRead
    By TWSK in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2007, 19:37
  5. What am I missing
    By PaulB in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th November 2004, 17:15

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