Hi there fellow members.Below is the first attempt to write a code alone and it did work but as usual it has bugs.
One indicates direction of rotation. (a lit LED for CW and an off LED for CCW rotation).
The other one pulses as the shaft is rotated in either direction.
When hard wired these are the results.
At first I tested with CW rotation, first wrote up that part of code and tested and it works perfectly. the CCW rotation is not tested during this time.
The CW is lit continuously and the other one pulses as the shaft is rotated.
Now after writing the CCW part. the code works but now the CW also creates a bit of problem, the CW LED turns off sometimes and same thing happens during CCW and the pulse LED sometimes hardly pulses.
Now my observation is contact bounce so I am trying to put some delays in between the direction instructions. But am not sure of how much a delay that I should give.
Any comments are most welcome and of course if any of you can think of a better way will be most appreciated.
Rifaa
This circuit used a 12F629, a standard rotary encoder is connected to two inputs that are held low by pull downs. Two output drives two LED.#define Bank0 BCF STATUS,RP0
#define Bank1 BSF STATUS,RP0
#define X GPIO,5 ; Encoder X,Y impute on GPIO.GP<5:4>
#define Y GPIO,4
#define DR GPIO,0 ; Direction indiacator, a HIGH for CW and a LOW for CCW
#define Pout GPIO,1 ; Output Pulse as the Encoder is rotated either direction
;------------------------------------------------------------------------------
;RESET VECTOR
ORG 0x0000 ; processor reset vector
GOTO MAIN ; go to beginning of program
;------------------------------------------------------------------------------
;Interrupt Service
ORG 0x0004 ; interrupt vector location
;Oscillator Caliberation
errorlevel -302
Bank1 ; set file register bank to 1
call 0x3FF ; retrieve factory calibration value
movwf OSCCAL ; update register with factory cal value
Bank0 ; set file register bank to 0
errorlevel +302
;-------------------------------------------------------------------------------
; MAIN ROUTINE
MAIN
clrf GPIO ; Clear Outputs
movlw 07h ; Disable-
movwf CMCON ; comparator
Bank1
movlw b'111000'
movwf TRISIO
Bank0
bcf DR
bcf Pout
CheckEncoder
btfsc X
goto CWR
btfsc Y
goto CCWR
goto CheckEncoder
CWR
btfss X
goto CheckEncoder
bsf DR
btfss Y
goto CWR
bsf Pout
CW1 btfsc X
goto CW1
bcf Pout
CW2
btfsc Y
goto CW2
goto CheckEncoder
CCWR
bcf DR
bcf Pout
btfss Y
goto CheckEncoder
bcf DR
CCW1
btfss X
goto CCW1
bsf Pout
CCW2
btfsc Y
goto CCW2
bcf Pout
CCW3
btfsc X
goto CCW3
goto CheckEncoder
end
One indicates direction of rotation. (a lit LED for CW and an off LED for CCW rotation).
The other one pulses as the shaft is rotated in either direction.
When hard wired these are the results.
At first I tested with CW rotation, first wrote up that part of code and tested and it works perfectly. the CCW rotation is not tested during this time.
The CW is lit continuously and the other one pulses as the shaft is rotated.
Now after writing the CCW part. the code works but now the CW also creates a bit of problem, the CW LED turns off sometimes and same thing happens during CCW and the pulse LED sometimes hardly pulses.
Now my observation is contact bounce so I am trying to put some delays in between the direction instructions. But am not sure of how much a delay that I should give.
Any comments are most welcome and of course if any of you can think of a better way will be most appreciated.
Rifaa