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
Bookmarks