Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Am I going potty or are Microchips AN617 routines faulty?

Status
Not open for further replies.

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).

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
 
Screenshot of the sim result with the registers in the watch window lower right.
AN617_1.jpg
 
I never had much success with the microchip routines so I dug out an old one I used many years ago,
This is the result in MPLAB v8.92 - the old one.
multi.png

As you can see it gets 25,256 as the result.
Complete code,
Code:
        radix       dec
        errorlevel     -207    ;Skip found label after column 1
        errorlevel     -302    ;Skip out of bank nuisance messages
        errorlevel     -303    ;Skip program word too large. Truncated to core size
;
; *******************************************************************************
; * Configuration fuse information for 16F1827:                    *
; *******************************************************************************
;
        include   <P16LF1827.INC>

 __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
 __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF

      CBLOCK    0x20
bL
bH
r1
r2
r3
t
      ENDC        

      CBLOCK    0x70
      ENDC

      ORG     0x0000              

start
      banksel OSCCON
      movlw     b'01101000'
      movwf   OSCCON
      banksel    0
      movlw    low(.451)
      movwf    bL
      movlw    high(.451)
      movwf    bH
      movlw    .56
      movwf    t
      call    multiply
      goto    $

multiply
      clrf    r3
      clrf    r2
      clrf    r1
      bsf        r1,7    ;used to count to 8
loop  rrf        t,f
      btfss    STATUS,C
      goto    noAdd
      movfw    bL
      addwf    r2,f
      movfw    bH
      btfsc    STATUS,C
      incfsz    bH,w    ;w = w+1
      addwf    r3,f
noAdd
      rrf        r3,f
      rrf        r2,f
      rrf        r1,f
      btfss    STATUS,C
      goto    loop
      return

      end

Mike.
 
Last edited:
As you can see it gets 25,256 as the result.
I've seen that somewhere as well.

I'll give that one a run.

Your first port of call should always be the PICLIST
Completely forgot about that site :facepalm:

Did a little bit of "research" and appears a few people have had problems with the AN617 routines. Looks like their app notes are vetted to the same level as their datasheets - poorly.
 
I've seen that somewhere as well.

I'll give that one a run.


Completely forgot about that site :facepalm:

Did a little bit of "research" and appears a few people have had problems with the AN617 routines. Looks like their app notes are vetted to the same level as their datasheets - poorly.
A number of the app notes are pretty useless.
 
I was doing the ADC TAD calcs a few days ago using I think the 16F1827 datasheet (might have been a different one) and in one part of the text they are using µS in the calc and then a bit further down they use mS.

Looking at the value of the storage cap in the PIC (10pF), µS would appear to be the correct one to use.
 
One thing to be aware of is that many of Microchip's math routines were originally written for their very early processors which behave slightly differently than the later ones. In particular, the operation of the carry bit has changed from the early to later processors, and that can result in incorrect calculation results when used with the wrong processor. It's possible that they've re-released some old routines without properly vetting it for proper operation on current processors.
 
I think their vetting process is almost non-existent these days, some of the newer datasheets are atrocious, you can follow the cut and paste sections all through them to the extent a lot of stuff doesn't even apply to the device that is the subject of the datasheet.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top