Need help understanding memory size

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

I need help understanding size of memory. I have a Mega64 and I'd like to use its internal 2K of EEPROM to store a list of voltages read from the ADC, every 15 minutes (only in a 24 hour period, then wrap) with the time stamp. Basically a voltage logger. I opened notepad and make a mock log of 96 entries (4 x 24 hours = 96). The file size when I was done was 8K. Does this mean it will not fit into EEPROM?

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

Not neceserily. You can "compress" data by logging it as hex values instead of characters.
I.e. if you read a voltage of 12v for instance, store it as 0x12 instead of the character '1'(0x31) and '2'(0x32). Then when you read it out of eeprom, convert it back to characters.
.txt files store data as characters, so you can easily halve the size.

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

As the ADC only returns a maximum of 10 bits then you shouldn't need any more than 2 bytes (16 bits) per entry. So your 96 readings in 24 hours should occupy 96*2=192 bytes of EEPROM. As you have 2048 bytes of EEPROM you have enough for almost 11 days of readings before you have to start re-using earlier entries. Assuming you use every byte in the EEPROM every 11 days and the EEPROM has a 100,000 write cycle life you should be good for more than 3,000 years of operation.

Cliff

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

Quote:
So your 96 readings in 24 hours should occupy 96*2=192 bytes of EEPROM.
Plus your time stamps.

Do you need an actual time (seconds past midnight sort of thing, with or without date), or will a simple "sample number" (0 - 95) suffice? If it will, you can use the position of your data in memory as the timestamp. You also have an extra 6 bits in each sample which could be used as part or all of the timestamp, such as a day number rollover. Then you'd know whether the sample in position (say) 10 was today's or 11 days ago.

Of course if you're not on a rigid 15 minute schedule and the sampling time is approximate, this all falls by the wayside. And so on. But within the constraints of your situation some space saving tricks on the timestamp may be possible.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Chuck,

Yup, assuming it's a fairly accurate 15 minutes I woudn't have thought you'd need anything more than a "day N starts here" marker. Maybe blow 2 bytes before every 192 reading bytes? Use the top bit to say it's a "day starts here" and the lower 15 bits to encode the day/year. You could even waste some bits. Days will run 0..365 (to include leap years) so you might as well use 9 bits for that leaving 6 bits for the year. So maybe even base it from 2000 and you still run up to 2063 even if you waste the 7 years we've already had this century.

Cliff

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

It will look like this:

09/21/2007  13:15:00  54  98

So I log 2 voltage readings every 15 minutes.

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

OK well all you need to know is that 21/9 is the 264th day of this year and store 264 (in 9 bits) and 07 in 6 bits and you've narrowed it down to 21/9/07. And the 13:15 reading is the 50th reading of the day. so after the 264/07 marker you look 100 bytes on and find 54/98 in those two bytes.

Cliff