Optimize eeprom capacity


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2006
    Location
    Lazio, Italy
    Posts
    41

    Default Optimize eeprom capacity

    Hi, I have some eeprom locations where I store information as possible . For example, I read the contents of four memory locations , I transfer it on four variables for a total of 32 bits. Now I have to memorize series of numbers ranging from 0 to 59 and then for this needs only six bits each so I can store 5 numbers and I advance two locations where I can store a variable that arrive up to 3 and so on . Or I could enter numbers of up to 10 occupying only 4 bits and I could insert 8. In short, I would like to optimize memory I have available The problem is how to put in the byte , and then remove only the bits that interest me ? There is an elegant way to manipulate these variables and then transfer them in eeprom? I hope I was clear . thanks

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Optimize eeprom capacity

    External EEPROM is so cheap and easy to use, is it really worth it?

  3. #3
    Join Date
    Jul 2006
    Location
    Lazio, Italy
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Optimize eeprom capacity

    Unfortunately I have to change the program of a Pic with EEPROM and I have to add more data . I could insert another EEPROM but I should change almost one hundred printed circuit boards. I think it is more convenient to optimize what I have now . Thanks

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Optimize eeprom capacity

    Hi,
    Sounds a lot like BASE64 encoding to me...
    Anyway, here's one way of doing what you ask:
    Code:
    InValues    VAR BYTE[4]
    OutValues   VAR BYTE[3]
    
    
    ' Max assignable value is 63
    InValues[0] = 50
    InValues[1] = 51
    InValues[2] = 52
    InValues[3] = 53
    
    Main:
      HSEROUT["Program start",13]
      OutValues[0] = ((InValues[0] & %00111111) << 2) + ((InValues[1] & %00110000) >> 4)
      OutValues[1] = ((InValues[1] & %00001111) << 4) + ((InValues[2] & %00111100) >> 2)
      OutValues[2] = ((InValues[2] & %00000011) << 6) + ((InValues[3] & %00111111))
      
      ' Print input values, only the 6 least significant bits of each value
      HSEROUT[BIN6 InValues[0], BIN6 InValues[1], BIN6 InValues[2], BIN6 InValues[3],13]
      
      ' Print output values, now encoded into 3 bytes.
      HSEROUT[BIN8 OutValues[0],BIN8 OutValues[1], BIN8 OutValues[2],13]
    
      Pause 100
      END
    It produsces the followin output
    Code:
    Program start
    110010110011110100110101
    110010110011110100110101
    /Henrik.

  5. #5
    Join Date
    Jul 2006
    Location
    Lazio, Italy
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Optimize eeprom capacity

    Thanks Henrik, your solution seems like a good starting point .

  6. #6
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Optimize eeprom capacity

    I think, as Henrik demonstrates, allotting 6 bits to each value is the most efficient or supportable or likely to be upgradable later (perhaps at some future date a pin-compatible processor with more EEPROM) method and so this is my advice as well. And, as he demonstrates the details, I will only suggest that a bit array of 24 elements would store 4 of your 6 bit numbers and write to 3 bytes of EEPROM without waste (well, except the two final bytes). For myself, it seems easiest to read and write to this array - shifting values in prior to a write and out to retrieve the stored values. Simpler in my mind to calculate retrieval positions with integer math. Henrick has done the "heavy lifting" for the subroutines to read and write...

    You may also look at BCD encoding. This is typically done with 4 or 8 bits, but there are 6 bit examples out there. Perhaps there is something that we have not thought of...

Similar Threads

  1. Replies: 6
    Last Post: - 11th September 2014, 10:50
  2. suggest optimize code
    By xxxxxx in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th March 2009, 13:24
  3. 9V battery capacity question
    By luminas in forum Off Topic
    Replies: 2
    Last Post: - 19th August 2008, 16:02
  4. EEprom
    By lerameur in forum General
    Replies: 1
    Last Post: - 23rd November 2006, 05:30
  5. EEPROM help
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th February 2005, 22:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts