;*******************************************************************************
;EQUATION USED FOR CALCULATION OF SINE TABLE ENTRIES = (SIN(ANGLE)+1)*FF/2
;Sine table has value corresponding to every 10 electrical degrees
;*******************************************************************************
TABLE
SINE_TABLE
addwf PCL,F
RETLW .2
RETLW .4
RETLW .8
RETLW .16
RETLW .24
RETLW .34
RETLW .50
RETLW .64
RETLW .80
RETLW .96
RETLW .112
RETLW .128
RETLW .144
RETLW .156
RETLW .168
RETLW .178
RETLW .184
RETLW .188
RETLW .190
;*******************************************************************************
;THIS ROUTINE INITIALIZES THE PARAMETERS REQUIRED FOR MOTOR INITIALIZATION.
;*******************************************************************************
INIT_MOTOR_PARAMETERS
#ifdef PSC_MOTOR_CONTROL
movlw 0x012 ;INITIALIZE THE TABLE OFFSET TO 3 REGISTERS
movwf TABLE_OFFSET1 ;TO FORM 0-120-240 DEGREES
movlw 0x00
movwf TABLE_OFFSET2
movlw 0x08
movwf TABLE_OFFSET3
bcf FLAGS,OFFSET1_FLAG ;OFFSET FLAGS INITIALIZATION
bsf FLAGS,OFFSET2_FLAG
btfsc FLAGS1,FWD_REV
goto INIT_MOT_REV
bsf FLAGS,OFFSET3_FLAG ;Offset3 initialized
goto INIT_MOT_FREQ
INIT_MOT_REV
bcf FLAGS,OFFSET3_FLAG
#endif
#ifdef THREE_PHASE_MOTOR_CONTROL
movlw 0x09 ;Initialize the table offset to 3 registers
movwf TABLE_OFFSET1 ;to form 0-120-240 degrees
bsf FLAGS,OFFSET1_FLAG ;Offset flags initialization
btfsc FLAGS1,FWD_REV
goto INIT_MOT_REV
movlw 0x03
movwf TABLE_OFFSET2
bcf FLAGS,OFFSET2_FLAG
movlw 0x0F
movwf TABLE_OFFSET3
bcf FLAGS,OFFSET3_FLAG
goto INIT_MOT_FREQ
INIT_MOT_REV
movlw 0x0F
movwf TABLE_OFFSET2
bcf FLAGS,OFFSET2_FLAG
movlw 0x03
movwf TABLE_OFFSET3
bcf FLAGS,OFFSET3_FLAG
#endif
INIT_MOT_FREQ
movlw 0xB1
movwf TMR0
bsf FLAGS,MOTOR_FREQ_COUNTER
RETURN