Hi All,
Been banging my head for a while now and I am getting closer. Thank you for the time you have taken to add life to this forum.
The Travel encoder section works pretty well, but the Manual encoder is erratic and sometimes take over the travel section and not let it work. A bump on Manual, and the Travel works again.
As a reminder. The Travel generates Pulse and Direction in one direction only. The Manual is for bi-directional fine adjustment after the Travel section's movement is complete (automatic). Target: 12F675 @ 4mHz INT_OSC
Anybody see what I'm missing?
Thanks
Bo
Code:A_trav VAR GPIO.0 'Travel encoder A input B_trav VAR GPIO.1 'Travel encoder B input A_man var GPIO.2 'Manual Encoder A input B_man var GPIO.3 'Manual Encoder B input P_out var GPIO.4 'Pulse output to motor D_out var GPIO.5 'level output for direction Dir VAR bit 'Direction Scratch var byte 'dummy byte Old_Bits VAR BYTE New_Bits VAR BYTE TravEncOld var byte 'TRAVel Measurement ENCoder TravEncNew Var byte ' ManEncOld var byte 'MANual input ENCoder ManEncNew var byte ' P_out = 1 'servo I/P = LO pulse, start HI INTCON = %10001000 'GLOBAL ON, GPIO Int ON CMCON = 7 'Comparator off, Digital I/O OPTION_REG = %00000000 'GPIO Pull-up Enabled TRISIO = %001111 WPU = %000111 'pull-ups 0-2 (3 added on board) IOC = %001111 'Int On Change GPIO 1-3 ANSEL = 0 INCLUDE "DT_INTS-14-0.bas" '..-14-0 = ALL Banks REM'd ASM INT_LIST macro ; IntSource, label, Type, ResetFlag? INT_Handler RBC_INT, _EncChg, ASM, yes endm INT_CREATE ; Creates the interrupt processor INT_ENABLE RBC_INT ;RB Port Change Interrupt ENDASM Old_Bits = GPIO & (%001111) 'Get initial inputs Main: GOTO Main '---[RBC - interrupt handler]--------------------------------------------------- EncChg: New_Bits = GPIO & (%001111) 'Get inputs TravEncNew = New_Bits & (%000011) 'strip New Travel encoder TravEncOld = Old_Bits & (%000011) 'Strip Old Travel Encoder if TravEncNew = TravEncOld then ManEnc ' If no chg -> Manual Encoder Dir = TravEncNew.1 ^ TravEncOld.0 'Check direction D_out = Dir 'Direction LEVEL out if Dir = 1 then 'Only travel 1 direction pulsout P_out,20 'drive servo controller Endif 'Controller is STEP/DIRECTION I/P goto DoneRotEnc 'skip Manual Encoder ManEnc: ManEncNew = New_Bits & (%001100) 'strip Manual Encoder ManEncOld = Old_Bits & (%001100) Dir = ManEncNew.3 ^ ManEncOld.2 'Direction of Manual input D_out = Dir pulsout P_out,20 'Pulse for either direction DoneRotEnc: Old_Bits = New_Bits 'reset reference Scratch = GPIO 'read GPIO to clear mis-match @ INT_RETURN




Bookmarks