Shop OBEX P1 Docs P2 Docs Learn Events
BS2 - Reading and writing to EPROMM - Im confused — Parallax Forums

BS2 - Reading and writing to EPROMM - Im confused

Lee_SpeakmanLee_Speakman Posts: 32
edited 2006-03-15 00:41 in BASIC Stamp
Hi everyone, id just like to ask how to read and write to the BS2's EPROMM, all the tutorials I have seen, seem to be really conpilcated!

Its for my digital dash project. I wish·to store 4·variables in EPROMM, which are all 16 bit word variables:

1)···· CIRC
2)·····RPM_LIMIT
3)·····RPM_LAUNCH
4)···· FAN_ON

At program startup these values must be recalled for use in the program and if the user wishes to change them in the setup they can. Any ideas? Im confused!

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-03-13 14:51
    Well, the EEPROM comand is for the BasicStamp 1 only.

    For similar needs, the BasicStamp 2 uses the DATA command.

    Variables must be declared as to Byte or Word length so that proper RAM locations are available. I suspect you are getting your four items confused with variables located in RAM.

    The CONSTANTS declaration is what will store a value in EEPROM to be called by name from within the program. I have a bit of trouble determinining if the BasicStamp 2 with store a 16 bit constant or not. And 8 bit constant would be limited to 256 while a 16 bit constant would go over 65,000.

    You may be able to store a High and Low segment of each constant to be combined after being sequentially read.

    Anyone else out there?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-13 15:08
    Lee,

    ·· You will need to use the READ and WRITE commands to write data to the EEPROM on the BS2.· Be careful of how often these values are updated since EEPROM has a finite write lifetime and using them as variables could easily wear them out.· If you're just loading them into existing variables at startup you should be fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Lee_SpeakmanLee_Speakman Posts: 32
    edited 2006-03-13 17:35
    Thanks Chris and Kramer. I sorted it out today in labs using the READ and WRITE commands. It only ever writes if you change one of the values upon startup, but most of the time it just stays constant. Its only needs to be re wrote with engine changes and wheel changes.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-13 21:36
    Note that you only have about 1 million writes to an eeprom location before that location 'wears out' -- ie will always read as a zero. That's a LOT of writes if you write once every 5 minutes. That's NOT a lot of write if you write once every second (it's about 277 hours, or 11 days of continuous running).

    So, if by "engine changes and wheel changes", you mean when you REPLACE the engine and REPLACE the wheels, and you only do that a few times a day, no problem. If by 'engine changes' you mean you rev-up the RPM, then you'll probably have a problem.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-03-14 09:38
    Allanlane5,
    I understand your approach and I don't have much experience with this.
    I look at the PBasic Manual and read that 'all math is done in 16-bit width'.

    Does that mean that any CONSTANTS can be a 16-bit number too? [noparse][[/noparse]I guess I should just test it out myself.]

    If so, that is a lot easier than creating DATA space, WRITING to the DATA for a one-time input, then declaring VARIABLE word space to transfer into, and READing the data into the VARIABLE, and finally using it.

    Whew!!!. As you can see, just declaring a CONSTANT would be much easier, more user friendly, and probably take up less space overall.
    Can it be done?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-14 15:02
    Kramer,

    ·· Two cases where a CONstant wouldn't work.· In his case it won't because the value needs to be changed and stored for later retrieval.· You cannot do that with a CONstant, since it cannot change.· Also, there are some other times when CONstants won't work will a DATA statement will.· Take storing string data for example.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-03-14 15:54
    I do indeed understand that there are conditions where CONSTANT won't work.
    Are there 16 bit conditions where it WILL work?

    I think he is calling his input Variables in error. They appear to me to really be Constants within the program and from what I see are not being changed within the program. He is just using them to set limits and intialize the program.

    Of course, I have been wrong before.........

    That still leaves me unsure if Constants can handle 16 bits or only 8bits. It really is hard to infer that from the PBasic manual.

    BTW, I do understand that Strings are usually much longer than Work length, so these wouldn't work.
    Also, tables of DATA are only useful if you have precise knowledge of where exactly everything is. Then you can choose the 3rd or 40th item at will. Neither case seems to apply.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 3/14/2006 4:24:07 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-14 15:59
    Kramer said...(trimmed)
    I think he is calling his input Variables in error. They appear to me to really be Constants within the program and from what I see are not being changed within the program. He is just using them to set limits and intialize the program.
    Of course, I have been wrong before.........
    Kramer,

    ·· I didn't look at the code so you could be right there.· I was just addressing the use of CONstants over DATA.· Unfortunately I have to step out so I may have to glance at it later today.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-14 16:06
    Lee,

    This is no problem; you simply create DATA statements to hold the values and use READ to grab them, WRITE to modify them.· Start by defining space (you can also use this to set default program start values):

    Circ········ ·DATA·· ·Word 0
    RPM_Limit··· ·DATA··· Word 0
    RPM_Launch··· DATA··· Word 0
    Fan_On······· DATA··· Word 0

    Note that you must use the Word modifier to reserve two bytes for each value.· You would do this to retrieve a value:

    · READ·Circ, Word circLevel

    Two things: Again you must use the Word modifier, and your variable name must be unique (you can't use the same name as the DATA label).· To put a value back, it's just as simple:

    · WRITE Fan_On, Word fanStatus


    Lee_Speakman said...
    Hi everyone, id just like to ask how to read and write to the BS2's EPROMM, all the tutorials I have seen, seem to be really conpilcated!

    Its for my digital dash project. I wish·to store 4·variables in EPROMM, which are all 16 bit word variables:

    1)···· CIRC
    2)·····RPM_LIMIT
    3)·····RPM_LAUNCH
    4)···· FAN_ON

    At program startup these values must be recalled for use in the program and if the user wishes to change them in the setup they can. Any ideas? Im confused!
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-03-14 16:29
    I guess I have misinterpreted the bold italics at the bottom, 'if the user wishes to change themin the setup they can."

    I will try programing some 16bit Constants for my own satisfaction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-14 16:32
    If you're going to give the user the source code you can either embed constants into the DATA table, or just embed the values -- not a big difference here as each DATA element is named.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-14 23:44
    Thanks Jon.· Didn't have time to follow up on this one earlier.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-15 00:41
    Note that the following is true:

    MyCon CON 2000

    MyVar VAR WORD

    MyVar = 1
    while MyVar < MyCon
    ' Do stuff
    wend ' or whatever...

    Now, where 'MyCon' is in your source code, the compiler plugs in the value 2000. Thus declaring MyCon takes no variable space -- which is very nice in the tight space in a BS2.
Sign In or Register to comment.