;**********************************************************************
; This file is for the target 12C509A *
; This programm is decode the rotation direction of 2 encoders *
; Pin definition: *
; GP0: direction 1 output *
; GP1: direction 2 output *
; GP2: signal B' from the sensor *
; GP3: signal A' from the sensor *
; GP4: signal B from the sensor *
; GP5: signal A from the sensor *
; *
; length of the loop max =20us *
; *
; with the internal oscillator 4Mhz *
; *
; If the internal RC oscillator is not implemented then the first
*
; instruction after the ORG 0x000 directive is not required. *
; *
; *
; Template file assembled with MPLAB V3.99.18 and MPASM V2.15.06.
*
; *
;**********************************************************************
; *
; Filename: 2encod.asm *
; Date: 28/09/2002 *
; File Version: 2.0 *
; *
; Author: LG *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=12c509a ; list directive to define processor
#include <p12c509a.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC
; MCLRE_ON tied the pin to internal VDD. Can be use as an I/O
; '__CONFIG' directive is used to embed configuration word within
.asm file.
; The lables following the directive are located in the respective
.inc file.
; See respective data sheet for additional information on configuration
word.
;***** VARIABLE DEFINITIONS
Sens1 EQU 0 ; counter pin out
Sens2 EQU 1 ; direction pin out
ChB1 EQU 4 ; Channel B entry
ChA1 EQU 5 ; Channel A entry
ChB2 EQU 2 ; Channel B'entry
ChA2 EQU 3 ; Channel A'entry
FlagA1 EQU 0x07 ; flag for the direction 1
FlagA2 EQU 0x08 ; flag for the direction 2
;**********************************************************************
ORG 0x3FF ; processor reset vector
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
movlw 0x6c
Start ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
; Configure the PIN
movlw 0x3C ; GP0 and GP1 in output only other in input
tris GPIO ; set the register
clrf FlagA1
clrf FlagA2
; detect the beginning
btfsc GPIO,ChA2 ; test if signal A2 is high
bsf FlagA2,0
btfsc GPIO,ChA1 ; test if Signal A1 is high
goto Load ; go next
goto Debut1 ; start the detection of Channel A1
Load bsf FlagA1,0 ; set the flag of A2
goto Debut2 ; start the detection of Channel A2
;***********************************************
; This loop start the detection of the channel 1
;***********************************************
Debut1 btfss GPIO,ChA1 ; test the State of A1 if =0 then jump else
prepare the jump to Channel 2
goto Debut5
btfsc FlagA1,0 ; test if A1 was = 1 before, yes jump to channel
2
goto Debut5
btfsc GPIO,ChB1 ; Detection of a new pulse, test B1
goto suite1 ; B1 forward to A1
bsf GPIO,Sens1 ; B1 backward to A1
goto suite3 ; jump to set the Flag A1
suite1 bcf GPIO,Sens1
suite3 bsf FlagA1,0
btfsc FlagA2,0 ; intermediary loop to jump to Channel 2
goto Debut4 ; A2 = 1 jump to wait falling edge
goto Debut3 ; A2= 0 jump to wait the rising edge
Debut2 btfss GPIO,ChA1 ; check the value of A1, wait the next falling
edge
bcf FlagA1,0 ; detect a falling edge, clear flagA1
Debut5 btfsc FlagA2,0 ; intermediary loop to jump to Channel 2
goto Debut4 ; A2 = 1 jump to wait falling edge
;*******************************************
; This loop start the detection of channel 2
;*******************************************
Debut3 btfss GPIO,ChA2 ; beginning of the loop wait the rising edge
goto Debut6 ; else jump to the channel 1
btfsc FlagA2,0 ; test the flag A2
goto Debut6 ; jump to the channel 1
btfsc GPIO,ChB2 ; new pulse test the position of B2
goto suite2 ; B2 forward to A2
bsf GPIO,Sens2 ; B2 backward to A2, Sens2= forward
goto suite4 ;
suite2 bcf GPIO,Sens2 ; sens2 = reverse
suite4 bsf FlagA2,0 ; set the flagA2
btfsc FlagA1,0 ; loop to prepare the jump to channel1
goto Debut2 ; jump to wait the falling edge of Channel1
goto Debut1 ; jump to wait the rising edge of Channel1
Debut4 btfss GPIO,ChA2 ; wait the falling edge on Channel A2
bcf FlagA2,0 ; clear the flagA2
Debut6 btfsc FlagA1,0 ; loop to prepare the jump to channel1
goto Debut2 ; jump to wait the falling edge of Channel1
goto Debut1 ; jump to wait the rising edge of Channel1
END ; directive 'end of program'
|