Searching \ for '[PIC]: floating point headaches' 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/devices.htm?key=pic
Search entire site for: 'floating point headaches'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: floating point headaches'
2001\06\26@175519 by Jonathan Newport

picon face
Hello all:

   I haven't been messing around with pics for a while....but just
picked it back up again a couple of weeks ago and forgot how much fun it
was.
Now, onto the plea for help....

   I admit...I've ALWAYS been scared of floating point routines, but
the time has come where I MUST use them....the Microchip routines scare
me worse than any of them....but maybe I'm just being stupid and
ignorant of binary math...in any case...I've found these routines which
look good to me and I think I can use.  What I'm trying to do is
multiply the 10-bit A/D value that I obtained from my F876 by
0.0048828125 to get the resultant voltage...the only thing I don't know
how to do is get the A/D value (an integer) into floating point
notation, actually, I guess I don't know how to get the 0.0048828 value
into floating point notation either, but that's just a constant...how
would I convert an integer to a float?  the float routines that I'm
using use two 16-bit arguments with an 8-bit mantissa and an extra sign
byte (which I don't know what does yet) here's one of the routines (some
call statements may be missing...I just gave a snippit):


;*******************************************************************
;   Binary Floating Point Multiplication :
;   ACCb(16 bits)EXP(b) * ACCa(16 bits)EXPa -> ACCb(16 bits)EXPb

F_mpy:  call  S_SIGN
 call  setup
mloop:    bcf  STATUS,C      ; clear carry bit       ??????????
 rrf  ACCdHI,F         ;rotate d right
 rrf  ACCdLO,F
 btfsc  STATUS,C      ;need to add?
 call  D_add
 rrf  ACCbHI,F
 rrf  ACCbLO,F
 rrf  ACCcHI,F
 rrf  ACCcLO,F
 decfsz  temp, F          ;loop until all bits checked
 goto  mloop

 movf  EXPa,W
 addwf  EXPb, F

 IF  Mode16
 movf  ACCbHI, F
 btfss  STATUS,Z
 goto  finup            ; if ACCbHI != 0
 movf     ACCbLO, F
 btfss    STATUS,Z
 goto     Shft08           ; if ACCbLO != 0 && ACCbHI == 0

 movf  ACCcHI,W
 movwf    ACCbHI           ; if ACCb == 0, then move ACCc to ACCb
 movf     ACCcLO,W
 movwf    ACCbLO
 movlw  .16
 addwf    EXPb, F
 goto      finup

Shft08:   movf     ACCbLO,W
 movwf    ACCbHI
 movf     ACCcHI,W
 movwf    ACCbLO
 movlw    .8
 addwf    EXPb,F

 ENDIF                     ; matching endif for IF Mode16

finup:    btfss    sign,MSB
 goto     F_norm

 decf     ACCcLO,F         ; negate ACCc
 comf     ACCcLO,F
 btfsc    STATUS,Z
 decf     ACCcHI,F
 comf     ACCcHI,F
 btfsc    STATUS,Z

neg_B:    decf     ACCbLO,F         ; negate ACCb
 comf     ACCbLO,F
 btfsc    STATUS,Z
 decf     ACCbHI,F
 comf     ACCbHI,F

 goto     F_norm



thanks for your time!

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


2001\06\26@190541 by Brent Brown

picon face
{Quote hidden}

You don't necessarily have to go to floating point. There may be a
couple of alternatives using 16 bit integer maths:-

1) 10 bit A/D result is a count of 1023. Scale your analog input by
resistor divider slightly to give a max count of 1000. Multiply by
integer 5, you get a 16 bit result 0-50000 that represents an input of
0-5V. Put in the decimal point where it needs to be when printing out
or displaying. Even if you don't scale and just ignore any ADC count
over 1000 the error is only about 2%.

2) Multiply by a fraction (multiply then divide). Eg: x18/37 gives a
max of 497 which could read 4.97 volts. Or x40/82 = 499, or even
better x45/92 = 500. All this fits in 16 bits OK.

Brent Brown
Electronic Design Solutions
16 English Street
Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/text: 025 334 069
eMail:  spam_OUTbrent.brownTakeThisOuTspamclear.net.nz

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


2001\06\26@192222 by Spehro Pefhany

picon face
At 04:48 PM 6/26/01 -0700, you wrote:

>    I admit...I've ALWAYS been scared of floating point routines, but
>the time has come where I MUST use them....

And why would that be? It's very seldom actually necessary, you know.
Just scale and use 16, 24 or even 32 bit fixed point math (possibly
adjusting the scaling with shifts between operations).

> the Microchip routines scare
>me worse than any of them....but maybe I'm just being stupid and
>ignorant of binary math...in any case...I've found these routines which
>look good to me and I think I can use.  What I'm trying to do is
>multiply the 10-bit A/D value that I obtained from my F876 by
>0.0048828125 to get the resultant voltage...the only thing I don't know
>how to do is get the A/D value (an integer) into floating point
>notation, actually, I guess I don't know how to get the 0.0048828 value
>into floating point notation either, but that's just a constant...how

Is there not a routine for doing the conversion in the package?
The only complex thing is that you should normalize the number, which
means that it effectively is left shifted and the exponent decremented
until the leftmost bit is a one (often an implied "one", depending on
the format), except for the special case of a zero. In the case of
Microchip's format, the implied "1" is replaced by the sign bit.

The exponent is like the base 10 exponent you are used to, except
it is base 2, and except it is "biased" by -127 so the routines
don't have to do signed math.

Neither is anything to be scared of. BTW, one of the piclist members
has written a conversion applet, called floatconv.exe

Best regards,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

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


2001\06\26@210715 by Olin Lathrop

face picon face
> the float routines that I'm
> using use two 16-bit arguments with an 8-bit mantissa and an extra sign
> byte

8 bit mantissa isn't enough if you want to make full use of the 10 bit A/D
results.  I use a 24 bit format for this kind of stuff.  It includes 1 sign
bit, 7 exponent bits, and 16 mantissa bits with an implied vestigual 1 bit.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinspamKILLspamembedinc.com, http://www.embedinc.com

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


2001\06\26@231449 by James Newton. Admin 3

face picon face
As always, the answer is on piclist.com.... <GRIN>

http://www.piclist.com/techref/piclist/codegen/constdivmul.htm

James Newton, PICList Admin #3
.....jamesnewtonKILLspamspam.....piclist.com
1-619-652-0593 phone
http://www.piclist.com

{Original Message removed}

2001\06\27@034411 by Alan B. Pearce

face picon face
>multiply the 10-bit A/D value that I obtained from my F876 by
>0.0048828125 to get the resultant voltage...the only thing I don't know

Are you not able to tweak the reference to simplify the math? It may be that
by setting the reference appropriately you can do away with the math
altogether by just shifting the decimal point in the value read.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\27@043714 by James Hillman

flavicon
face
Spehro Pefhany wrote :

> Neither is anything to be scared of. BTW, one of the piclist members
> has written a conversion applet, called floatconv.exe

With floatconv.exe :
In Microchip 24bit mode some conversions are slightly incorrect
eg:

22702080 into the Float textbox and Convert to Byte
Microchip 32 bit:  972D3400    (ok)
Microchip 24 bit : 972D34        (ok)

22702079 into the Float textbox and Convert to Byte
Microchip 32 bit:  972D33FE  (ok)
Microchip 24 bit : 972D32       (not ok - it is too low)

However its very useful and I use it often, but only in 32 bit mode.

James

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\27@123006 by Jonathan Newport

picon face
Sorry, I MEANT to say 16 bit mantissa with an 8-bit exponent....

Jonathan

Olin Lathrop wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\06\27@151614 by Jonathan Newport

picon face
Alright, I worked on it a few hours and got it...without floating
point......as it turns out I didn't need to use voltage at all....I'm trying
to use an AD22100 temperature chip.  It has a 0 degree level of 1.375V so I
simply (1) took that 10 bit number in A/D steps (~282) subtracted it from
the A/D value present on an0 then divided by the chip's temp coefficient
0.0225, but what I actually did was multiply step (1) by:

      1                     5V
-----------     x------------ =  217  (without decimal place) and then just
placed the decimal point where it was appropriate
0.0225 V/C      1024

thanks for your all your help!

Jonathan


Jonathan Newport wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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