CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Float in eeprom using #rom getenv("EEPROM_ADDRESS"

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

Float in eeprom using #rom getenv("EEPROM_ADDRESS"
PostPosted: Thu Nov 18, 2010 10:01 am     Reply with quote

Hi All,

My question can be defined as following:
Code:
#define eeoffset 0x10
#define ResistanceHigherCurrent  1.8

#rom getenv("EEPROM_ADDRESS")+eeoffset = {"string"}


In the code above, how to write into eeprom the 1.8 float value as 32-bit float instead of the "string"?

Best wishes.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: Float in eeprom using #rom getenv("EEPROM_ADDRESS&q
PostPosted: Thu Nov 18, 2010 11:33 am     Reply with quote

FFT wrote:

In the code above, how to write into eeprom the 1.8 float value as 32-bit float instead of the "string"?

the EEPROM internal construction is 8 bits (1 byte); in these 8 bits you can store a char or a int8 value. and obviously, many char's can be concatenated, and the result is a string. you have already seen how this works.

but to store a float in EEPROM you must break it down into 8bit "chunks". there are many ways to approach this, and it is somewhat application dependent. one simplistic (and brute force) option is in fact to continue to store the string, and convert the string to a float as needed in your program. look into the C language's atof() and sscanf() functions.

otherwise, you will have to determine a method to take your float value (bounded, for many reasons) and represent it as a structure of 8bit values. there are several practical ways to do this.

jds-pic
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 12:51 pm     Reply with quote

(apparently useless post deleted)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D


Last edited by bkamen on Thu Nov 18, 2010 3:43 pm; edited 1 time in total
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 3:38 pm     Reply with quote

Hi and thanks for the answers but these are not the solution.

I think you misunderstood the question.
I ask how to initialize float data in eeprom (embedded in hex file) for the programming moment. I already can read and write float values at run-time.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 3:45 pm     Reply with quote

you don't have to.

When you initialize the variable, there will be code to do it for you.


so when you say:


float var=1.8;

there will be code to initialize it to the desired value.

If that's not what you want, then you are not fully explaining what/why you are trying to accomplish and should consider elaborating your situation/goal a little more.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 4:24 pm     Reply with quote

He wants to know how to easily store a floating point number in the PIC's
data eeprom at compile time.

I think he wants something like this, except for floating point:
http://www.ccsinfo.com/forum/viewtopic.php?t=35202

Here is one way, but it's not very easy to use:
http://www.ccsinfo.com/forum/viewtopic.php?t=40322
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 8:28 am     Reply with quote

@PCM_Programmer,
Thanks so much, this is what I want.

But, what is the difference between 32-bit float and int32?

Code:
#define putLong(value) {value,(value>>8),(value>>16),(value>>24)}
#rom 0x0f000 = putLong(0x12345678)


Why that code cannot be used for floats too?

Actually we don't care about the mantissa, sing... , just we have 4 bytes to store.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 4:00 pm     Reply with quote

It doesn't work. A method is needed that can extract the 4 bytes that
make up a floating point number, and do it at compile time. I don't
immediately know how to do this.

If a method doesn't exist, CCS would have to be requested to add the
feature.
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 10:03 pm     Reply with quote

Why not just let the program initialize eeprom when it is first run?
You can read a 'flag' byte of eeprom at powerup. If it is not 0x00, for instance, then you write your initialization values to eeprom and write 0x00 to your flag byte. Future power ups will not re-write it.

Just a thought
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 4:08 am     Reply with quote

The problem is that on small chips, this is a waste of space.

It is what I do.

I declare my eeprom data as a structure, containing all the stuff I want to store, and with an extra 'marker' byte at the start, initialised with something like 0xA5. The structure is declared in the main code with initialisation values. Then on boot up, I simply test if the 'marker' matches the marker in ROM. If not, I copy the entire structure into the ROM, while if it does match (implying the data has been used before), I instead read it back.

It is a silly weakness really of the compiler, with it happily accepting #ROM int16, or #ROM int8 declarations, but not accepting #ROM float, or #ROM int32.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group