FRAM (MB85RC256V), Atmega 2560, external storing

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I hope this is the right section.

 

My project is basically a data logger(temp,Humidty, accel, FRAM) eventual.  Right now I  only have I2C communication back and forth to the FRAM, and can store on any address. My next issue is figuring out how to store my data on the MB85RC256V effectively without wasting space.  Say i was to store a string : "100,30, 40, 70",  which is bigger than 1 address location, what would be the best way of keeping track of where my strings starts and stops and how do I separate one string to fill up a location. 

 

 

I am sorry if I am making myself unclear, I am still a newbie. I appreciate any input, maybe someone knows of a similar project/problem/guide, and would be kind enough to link it in the comments. 

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your string takes 13 bytes of storage include the end of line character. Since your FRAM is only 32k bytes, storing strings is not necessarily the most efficient means of storage. It is convenient though.

 

There's a couple of ways you can use to determine the end of your data - scan each location and test for 0xff. Since 0xff is not a valid character and is the default erased value of the FRAM (check this!), then the first location with 0xff is the end of your currently stored data. This takes time and depends on have much data you're already stored.

 

 

The other technique is to use the first two locations to store the address of the first free location.

 

Finding the end of each of your strings is easy - terminate each string with an end of line like a 0x0d.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your example data takes 13 bytes as a sting but just 4 bytes as a structure containing hex values.

 

So, list every variable you want to store, the range it can take, and the precision you want to store it at.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the input!

I dont think i completely understand why 0xff is the default erased value of the FRAM, do you have a reference? 

Sounds like a great idea to store each variable as a hex value to save space. For instance I would store time, temperature, humidity, acceleration all as hex values and separate them with the value of Comma(or is another value maybe better?).

Range and precision is also good points i need to consider, would you recommend me to for instance evaluate the range of each set of variables(1-6 bytes total) and distribute them 8 bit at the time?

 

Thanks for taking the time to reply!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mr_logger wrote:

...and separate them with the value of Comma...

 

Why bother separating them with anything  at all? If you are always storing, for example, four 8-bit values then you know the first set of values starts at offset = 0, the second set at offset = 4, the third at offset = 8 and so on.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are absolutely right, I didn't even think of that...

This might sound stupid, but eventually i would like different modes of operation. While in one mode there will only be stored 2 variable, another mode will store 5 variables. For instance if the temperature value is not high enough it wont be stored on the Fram etc.

I can see how your solution would be the easiest to keep track of all variables if I where to have the same 4 variables stored all the times. Since I would need to Identify these variables when i read them back later, how can I recognize storing 4 variables and then just 2 variables later. 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Fram is easy to use, but expensive for large memory storage.

Life is much easier if you allocate some memory for a structure to hold your data.

For example put your data in a "packet", that include a packet type, (1 = format #1 with all data,, 2 = format 2 with just temp and humidity, ....).

It is easier if you have a Start of Packet character, (a character that isn't used within the data set), to scan through the data looking for packets, but technically that isn't necessary if you know the format for each packet that has been stored, and therefore its length.

 

Many data loggers include a data and time as well, so you know when the data measurement took place.

 

Storing the data as numeric data is more compact than storing the data as an ASCII string, but an ASCII string is human readable.

 

If you need more memory to accommodate the overhead of the packet structure, then add a second chip...

 

If you really need lots of storage then think about moving to an SD card for the data storage.

Then you can have GB's of data for the cost of a Fram chip or two.

There are canned libraries for file structures for use on SD cards that makes them PC readable as well.

 

JC

  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, you don’t need to erase fram like you do with flash or eeprom, so there is no default value, but that doesn’t stop you filling it with 0xff or whatever value you like.

As for determining if you have stored 4 variables or two variables, you need some means of determining this. You could begin each message with a magic number that tells you what the following data is, but that mightbe wasteful. If you tell us the range of values each sample has, then we might be able to suggest ways of packing and labelling the data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mr_logger wrote:

how can I recognize storing 4 variables and then just 2 variables later. 

 

If the stored data doesn't need to persist across mode changes, ie still be valid after you change mode, then just make your first 'record' in memory a note of what mode the data was recorded in.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great stuff here guys, thanks again! 

 

If I understand this data "packet" correctly, I would for instance allocate some memory before each sets of variables or at a separate location in the memory?

I understand that eeprom or flash maybe more suitable, but I cant change this anytime soon. I am basically stuck with the Fram for now.

 

When it comes to the range of  each variable:

 Time: still uncertain what would be best here. If year-month-date-hour-min-sec is the best solution or just how many 30/15/10/5 minutes has gone since start(and just calculate later). I guess if the logger has been logging for a year i might get a issue.

Temperature :in degrees Celsius. number between -40.00 to 90.00,

Humidity: number between 0.0 to 90.0

Accelerometer: number beween -4.0 and +4.0 

 

I haven't yet decided how accurate(in decimals) I would need to store the data.

 

By a "magic number" you mean like 1=Temperature, 2= Humidity etc? Would this not give me the wrong number when reading it back? 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mr_logger wrote:

...or just how many 30/15/10/5 minutes has gone since start(and just calculate later). I guess if the logger has been logging for a year i might get a issue.

 

I think every logger I've seen takes a set of measurements at a regular interval, so all you need to record is the start date and time, and the interval. If each measurement is taken at a regular interval then you do not need to record the data and time with the measurement as it's implied.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss