Searching \ for '16F84 Multiply 13bit by 0.0625' in subject line. ()
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.
'16F84 Multiply 13bit by 0.0625'
2000\03\25@175454 by

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

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   tcscmcorp.com
(*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

http://www.harvardrepeater.org

> 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

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
Grant Forest <PICLISTMITVMA.MIT.EDU> wrote:

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

and Thomas C. Sefranek <PICLISTMITVMA.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

MOVLW   00000001B
ANDWF   HI

-Andy

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

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
movf    Temp1, w
skpnc
incfsz  Temp1, w
clrc
rlf     Temp0, f
rlf     Temp1, f
movf    Temp0, w
movf    Temp1, w
skpnc
incfsz  Temp1, w
;----------------------------------------

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

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