Hi all,

I have been working on this for too long and I'm starting to chase my tail.

I'm to the point that I can remember the post numbers, but I'm still overlooking something.

The purpose is this:
1) Read Encoder #1 to measure direction and distance of a linear movement.
2) If travel is +, do nothing
3) if travel is -, feed pulses to a servo driver to move a motor (feed material at same rate as linear retract).
4) there a couple of lines I left in for adding manual over-ride.
5) testing on a 877 with a X-1 board but the target can be anything.

Thanks for taking a look.
Bo

' 1)Quadrature encoder reading direction and speed of mechanical slide.
' 2) Motor (servo) driven in ONE direction of slide movement,
' not driven for other direction. Pulse & Direction drive.
' 3) Overide switches to drive servo either direction manually.
'
A_INPUT VAR PORTB.4 'encoder A input
B_INPUT VAR PORTB.5 'encoder B input
F_Sw var PORTB.6 'Foward switch input
R_sw var PORTB.7 'Reverse Sw input
P_out var PORTA.0 'Pulse out to motor
D_out var PORTA.1 'level out for direction
'only for manual Sw
' drive. Implement Ltr.
LED1 var PORTA.5 'heartbeat for INT
RdEnc1 VAR BIT
RdEnc2 VAR BIT
COUNTER VAR WORD

TRISA = %00000000
TRISB = %11111111
TRISD = %00000000
OPTION_REG.7 = 0 'enable POTRB pull-ups

INCLUDE "DT_INTS-14.bas" 'Base Inturrupt program
include "ReEnterPBP.pbp" 'allow PBP int

ASM
INT_LIST macro ;IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _MotorDrive, PBP, yes
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm

INT_ENABLE RBC_INT ;enable RB change int
INT_ENABLE INT_INT ; enable external (INT) interrupts
ENDASM

Start
RdEnc2 = A_INPUT & ~ RdEnc1 'EVERY POSITIVE GOWING EDGE OF A_INPUT
RdEnc1 = A_INPUT 'GIVES A PULSE OF ONE PROGRAM CYCLE

IF RdEnc2 = 1 AND B_INPUT = 1 Then 'Encoder TURNS CW: UP
COUNTER = 1
EndIF

IF RdEnc2 = 1 AND B_INPUT = 0 Then 'Encoder TURNS CCW: DN
COUNTER = 0
EndIF

counter = portb & %00000011 'for troubleshooting: strip i/p.
PORTD = counter 'for troubleshooting: to see i/p.

goto start

'+++++++++++++++++
'Motor Drive Pulse Out inturrupt handler
'++++++++++++++++++
MotorDrive:
if counter = 1 then
pulsout P_out,100
endif
@ INT_RETURN
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN
end