Question about real type

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

Question about real type

#1 Post by Skydec » 08 Feb 2009 16:25

For a project I have to decode floating point values send over the serial port.
What I want to do is declare an absolute real type and an array of byte also absolute.
But I was wondering how is real type made?
Is it according IEEE 754 (sign, exponent, fraction) ?
How many bits are used for exponent and fraction, what is the bias (127?)

Or does anybody made some floating point conversions? single precision and double precision?

Thanks in advance.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Question about real type

#2 Post by Dany » 08 Feb 2009 19:02

Skydec wrote:For a project I have to decode floating point values send over the serial port.
Are they sent in ascii or in binary? If they are sent in ascii, then you can use the "Str2Float" function from Yo2Lio's "String Util" library (http://www.microelemente.ro/MikroPascal/).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

#3 Post by Skydec » 08 Feb 2009 21:12

They are send in binary..

I allready use those functions, they are very nice! but I can't use them for this problem.

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#4 Post by FRM » 10 Feb 2009 20:25

I am assuming you are concerned with how to handle the bytes at the pc side? I have only used Delphi for this.

Using standard or (excellent) 3rd party libs such as florin's/janni's -
PIC/mP use microchip format, whereas dsPIC/mPdsPIC handles bytes as IEEE.

Both versions would be treated as single precision in pc based compiler.
The PIC real type would need to be converted to IEEE for easy usage in pc based compiler like Delphi (ask janni about this if interested!)
Real data bytes are stored lowest to highest byte.
Here's a little code from a PIC project:

Code: Select all

Eeprom_Array : Array[0..120] of byte; absolute $74;

pGain : real; absolute $74;                        //0-3
pGain_lo : byte; absolute $74;                     //0
pGain_hi : byte; absolute $75;                     //1
pGain_Higher : byte; absolute $76;                 //2
pGain_Highest : byte; absolute $77;                //3

iGain : real; absolute $78;                        //4-7
iGain_lo : byte; absolute $78;                     //4
iGain_hi : byte; absolute $79;                     //5
iGain_Higher : byte; absolute $7A;                 //6
iGain_Highest : byte; absolute $7B;                //7

dGain : real; absolute $7C;                        //8-11
dGain_lo : byte; absolute $7C;                     //8
dGain_hi : byte; absolute $7D;                     //9
dGain_Higher : byte; absolute $7E;                 //10
dGain_Highest : byte; absolute $7F;                //11

SamP_Step : Real; absolute $80;                    //12-15
ConP_Step : Real; absolute $84;                    //16-19
OilT_Step : Real; absolute $88;                    //20-23
TargP : Real; absolute $8C;                        //24-27
max_DP : Real; absolute $90;                       //28-31

filt_reg : Word; absolute $94;                     //32-33
filt_reg_lo : Byte; absolute $94;                  //32
filt_reg_hi : Byte; absolute $95;                  //33

mode_reg : Word; absolute $96;                     //34-35
mode_reg_lo : Word; absolute $96;                  //34
mode_reg_hi : Word; absolute $97;                  //35

ADC_CH1 : Longint; absolute $98;                   //36-39
ADC_CH1_lo : byte; absolute $98;                   //36
ADC_CH1_hi : byte; absolute $99;                   //37
ADC_CH1_higher : byte; absolute $9A; // 24bit data  //38
ADC_CH1_highest : byte; absolute $9B;// Not used initialised as '0'
You can use this way to reassemble ADC binary data quickly from spi reads etc.
I added the real to byte-wise declarations in for clarity.
I transmit the array sequentially via rs232 to front end written in Delphi, as well as storing parts of it in eeprom, but I do not know of any double precision routines for PIC in mPascal.
See also: http://www.mikroe.com/forum/viewtopic.p ... e77d0c779b
I hope this helps a little.

Skydec
Posts: 39
Joined: 30 Jan 2009 12:38

#5 Post by Skydec » 24 Feb 2009 22:38

Thanks for the reply.

It makes a bit more sence.

I'm going to try to find some explanation about pic's real type.

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#6 Post by FRM » 25 Feb 2009 01:20


Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”