piclist 2001\03\13\120916a >
Thread: math calibration algorithm ?
face BY : Nikolai Golovchenko email (remove spam text)

I think it can be done a bit easier.

1. Calculating slope. slope=(full_scale-cal_zero)/100. Here a fixed
point division would be useful that takes at least 10 bits for
dividend, 7 bits for divisor and the result as fixed point, say 3Q8
(11 bits is 0.05% accuracy at the full scale).

2. Calculating real value. real_value=(measured_value-cal_zero)/slope.
Here you need a subtraction and division again. A nice trick is
possible to use just one divide routine! The only significant
difference is that you need the result as 7Q8 (0-100 range with a few
fraction bits).

So, the common divide routine should take:
       dividend = 10 bits or more in integer format
       divisor = 15 bits in 7Q8 format
and produce:
       quotient = 15 bits in 7Q8 format

3. Displaying the results. Depending on how much digits after the
point you display, multiply the 7Q8 result by 10 (to get 1 fraction
decimal digit) or 100 (2 fraction decimal digits) and leave only the
integer bits of the result. Multiplication by a constant is easy, if
you use the online constant multiplication code generator or a
regular multiplication routine.

Then convert the integer result to decimal, using a routine at
piclist.com (there is one for 0-999 range and another for 0-65535 -
one of them should fit).

That's it!

Try this for division:

; Input:
;  a1:a0 - 10 bit dividend
;  b1:b0 - 15 bit divisor in 7Q8 format (b1 is integer, b0 is
;          fractional)
; Output:
;  c1:c0 - 15 bit quotient in 7Q8 format
; Temporary:
;  temp - current remainder extension (used for intermidiate calculations
;                only)
;  count - counter

;left align the dividend
; (shift accumulator left 1 bit to get the first result bit weight
;  equal to 128)
       rlf     a0, f
       rlf     a1, f
;initialize registers
       clrf temp                  ;clear remainder
       movlw 15                   ;15 iterations
       movwf count
       clrf c0                    ;clear result - it will be used
       clrf c1                    ;to shift zeroes to dividend
       rlf c0, f                  ;shift in next result bit
       rlf c1, f
       rlf a0, f                  ;and shift out next bit of dividend
       rlf a1, f                  ;to remainder
       rlf temp, f

       movf b0, w                 ;load w with lower divisor byte
       btfsc temp, 7              ;if remainder positive - subtract,
        goto div_add              ;if negative - add
       subwf a0, f
       movf b1, w
        incfsz b1, w
         subwf a1, f
       movlw 1
        subwf temp, f
       goto div_next
       addwf a0, f
       movf b1, w
        incfsz b1, w
         addwf a1, f
       movlw 1
        addwf temp, f
;here carry has a new result bit
       decfsz count, f
        goto div_loop
;shift in last result bit
       rlf c0, f
       rlf c1, f

Good luck!

---- Original Message ----
From: Vasile Surducan <spamvasilespam_OUTspamspamL30.ITIM-CJ.RO>
Sent: Monday, March 12, 2001 9:01:13
Subj: [PIC]: math calibration algorithm ?

{Quote hidden}

http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

<287967385.20010313181544@yahoo.com> 7bit

In reply to: <Pine.LNX.4.20.0102220924440.7537-100000@L30.itim-cj.ro>
See also: www.piclist.com/techref/microchip/math/index.htm?key=math
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) math calibration algorithm ?

month overview.

new search...