Going back to basics, some advice on memory storage


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Going back to basics, some advice on memory storage

    Guys, I need some advice on basic storage locations as I'm running round in circles...

    Pic: 18F4620

    Task: To load a set of pre-set values for a project that has 16 channels when first programmed. Each channel has an on time, an off time and a maximum value for the level. All of these are word variables can then be set by a user via menu options, so for argument sake all the on times can be pre-set to 14:00 hrs and then the user can set channel one to 15:00 hrs, then channel two to 16:00 hrs etc. Then in the event of a power fail these user values are saved and then read back in.

    At the moment I can have used the normal READ and WRITE statements to keep track of the user set variables, but its been suggested that I need to use the DATA statement to write the initial data to the EEPROM. The only thing is I'm not that clear on how to do this correctly.

    My current read write statements start at location 8

    Code:
    write 8,CH1_Max.lowbyte                           
    write 9,CH1_MAX.highbyte
    write 10,CH2_Max.lowbyte                          
    write 11,CH2_Max.highbyte 
    write 12,CH3_Max.lowbyte 
    .....
    write 102,CH16_off_Time.lowbyte          
    write 103,Ch16_off_Time.highbyte
    No I know that the DATA statement uses a similar arrangement for location, so would I simply substitute the WRITE command for DATA ?

    Code:
    DATA 8,CH1_Max.lowbyte                           
    DATA 9,CH1_MAX.highbyte
    DATA 10,CH2_Max.lowbyte
    And does the READ statement work with DATA statement, or do I need to use EEPROM statement is some way ?

    Sorry if this seems a noob question, but in my previous projects I've never bothered with worrying about saving the settings as it was often quick enough to re-enter them manually as there were not so many values to set..but 96 entries is just a tad to much...

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    horses an water

    I try again this seems to have gone through to the keeper
    http://www.picbasic.co.uk/forum/showthread.php?t=20966


    arrays and the ext modifier don't exist for no reason

    Code:
    data_block var byte[96]
    i var byte
    ch_max var word ext   ;accessable as ch_max[0] to ch_max[15]
    ch_on  var word ext   ;accessable as ch_on[0] to ch_on[15]
    ch_off var word ext   ;accessable as ch_off[0] to ch_off[15]
    
    asm
    ch_max =  data_block
    ch_on  =  data_block+32
    ch_off =  data_block+64
    endasm
    save_data:
    for i = 0 to 95
    write 8+i ,data_block[i]
    next
    return
    read_data:
    for i = 0 to 95
    read 8+i ,data_block[i]
    next
    return
    
    set_defaults:
    for i=0 to 15
    ch_max[i]= 3000
    ch_on[i}= 1800
    ch_off[i]=600
    next
    return

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    Richard, your previous posts hadn't been overlooked... I was trying to keep my explanation as simple as possible with regards to the locations in order to help explain what I was looking for, which was info on the correct way to use the DATA and EEPROM statements... which you appear to of overlooked in your reply whilst you were hell bent on being sarcastic with your

    horses an water

    I try again this seems to have gone through to the keeper"

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    sorry about the sarcasm ,but doing it your way that's a lot of typing

    still
    DATA 8,CH1_Max.lowbyte
    DATA 9,CH1_MAX.highbyte
    DATA 10,CH2_Max.lowbyte
    won't work data can only store constants

    data @8, 123,34,23,15 ........................ for the other 92 values

    and it can be readback with read
    Last edited by richard; - 23rd March 2016 at 23:17. Reason: @fell off

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    DATA is used to store the value(s) in the EEPROM when the device is programmed. Ie. to get a "default" value in there. It's embedded in the .hex file image which get programmed into the device.
    WRITE is used to store values in EEPROM during runtime.
    It doesn't matter HOW the values got there, READ will access them.

    You don't really have to keep track of the adresses etc, you can do
    Ch1_On_Time DATA WORD 1234
    Ch1_Of_Time DATA WORD 2345

    This way you have created a label for each entry in the EEPROM which you can then use when your READ or WRITE from/to it in your code. Please note that Ch1_On_Time in this case is NOT your variable - it's ONLY a label. To actually USE it in your program you need to READ it from EEPROM and Place it an ordinary variable - but you're already doing that.

    Using arrays, the EXT modifer, and indexing thru the data as in Richards example is probably more efficient code wise but may not be the easiest way to debug and/or understand. YMMV.

    /Henrik.

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    Henrik,

    Thank you for your very informative post. I agree that Richards guidance in using the array and modifier makes for tighter compact code. I just thought that in this case it might of muddied the water a little when I was trying to explain my question.

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    Henrik,

    If I follow your post correctly I can do the following

    Code:
    DATA @8,0 
    
    EE_CH1_Max DATA WORD 4095
    EE_CH2_Max DATA WORD 4095
    
    etc
    and then

    Code:
    read EE_CH1_Max, WORD CH1_Max
    read EE_CH2_Max, WORD CH2_Max
    The part I can't get my head round is assuming you place the data statement at the start of the code so this happens when the code is run, what distinguishes it from a fresh install and a reboot as surely the code is executed from the start when powered up and will use the data command when it reaches that line of code ?

  8. #8
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Going back to basics, some advice on memory storage

    Oh it's so much easier with labels than using all that location, lowbyte hughtbyte stuff !!!

    I now have a set of preset values loaded first time after the chip is programmed, and user variables saved once changed by the user, which are retained in the event of a power fail...

    Now to do a few more bits before following Richards examples to tidy up the code and make ot a bit more compact...

Similar Threads

  1. I2C storage issue
    By lerameur in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th November 2010, 19:42
  2. Memory Overflow? Urgently need advice
    By curian88 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th April 2010, 14:42
  3. data storage label
    By MINHLE in forum General
    Replies: 6
    Last Post: - 17th December 2009, 14:04
  4. internal storage space?
    By gtrplaya101 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th October 2009, 06:45
  5. The basics
    By malc-c in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 22nd June 2008, 00:09

Members who have read this thread : 0

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