Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can anybody help with Floating Point Routines for PIC 18F ?

Status
Not open for further replies.

3BABY

Member level 5
Joined
Jan 14, 2011
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
New Zealand
Activity points
2,252
Hi Guys,

ive been looking through Microchips IEEE 754 sheet and trying to manipulate it to work on 18F series but its just not happening.. would anyone out there have some Add, Subtract, Multiply, Divide, integer to FP routines that they could share? single precision would be perfect!


Thanks,
 

I remember using float variables in C18 without any problems. The problem was that only one operation at once seemed to be allowed, otherwise producing syntax error (for example d=(a/b)*c produced syntax error).
 

I remember using float variables in C18 without any problems. The problem was that only one operation at once seemed to be allowed, otherwise producing syntax error (for example d=(a/b)*c produced syntax error).

I believe AN575 was targeted at the PIC16 & PIC17 range, which may be the reason you are not having much success.

The following is a set of assembler floating point routines for the PIC18F:

**broken link removed**

The originating web page is Old Nabble - PIC - [PIC] - Complete working 32 bit floating point math library for PIC18x needed

Hey Guys,

thanks for the replys.. it looks like the above link was to a 18F'd version of the Microchip AN575.. which is basically what i was trying todo..

anyways.. i have copied the code from the asm and ran the Flo32_Add routine with the below in AARG and BARG ( 3.5 and 2.5 ) but i dont get back the floating point value of decimal 6.. i get back 3.5 as in:

10000000 in AEXP
01100000 in AARGB0
00000000 in AARGB1
00000000 in AARGB2


when i should be get

10000001 in AEXP
01000000 in AARGB0
00000000 in AARGB1
00000000 in AARGB2


Code:
;Number: 3.5
; 10000000 11000000 00000000 00000000

MOVLW b'01100000'
MOVWF AARGB0
MOVLW b'00000000'
MOVWF AARGB1
MOVLW b'00000000'
MOVWF AARGB2
MOVLW b'10000000'
MOVWF AEXP


;Number: 2.5
; 10000000 01000000 00000000 00000000

MOVLW b'00100000'
MOVWF BARGB0
MOVLW b'00000000'
MOVWF BARGB1
MOVLW b'00000000'
MOVWF BARGB2
MOVLW b'1000000'
MOVWF BEXP



		CALL Flo32_Add




what im confused about is the below, is AARGB0 supposed to equal HIGHBYTE ? if so that would mean the SIGN / MSB of AARGB0 is correct but the hidden bit is still the MSB and hasnt shifted this bit out.. and AEXP / EXPONENT should be 1 higher.

could anybody please test this routine for me to confirm it is or isnt giving the correct result?

thanks



;*****************************************************************************
; 32 bit floating point representation
; EXPONENT 8 bit biased exponent
; It is important to note that the use of biased exponents produces
; a unique representation of a floating point 0, given by
; EXP = HIGHBYTE = MIDBYTE = LOWBYTE = 0x00, with 0 being
; the only number with EXP = 0.
; HIGHBYTE 8 bit most significant byte of fraction in sign-magnitude representation,
; with SIGN = MSB, implicit MSB = 1 and radix point to the right of MSB
; MIDBYTE 8 bit middle significant byte of sign-magnitude fraction
; LOWBYTE 8 bit least significant byte of sign-magnitude fraction
; EXPONENT HIGHBYTE MIDBYTE LOWBYTE
; xxxxxxxx S.xxxxxxx xxxxxxxx xxxxxxxx
; |
; RADIX
; POINT



**** EDIT ***

and the same thing happens when i try to add decimal 5 to 3 i get 5 back in AARG.. and again with 3 + 4 i get 3 back in AARG... is the Add routine even manipulating AARG??? i have steped through it but cant see anything crazy happening..

on another note the integer to floating point routine seems to work..

from what i understand the SIGN part of the 32bit floating point number is the MSB of AARGB0 and the other 23 bits is the mantissa.. the AEXP is the 8 bit exponent.. correct?
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top