Searching \ for '[PIC] AN575: 0.0+1.0=-1.0 ?' 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: 'AN575: 0.0+1.0=-1.0 ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] AN575: 0.0+1.0=-1.0 ?'
2005\04\29@181532 by Mark Rages

face picon face
Well this is annoying.

I'm using the "FP24.A16" floating point library from AN575.

If I try to add 1.0 to 0, I get -1.0.

I'm using the same routine for conversion to float on the "1.0" and the "-1.0".

It doesn't matter if I put the 1 in AARG and the 0 in BARG or vice-versa.

No wonder my PID controller wasn't working right.

Has anone else encountered this?

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\04\29@182301 by Mark Rages

face picon face
On 4/29/05, Mark Rages <spam_OUTmarkragesTakeThisOuTspamgmail.com> wrote:
> Well this is annoying.
>
> I'm using the "FP24.A16" floating point library from AN575.
>
> If I try to add 1.0 to 0, I get -1.0.
>

Two more data points.

1.0+1.0=-2.0
-1.0-1.0=-2.0

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\04\29@183204 by olin_piclist

face picon face
Mark Rages wrote:
> If I try to add 1.0 to 0, I get -1.0.
>
> ...
>
> No wonder my PID controller wasn't working right.
> Has anone else encountered this?

Not me.  I use my own 24 bit floating point routines for PID controllers and
the like.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\04\29@184407 by olin_piclist

face picon face
Mark Rages wrote:
> Two more data points.
>
> 1.0+1.0=-2.0
> -1.0-1.0=-2.0

For $299 you can have my battle-tested 24 bit floating point routines in
source code form.  You can send out all the derived binaries you want
royalty free, but the sources have to stay within your organization.  The
routines are:

 FP24FLT  -  Convert 32 bit fixed point to floating.

 FP24ADD  -  Add.

 FP24SUB  -  Subtract.

 FP24MUL  -  Multiply.

 FP24DIV  -  Divide.

 FP24MIN  -  Find minimum of two values.

 FP24MAX  -  Find maximum of two values.

 FP24FIX  -  Convert floating point to 32 bit fixed point.

The interface and operation of all routines are well documented in the
source code comments.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\04\29@184425 by Mark Rages

face picon face
On 4/29/05, Olin Lathrop <.....olin_piclistKILLspamspam@spam@embedinc.com> wrote:
> Mark Rages wrote:
> > If I try to add 1.0 to 0, I get -1.0.
> >
> > ...
> >
> > No wonder my PID controller wasn't working right.
> > Has anone else encountered this?
>
> Not me.  I use my own 24 bit floating point routines for PID controllers and
> the like.

Yes, and I applaud you for it.

Anyone *else* used AN575 arithmetic?

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\04\30@125551 by Dennis Crawley

flavicon
face
Mark Rages <markragesspamKILLspamgmail.com> wrote:
> Yes, and I applaud you for it.
>
> Anyone *else* used AN575 arithmetic?

> Regards,
> Mark
> markrages@gmail
> --

Your results are OK!.
The problem is the Microchip format.
To convert to IEEE format simple do this:

IEEE_to_PIC16/17  PIC16/17_to_IEEE
RLCF AARGB0,F     RLCF AARGB0,F
RLCF AEXP,F       RRCF AEXP,F
RRCF AARGB0,F     RRCF AARGB0,F

delete de C for 16 series.


REgards,
Dennis Crawley
Argentina.

PS: To sale, please change the Tag... or re-read the FAQ. :) my 300$


2005\04\30@154336 by Mark Rages

face picon face
On 4/30/05, Dennis Crawley <.....proyectosenpicKILLspamspam.....yahoo.com.ar> wrote:
{Quote hidden}

Thanks.

I'm not sure that solves my problem though.

I'll try it on a simulator when I have time and post the raw
(unconverted) byte values.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\04\30@183333 by Dennis Crawley

flavicon
face
Mark Rages <markragesspamspam_OUTgmail.com> wrote:
{Quote hidden}

I do.

>
> I'll try it on a simulator when I have time and post the raw
> (unconverted) byte values.


I've already did it for you, this is the code. Do not forget all the
includes, and read carefully page 3 of AN575:


;-1.0 + -1.0 = -2.0
;-1.0 = IEEE FORMAT: BF800000
;-1.0 = PIC  FORMAT: 7F800000
;Expected:
;-2.0 = IEEE FORMAT: C0000000
;-2.0 = PIC  FORMAT: 80800000

SELF
;input in IEEE format

 MOVLW 0xbf
 MOVWF AEXP
 MOVLW 0x80
 MOVWF AARGB0
 MOVLW 0x00
 MOVWF AARGB1

 MOVLW 0xbf
 MOVWF BEXP
 MOVLW 0x80
 MOVWF BARGB0
 MOVLW 0x00
 MOVWF BARGB1

IEEE2MCHP:
       RLF    AARGB0,F
       RLF    AEXP,F
       RRF    AARGB0,F

       RLF    BARGB0,F ;yeah!
       RLF    BEXP,F   ;also this one
       RRF    BARGB0,F


 CALL FPA24

MCHP2IEEE:
       RLF AARGB0,F
       RRF AEXP,F
       RRF AARGB0,F

 GOTO SELF

Voilá!
Dennis Crawley
Argentina.

:))))$300!!!

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