augustinetez
Active Member
I can't get to the workbench at the moment, so fiddling around with the Oshon Sim and code re my ADC scaling thread.
I have been fiddling with the multiply word (NumH,NumL) by 56 and divde by 10 thing as the sim doesn't like Mikes table code.
So if my maths is correct 451 x 56 (dec) = 25,256 (dec)
Using Microchips AN617 16x8 Bit Unsigned Fixed Point Multiply routine, I am getting 451 x 56 = 36,900 (code below).
BARGB0 is loaded with 56 (dec), TEMPB0 is loaded with NumL & TEMPB1 is loaded with NumH which for the purposes of this calc = 451 dec (using any other numbers in NumH:NumL gives corresponding errors).
I have been fiddling with the multiply word (NumH,NumL) by 56 and divde by 10 thing as the sim doesn't like Mikes table code.
So if my maths is correct 451 x 56 (dec) = 25,256 (dec)
Using Microchips AN617 16x8 Bit Unsigned Fixed Point Multiply routine, I am getting 451 x 56 = 36,900 (code below).
BARGB0 is loaded with 56 (dec), TEMPB0 is loaded with NumL & TEMPB1 is loaded with NumH which for the purposes of this calc = 451 dec (using any other numbers in NumH:NumL gives corresponding errors).
Code:
;**********************************************************************************************
; 16x8 Bit Unsigned Fixed Point Multiply 16x8 -> 24
; Input: 16 bit unsigned fixed point multiplicand in AARGB0
; 8 bit unsigned fixed point multiplier in BARGB0
; Use: CALL FXM1608U
; Output: 24 bit unsigned fixed point product in AARGB0
; Result: AARG <-- AARG x BARG
; Max Timing: 5+119+2 = 126 clks
; Min Timing: 5+54 = 59 clks
; PM: 5+26+1 = 31 DM: 7
FXM1608U CLRF AARGB2 ; clear partial product
MOVF AARGB0,W
MOVWF TEMPB0
MOVF AARGB1,W
MOVWF TEMPB1
UMUL1608L
RETLW 0x00
;**********************************************************************************************
UMUL1608L macro
; Max Timing: 2+13+6*15+14 = 119 clks
; Min Timing: 2+7*6+5+4 = 54 clks
; PM: 26 DM: 7
MOVLW 0x08
MOVWF LOOPCOUNT
LOOPUM1608A
RRF BARGB0, F
BTFSC _C ;--> _C = STATUS,C
GOTO LUM1608NAP
DECFSZ LOOPCOUNT, F
GOTO LOOPUM1608A
CLRF AARGB0
CLRF AARGB1
RETLW 0x00
LUM1608NAP
BCF _C
GOTO LUM1608NA
LOOPUM1608
RRF BARGB0, F
BTFSS _C
GOTO LUM1608NA
MOVF TEMPB1,W
ADDWF AARGB1, F
MOVF TEMPB0,W
BTFSC _C
INCFSZ TEMPB0,W
ADDWF AARGB0, F
LUM1608NA RRF AARGB0, F
RRF AARGB1, F
RRF AARGB2, F
DECFSZ LOOPCOUNT, F
GOTO LOOPUM1608
endm