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.
Question about real type
Re: Question about real type
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/).Skydec wrote:For a project I have to decode floating point values send over the serial port.
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)
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)
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:
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.
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'
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.
For more information you could try:
http://ww1.microchip.com/downloads/en/A ... 00670b.pdf
or~
http://ww1.microchip.com/downloads/en/A ... /00575.pdf
http://ww1.microchip.com/downloads/en/A ... 00670b.pdf
or~
http://ww1.microchip.com/downloads/en/A ... /00575.pdf