Searching \ for '16F84 Multiply 13bit by 0.0625' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/math/index.htm?key=multiply
Search entire site for: '16F84 Multiply 13bit by 0.0625'.

Truncated match.
PICList Thread
'16F84 Multiply 13bit by 0.0625'
2000\03\25@175454 by Grant Forest

flavicon
face
Goodday,
Finally got my LM76 Sign Digital i2c sensor working
but now have to multiply the 13-bit two complement word by
0.0625 (1 bit indicated 0.0625 degrees C)
Had a look in the archive but nothing applicable.
Anyone using a Lm76, and got around this multiply,
or where I can look for some fraction code.
Tks
Grant Forest

2000\03\25@191331 by Thomas C. Sefranek

face picon face
Grant Forest wrote:

> Goodday,
> Finally got my LM76 Sign Digital i2c sensor working
> but now have to multiply the 13-bit two complement word by
> 0.0625 (1 bit indicated 0.0625 degrees C)
> Had a look in the archive but nothing applicable.
> Anyone using a Lm76, and got around this multiply,
> or where I can look for some fraction code.
> Tks
> Grant Forest

Well, .0625 is 1/16
a right shift is divide by 2,
4 right shifts are a divide by 16.

--
 *
 |  __O    Thomas C. Sefranek   spam_OUTtcsTakeThisOuTspamcmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

2000\03\25@202053 by William Chops Westfield

face picon face
   > Finally got my LM76 Sign Digital i2c sensor working
   > but now have to multiply the 13-bit two complement word by
   > 0.0625 (1 bit indicated 0.0625 degrees C)

   Well, .0625 is 1/16
   a right shift is divide by 2,
   4 right shifts are a divide by 16.

Aren't you glad you spent all that time getting a nice clean analog section
of circuitry, worthy of a 13bit A-D converter, only to throw away four of
the bits?

Consider multiplying by 100 16ths, (100/16) to get the voltages as an
integer value equal to the number of hundredths of degrees.  100/16s is a
bit less than 8, so the result should still fit in 16 bits.  One of the math
wizards might suggest an algorithm (to start with, 100/16 = 25/4) that will
let you escape going to a 24 bit int.  (I wouldn't mind seeing a
simultaneous multiply/divide algorithm for handling fractions like this in
general! (ie where you're sure the final result will be less than N bytes,
but where the intermediate values can exceed N bytes.))

BillW

2000\03\25@202921 by Dan Michaels

flavicon
face
At 08:53 AM 3/26/00 +1000, you wrote:
>Goodday,
>Finally got my LM76 Sign Digital i2c sensor working
>but now have to multiply the 13-bit two complement word by
>0.0625 (1 bit indicated 0.0625 degrees C)
>Had a look in the archive but nothing applicable.
>Anyone using a Lm76, and got around this multiply,
>or where I can look for some fraction code.
>Tks
>Grant Forest
>

Looks like /16 here, but if you're interested in general in
fractional arithmetic methods, my old TI TMS320 guides describe
something called "Q-format". Extremely clever stuff.

Can probably find it somewhere on the TI site.

- Dan Michaels
Oricom Technologies
http://www.sni.net/~oricom
==========================

2000\03\25@204755 by Andrew Warren

face
flavicon
face
Grant Forest <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

> have to multiply the 13-bit two complement word by 0.062

and Thomas C. Sefranek <PICLISTspamKILLspamMITVMA.MIT.EDU> replied:

> Well, .0625 is 1/16
> a right shift is divide by 2,
> 4 right shifts are a divide by 16.

Grant:

If you just do 4 right-shifts, you'll end up with a 9-bit two's-
complement number... Which is ok, I guess, but it'd probably be
easier to work with the value if it were represented as a straight 8-
bit number in the range [0-256], with a SEPARATE sign bit.  To get
THAT, do this:

   RRF     HI
   RRF     LO
   RRF     HI
   RRF     LO
   RRF     HI
   RRF     LO
   RRF     HI
   RRF     LO,W

   BTFSC   HI,0
   SUBLW   0
   MOVWF   LO

After executing that code, LO will contain a number between 0 and 256
(representing the absolute value of the temperature, in degrees C),
and bit 0 of HI will hold the sign of the temperature (1 = negative,
0 = positive).  Bits 1-7 of HI will contain garbage; if that bothers
you, you can mask them by adding:

   MOVLW   00000001B
   ANDWF   HI

-Andy


=== Andrew Warren - .....fastfwdKILLspamspam.....ix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

2000\03\25@224623 by Nikolai Golovchenko

flavicon
face
Grant,
In general, you may want to use a code generator at
http://www.piclist.com/codegen/constdivmul
to multiply an integer variable by a floating point constant(0.0625,
6.25, or whatever). It will work also in case you have a variable with
both integer and fractional part(Q-format).

In your case, results are (0 - is the least significant byte):

; Acc = Acc * 0.062500
;
; ALGORITHM:
; Clear accumulator
; Add input / 16 to accumulator
; Move accumulator to result
;
; Error in constant approximation : 0.000000, %


; Input:  Acc0 .. Acc1  (13 bits)
; Output: Acc0 .. Acc1  (9 bits)

       cblock
       Acc0
       Acc1
       endc

       clrc
       rrf     Acc1, f
       rrf     Acc0, f
       clrc
       rrf     Acc1, f
       rrf     Acc0, f
       clrc
       rrf     Acc1, f
       rrf     Acc0, f
       clrc
       rrf     Acc1, f
       rrf     Acc0, f
;----------------------------------------

and

; Acc = Acc * 6.250000
;
; ALGORITHM:
; Clear accumulator
; Add input * 4 to accumulator
; Add input * 2 to accumulator
; Add input / 4 to accumulator
; Move accumulator to result
;
; Error in constant approximation : 0.000000, %


; Input:  Acc0 .. Acc1  (13 bits)
; Output: Acc0 .. Acc1  (16 bits)

       cblock
       Acc0
       Acc1
       Temp0
       Temp1
       endc

       movf    Acc0, w
       movwf   Temp0
       movf    Acc1, w
       movwf   Temp1
       clrc
       rrf     Acc1, f
       rrf     Acc0, f
       clrc
       rrf     Acc1, f
       rrf     Acc0, f
       clrc
       rlf     Temp0, f
       rlf     Temp1, f
       movf    Temp0, w
       addwf   Acc0, f
       movf    Temp1, w
       skpnc
       incfsz  Temp1, w
       addwf   Acc1, f
       clrc
       rlf     Temp0, f
       rlf     Temp1, f
       movf    Temp0, w
       addwf   Acc0, f
       movf    Temp1, w
       skpnc
       incfsz  Temp1, w
       addwf   Acc1, f
;----------------------------------------


Nikolai

On Sunday, March 26, 2000 Grant Forest wrote:
> Goodday,
> Finally got my LM76 Sign Digital i2c sensor working
> but now have to multiply the 13-bit two complement word by
> 0.0625 (1 bit indicated 0.0625 degrees C)
> Had a look in the archive but nothing applicable.
> Anyone using a Lm76, and got around this multiply,
> or where I can look for some fraction code.
> Tks
> Grant Forest

2000\03\26@164031 by Grant Forest
flavicon
face
Tks for the answers
A sudden loss of memory that .0625 is 4 shifts
Grant

----------
> > Well, .0625 is 1/16
> > a right shift is divide by 2,
> > 4 right shifts are a divide by 16.
>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...