     LIST P= 16F628
     INCLUDE "P16F628.INC"
     RADIX DEC


W_TEMP EQU 0X20
STATUS_TEMP EQU  0X21

AUX1_L EQU  0X22
AUX1_H EQU  0X23
AUX2_L EQU  0X24
AUX2_H EQU  0X25
AUX EQU  0X26

S0 EQU  0X27
S1 EQU  0X28
S2 EQU  0X29

QUADRANT EQU  0X2A
CASE EQU  0X2B
ANGLE EQU  0X2C
X EQU  0X2D
Y EQU  0X2E
MIDTH EQU  0X2F
PHI_H EQU  0X30
PHI_L EQU  0X31
Q_H EQU  0X32
Q_L EQU  0X33
TEMP EQU  0X34

COUNT EQU 0X35

DX EQU  0X36
DY EQU  0X37

     ORG  0X0000
     CLRF  STATUS
     GOTO PROGRAM_START

     ORG 0X0004 ;interrupt entry

     ; SAVE CONTEXT (PIC REGISTERS)
     MOVWF   W_TEMP
     SWAPF   STATUS, W
     MOVWF   STATUS_TEMP

     ; Interrupt Service Routine
     BTFSC PORTA,3	;skip if PWM is low 
     GOTO   OFF_
     ; ON
     COMF ANGLE,W	;create complement
     NOP		;synchronization
     BSF PORTA,3	;set PWM high
     GOTO   POP
OFF_
     MOVF ANGLE,W	;set to angle-value
     BCF PORTA,3	;clear PWM
     GOTO   POP		;needed to synchronize
     ;
POP
     BCF    STATUS, RP0 ;make sure we have bank0
     MOVWF  TMR0		;set the timer
     BCF    INTCON, T0IF ;clear the interrupt-flag

     ; RESTORE CONTEXT (PIC REGISTERS)
     SWAPF   STATUS_TEMP, W
     MOVWF   STATUS
     SWAPF   W_TEMP, F
     SWAPF   W_TEMP, W
     RETFIE
     ; HEADER END

   ; TO CALL Y=ATAN(X):
     ; MOVF X,W
     ; CALL ATAN
     ; MOVWF Y
     ; NOW THE ATAN TABLE
ATAN
     ADDWF PCL;*
     RETLW 0;*1
     RETLW 1;*2
     RETLW 1;*3
     RETLW 2;*4
     RETLW 2;*5
     RETLW 3;*6
     RETLW 4;*7
     RETLW 4;*8
     RETLW 5;*9
     RETLW 5;*10
     RETLW 6;*11
     RETLW 6;*12
     RETLW 7;*13
     RETLW 7;*14
     RETLW 8;*15
     RETLW 9;*16
     RETLW 9;*17
     RETLW 0XA;*18
     RETLW 0XA;*19
     RETLW 0XB;*20
     RETLW 0XB;*21
     RETLW 0XC;*22
     RETLW 0XC;*23
     RETLW 0XD;*24
     RETLW 0XE;*25
     RETLW 0XE;*26
     RETLW 0XF;*27
     RETLW 0XF;*28
     RETLW 0X10;*29
     RETLW 0X10;*30
     RETLW 0X11;*31
     RETLW 0X11;*32
     RETLW 0X12;*33
     RETLW 0X12;*34
     RETLW 0X13;*35
     RETLW 0X13;*36
     RETLW 0X14;*37
     RETLW 0X14;*38
     RETLW 0X15;*39
     RETLW 0X15;*40
     RETLW 0X16;*41
     RETLW 0X16;*42
     RETLW 0X17;*43
     RETLW 0X17;*44
     RETLW 0X18;*45
     RETLW 0X18;*46
     RETLW 0X19;*47
     RETLW 0X19;*48
     RETLW 0X1A;*49
     RETLW 0X1A;*50
     RETLW 0X1B;*51
     RETLW 0X1B;*52
     RETLW 0X1B;*53
     RETLW 0X1C;*54
     RETLW 0X1C;*55
     RETLW 0X1D;*56
     RETLW 0X1D;*57
     RETLW 0X1E;*58
     RETLW 0X1E;*59
     RETLW 0X1E;*60
     RETLW 0X1F;*61
     RETLW 0X1F;*62
     RETLW 0X20;*63
     RETLW 0X20;*64
     RETLW 0X21;*65
     RETLW 0X21;*66
     RETLW 0X21;*67
     RETLW 0X22;*68
     RETLW 0X22;*69
     RETLW 0X22;*70
     RETLW 0X23;*71
     RETLW 0X23;*72
     RETLW 0X24;*73
     RETLW 0X24;*74
     RETLW 0X24;*75
     RETLW 0X25;*76
     RETLW 0X25;*77
     RETLW 0X25;*78
     RETLW 0X26;*79
     RETLW 0X26;*80
     RETLW 0X27;*81
     RETLW 0X27;*82
     RETLW 0X27;*83
     RETLW 0X28;*84
     RETLW 0X28;*85
     RETLW 0X28;*86
     RETLW 0X29;*87
     RETLW 0X29;*88
     RETLW 0X29;*89
     RETLW 0X29;*90
     RETLW 0X2A;*91
     RETLW 0X2A;*92
     RETLW 0X2A;*93
     RETLW 0X2B;*94
     RETLW 0X2B;*95
     RETLW 0X2B;*96
     RETLW 0X2C;*97
     RETLW 0X2C;*98
     RETLW 0X2C;*99
     RETLW 0X2D;*100
     RETLW 0X2D;*MURPHY
     RETLW 0X2D;*MURPHY
     RETLW 0X2D;*MURPHY
     RETLW 0X2D;*MURPHY
     RETLW 0X2D;*MURPHY
ADD16
     MOVF    AUX2_L, W
     ADDWF   AUX1_L, F
     BTFSC   STATUS, C
     INCF    AUX2_H, F
     MOVF    AUX2_H, W
     ADDWF   AUX1_H, F
     RETLW   0
SUB16
     MOVF    AUX1_L, W
     SUBWF   AUX2_L, W
     MOVWF   AUX1_L
     BTFSC   STATUS, C
     GOTO    SUB16_H
     INCF    AUX1_H, F
SUB16_H
     MOVF    AUX1_H, W
     SUBWF   AUX2_H, W
     MOVWF   AUX1_H
     RETLW   0
GREU8
     MOVF    AUX1_L, W
     SUBWF   AUX, W
     BTFSC   STATUS, C
     GOTO    GREU8_CLEAR_W
     BTFSC   STATUS, Z
     GOTO    GREU8_CLEAR_W
     MOVLW   0X01
     MOVWF   AUX
     RETLW   0
GREU8_CLEAR_W
     CLRF    AUX
     RETLW   0
GREU16
     MOVF    AUX1_H, W
     SUBWF   AUX2_H, W
     BTFSC   STATUS, Z
     GOTO    GREU16_LOWER_BYTE
     BTFSS   STATUS, C
     GOTO    GREU16_CLEAR_W
     BTFSC   STATUS, Z
     GOTO    GREU16_CLEAR_W
     MOVLW   0X01
     MOVWF   AUX
     RETLW   0
GREU16_LOWER_BYTE
     MOVF    AUX1_L, W
     SUBWF   AUX2_L, W
     BTFSS   STATUS, C
     GOTO    GREU16_CLEAR_W
     BTFSC   STATUS, Z
     GOTO    GREU16_CLEAR_W
     MOVLW   0X01
     MOVWF   AUX
     RETLW   0
GREU16_CLEAR_W
     CLRF    AUX
     RETLW   0
EQU8
     MOVF    AUX1_L, W
     SUBWF   AUX, W
     BTFSS   STATUS, Z
     GOTO    EQU8_CLEAR_W
     MOVLW   0X01
     MOVWF   AUX
     RETLW   0
EQU8_CLEAR_W
     CLRF    AUX
     RETLW   0

;
MUL_AUX
    	CLRF	AUX1_H
	MOVF	DX,W
	MOVWF  AUX1_L
ROT
	BCF	STATUS,C
	RLF	AUX1_L,F
	RLF	AUX1_H,F
	DECFSZ	AUX
	GOTO	ROT
	MOVF	AUX1_L,W
	ADDWF   Q_L,F
	MOVF	STATUS,W
	ANDLW   B'00000001'
	ADDWF   Q_H,F
	MOVF	AUX1_H,W
	ADDWF   Q_H,F
	RETLW	0
;
;
;
DIV16_8
	CLRF	COUNT
	MOVF	DY,W
LOOP_DIV	
	SUBWF	Q_L,F
	BTFSC	STATUS,C
	GOTO	INCREMENT
NEGATIVE
	MOVF	Q_H
	BTFSC	STATUS,Z ;SKIP IF NOT ZERO
	RETURN
	DECFSZ	Q_H
	GOTO	INCREMENT
INCREMENT
	INCF 	COUNT
	GOTO	LOOP_DIV


PROGRAM_START
    
 
     BCF    STATUS, RP0
     
     ;  INITIALIZE PORT B AS OUTPUT WITH INITIAL VALUE 0X00
     ;  INITIALIZE PORT A,[0..2] AS INPUTS
     ;  CONFIGURE COMPARATORS
     ;
     MOVLW 0X03   ;Two comparators with same reference
     MOVWF CMCON
     BSF   STATUS,RP0
     MOVLW 0X07
     MOVWF TRISA
     CLRF  TRISB
     BCF   STATUS,RP0
     CLRF  PORTB
     
     ; configure timer
     BSF    STATUS, RP0	;BANK1
     MOVLW  B'11010010'	;PRESCALE 1:8
     MOVWF  OPTION_REG
     BCF    STATUS, RP0	;BANK0
     BSF    INTCON, GIE	;allow interrupts
     BSF    INTCON, T0IE ;allow timer interrupt

     MOVLW  0X32
     MOVWF  ANGLE  ;Angle=56 -->off-set value to trepass 1,3V loss at diodes in buffer
     CLRF   PHI_L
     CLRF   PHI_H
     ; MIDTH DEFINED AS 3V * 256 / 5V =153
     MOVLW  0X99
     MOVWF  MIDTH
     CLRF   X
     CLRF   Y
     ; JUMP TO MAIN PROGRAM
     GOTO   START
     ;
     ; HERE THE READINGS OF THE CHANNELS
LOOP_1
     ;  WAIT 0.01MS
     MOVLW  14;*
     MOVWF  AUX1_L
DELAYLAB11;*
     DECFSZ AUX1_L, F;*
     GOTO   DELAYLAB11;*
     NOP;*
     ;
    
     ; SKIP IF COMPARATOR 1 IS HIGH
     BTFSS CMCON,C1OUT
     GOTO   COUNT_1
     ; NOW WE HAVE THE FIRST VALUE TO BE STORED
     MOVF   PORTB, W
     MOVWF  X
     GOTO   CONTINUE_1
     ;
LOOP_2
     ;  WAIT 0.01MS
     MOVLW  14;*
     MOVWF  AUX1_L
DELAYLAB12;*
     DECFSZ AUX1_L, F;*
     GOTO   DELAYLAB12;*
     NOP;*
     ;
     
     ; SKIP IF COMPARATOR 2 IS HIGH
     BTFSS CMCON,C2OUT
     GOTO   COUNT_2
     ; NOW WE HAVE THE SECOND VALUE TO BE STORED
     MOVF   PORTB, W
     MOVWF  Y
     GOTO   CONTINUE_2
     ;
     ;
START
     BCF    STATUS, RP0
     ;
     ; CLEAR PORT B
     CLRF   PORTB
     ;
     ; CHANNEL_1
     ;
     ;
COUNT_1
     BCF    STATUS, RP0
     INCFSZ  PORTB,F
     GOTO   LOOP_1
     ;
CONTINUE_1
     BCF    STATUS, RP0
     
     ; CLEAR PORTB
     CLRF   PORTB
     ;
     ;  WAIT 0.01MS
     MOVLW  14;*
     MOVWF  AUX1_L
DELAYLAB13;*
     DECFSZ AUX1_L, F;*
     GOTO   DELAYLAB13;*
     NOP;*
     ;
     ; CHANNEL_2
     ;
     ;
COUNT_2
     BCF    STATUS, RP0
     INCFSZ PORTB,F;*
     GOTO   LOOP_2
     ;
CONTINUE_2
     BCF    STATUS, RP0
     ;
     ;



   ; QUADRANT
     MOVF   X, W
     MOVWF  S1
     MOVF   MIDTH, W
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   GREU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB1
     MOVF   X, W
     MOVWF  S1
     MOVF   MIDTH, W
     SUBWF  S1, W
     MOVWF  DX
     MOVF   Y, W
     MOVWF  S1
     MOVF   MIDTH, W
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   GREU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB2
     MOVF   Y, W
     MOVWF  S1
     MOVF   MIDTH, W
     SUBWF  S1, W
     MOVWF  DY
     MOVLW  1
     MOVWF  QUADRANT
     GOTO   ELSELAB2
ENDIFLAB2
     BCF    STATUS, RP0
     MOVF   MIDTH, W
     MOVWF  S1
     MOVF   Y, W
     SUBWF  S1, W
     MOVWF  DY
     MOVLW  2
     MOVWF  QUADRANT
ELSELAB2
     BCF    STATUS, RP0
     GOTO   ELSELAB1
ENDIFLAB1
     BCF    STATUS, RP0
     MOVF   MIDTH, W
     MOVWF  S1
     MOVF   X, W
     SUBWF  S1, W
     MOVWF  DX
     MOVF   Y, W
     MOVWF  S1
     MOVF   MIDTH, W
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   GREU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB3
     MOVF   Y, W
     MOVWF  S1
     MOVF   MIDTH, W
     SUBWF  S1, W
     MOVWF  DY
     MOVLW  4
     MOVWF  QUADRANT
     GOTO   ELSELAB3
ENDIFLAB3
     BCF    STATUS, RP0
     MOVF   MIDTH, W
     MOVWF  S1
     MOVF   Y, W
     SUBWF  S1, W
     MOVWF  DY
     MOVLW  3
     MOVWF  QUADRANT
ELSELAB3
     BCF    STATUS, RP0
ELSELAB1
     BCF    STATUS, RP0
     ;
     ;
      ; CASE
     MOVF   DX, W
     MOVWF  S1
     MOVF   DY, W
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   GREU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB4
     MOVLW  1
     MOVWF  CASE
     MOVF   DX, W
     MOVWF  TEMP
     MOVF   DY, W
     MOVWF  DX
     MOVF   TEMP, W
     MOVWF  DY
     GOTO   ELSELAB4
ENDIFLAB4
     BCF    STATUS, RP0
     MOVLW  2
     MOVWF  CASE
ELSELAB4
     BCF    STATUS, RP0

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; HERE THE ANGLE COMPUTATIONS
; Q=100*X
; COUNT=Q / Y
; PHI = ATAN(COUNT)

	CLRF	Q_L
	CLRF	Q_H
	BCF	STATUS,C
; MUL_100
	MOVLW	6
	MOVWF	AUX
	CALL	MUL_AUX
	
	MOVLW	5
	MOVWF	AUX
	CALL	MUL_AUX
	
	MOVLW	2
	MOVWF	AUX
	CALL	MUL_AUX

; DIVIDE 	
	CALL	DIV16_8
 ; ATAN
	MOVF   COUNT,W
	CALL    ATAN
     	MOVWF   PHI_L

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;+++++++++++++++++++++++++++++++++++++++++++

;HERE THE ANGLE EXTRACTING
;RESPECTING QUADRANT AND CASE


     CLRF   PHI_H
     MOVF   QUADRANT, W
     MOVWF  S1
     MOVLW  4
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB5
     MOVF   CASE, W
     MOVWF  S1
     MOVLW  1
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB6
     MOVLW  90
     MOVWF  AUX1_L
     MOVLW  0
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   SUB16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
ENDIFLAB6
     BCF    STATUS, RP0
ENDIFLAB5
     BCF    STATUS, RP0
     ;
     MOVF   QUADRANT, W
     MOVWF  S1
     MOVLW  3
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB7
     MOVF   CASE, W
     MOVWF  S1
     MOVLW  1
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB8
     MOVLW  90
     MOVWF  AUX1_L
     MOVLW  0
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   ADD16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
     GOTO   ELSELAB8
ENDIFLAB8
     BCF    STATUS, RP0
     MOVLW  180
     MOVWF  AUX1_L
     MOVLW  0
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   SUB16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
ELSELAB8
     BCF    STATUS, RP0
ENDIFLAB7
     BCF    STATUS, RP0
     ;
     MOVF   QUADRANT, W
     MOVWF  S1
     MOVLW  2
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB9
     MOVF   CASE, W
     MOVWF  S1
     MOVLW  1
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB10
     MOVLW  0X0E
     MOVWF  AUX1_L
     MOVLW  0X1
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   SUB16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
     GOTO   ELSELAB10
ENDIFLAB10
     BCF    STATUS, RP0
     MOVLW  180
     MOVWF  AUX1_L
     MOVLW  0
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   ADD16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
ELSELAB10
     BCF    STATUS, RP0
ENDIFLAB9
     BCF    STATUS, RP0
     ;
     MOVF   QUADRANT, W
     MOVWF  S1
     MOVLW  1
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB11
     MOVF   CASE, W
     MOVWF  S1
     MOVLW  1
     MOVWF  AUX
     MOVF   S1, W
     MOVWF  AUX1_L
     CALL   EQU8
     BCF    STATUS, RP0
     MOVF   AUX, W
     BTFSS  AUX, 0
     GOTO   ENDIFLAB12
     MOVLW  0X0E
     MOVWF  AUX1_L
     MOVLW  0X1
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   ADD16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
     GOTO   ELSELAB12
ENDIFLAB12
     BCF    STATUS, RP0
     MOVLW  0X68
     MOVWF  AUX1_L
     MOVLW  0X1
     MOVWF  AUX1_H
     MOVF   AUX1_L, W
     MOVWF  S1
     MOVF   AUX1_H, W
     MOVWF  S2
     MOVF   PHI_L, W
     MOVWF  AUX1_L
     MOVF   PHI_H, W
     MOVWF  AUX1_H
     MOVF   S2, W
     MOVWF  AUX2_H
     MOVF   S1, W
     MOVWF  AUX2_L
     CALL   SUB16
     BCF    STATUS, RP0
     MOVF   AUX1_L, W
     MOVWF  PHI_L
     MOVF   AUX1_H, W
     MOVWF  PHI_H
ELSELAB12
     BCF    STATUS, RP0
ENDIFLAB11
     BCF    STATUS, RP0

  ;++++++++++++++++++++++++++++++++++++++++++++++

 

;งงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงง
; HERE THE CONVERSION TO FIR INTO THE PWM-CONDITIONS:
; PHI=PHI/2+70
; SO WE GET VALUES FROM 70 TO 180+56=236
;THIS MAKES SURE THE VOLTAGE WILL BE GREATER
;THAN THE 1,3V-LOSS AT THE OUTPUT-DIODES

	BCF  STATUS,C
	RRF  PHI_H ;DIVISION BY TWO
	RRF  PHI_L
	MOVLW  0X32 ; DEC 56
	ADDWF  PHI_L,W
	MOVWF  ANGLE 
	
 
;งงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงง
    
     GOTO   START
     ;
     ;
     ;
     ;
     ;
     ;
  
     END
