Shop OBEX P1 Docs P2 Docs Learn Events
still trying to store data to eeprom — Parallax Forums

still trying to store data to eeprom

mike_1234mike_1234 Posts: 21
edited 2005-11-23 15:12 in BASIC Stamp
Hello,

I have started to write a new program, what i have is one input that has a value of dec 1.· Then i have a second input that acts as a way to dump the values retained in memory.

two problems.

1. when i use the second input to dump what is in memory on the debug screen all·i get is....

locaton 0 = 0
locaton 11 = 1
"······ "· " "· " "
and it keeps going everytime i push that second input button.

2.· I have just one input putting a value into memory, it doesnt matter if i push the button or not, it seems to keep on displaying the same thing... the value never changes

3.· Future problem... i will be adding three more inputs that each carry a dec value.· I will need to store each value to a memory location, so each time i store a number the memory location has to increment, just as if you were pushing numbers on to a stack.· (for all you 68hc11 lovers out there· lol).

here is a copy of my code, please send me feed back, thanks!

' {$STAMP BS2pe}
' {$PORT COM1}
' {$PBASIC 2.5}

INPUT IN0
INPUT IN1

idx·· VAR Byte
value VAR Byte
loc·· VAR Byte

Chk_Inputs:
· IF IN0 = 1 THEN GOSUB SUB1
· IF iN1 = 1 THEN GOSUB INFO_READ
GOTO Chk_inputs

SUB1:
· STORE 8
· WRITE loc, 2
RETURN

INFO_READ:
DEBUG "Location ", DEC idx, " = ", DEC value, CR

·STORE 8
··· FOR idx = 0 TO 10
··· READ idx, value

NEXT
RETURN

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-11-22 22:46
    Wow. I hope you realize that you can only write the eeprom values about a million times. That seems like a lot, until you create the kind of code you've created. As long as "in0" is high, this loop is going to run. And this loop looks like it will run in less than 1 millisecond.

    Thus, running this for about a week will 'wear out' your eeprom at location "Loc" -- which you never initialize, by the way, so I assume it's zero most of the time.

    So, please please please put a 'pause 1000' in your 'main' loop, so at least it only does one write per second.

    Plus, there's a big difference between an "Input" and a "Button". A "Button" you push needs to have some de-bouncing on it.
  • SN96SN96 Posts: 318
    edited 2005-11-22 23:11
    I would take the goto loop out to spare your eeprom, and just run a simple test without the buttons to leran how this works first.
    Here is what I found wrong with your code at a glance:
    ' {$STAMP BS2pe}
    ' {$PORT COM1}
    ' {$PBASIC 2.5}
     
     
    INPUT IN0
    INPUT IN1
    idx   VAR Byte
    value VAR Byte
    loc   VAR Byte
     
    '-----------( Mian )-----------------
     
    Chk_Inputs:
      IF IN0 = 1 THEN GOSUB SUB1
      IF IN1 = 1 THEN GOSUB INFO_READ
    GOTO Chk_inputs
     
    '-----------( Subs )-----------------
    SUB1:
      STORE 8                ' I would change this to 7
      WRITE loc, 2           ' This says write value of 2 at location 0 (loc has no value assigned)
      RETURN
    INFO_READ:
      DEBUG "Location ", DEC idx, " = ", DEC value, CR
        STORE 8             ' <-------- Help file shows only a range 0 to 7 so 8 is not good
          FOR idx = 0 TO 10 ' <-------- This should be 0 to 7 as there are only 8 slots
            READ idx, value
          NEXT
      RETURN
    

    I do not have a BS2pe so this is as much help I could provide.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike



    Post Edited (SN96) : 11/22/2005 11:22:18 PM GMT
  • aliniousalinious Posts: 51
    edited 2005-11-22 23:42
    Mike_1234,

    I have reworked the program so that if you press a button it will store the value (1,2,3, or 4 ) to the E2PROM. The E2PROM addresses are automatically incremented as you had mentioned (WR_E2PROM_Addr = WR_E2PROM_Addr + 1). Thus if you press 1, 2, 3, 4, 4, 3, 2, 1; Address 0 = 1, 1 = 2, 2 = 3, 3 = 4, 4 = 4, 5 = 3, 6 = 2, 7 = 1... and so on.

    When pin 5 is taken high the BS2pe will read all the contents of E2PROM slot 8 and display them on the debug screen.

    I have attached the program below.

    SN96: STORE 8 is valid because the BS2pe has 16 slots of E2PROM (0 - 15). Check out the help file under STORE and you will see it is the BS2p /px that has only 8 E2PROM slots (0 - 7). Also, if the STORE value is greater than the range of the BS2xx ($Stamp Directive) )being used the compiler will flag it as an error.

    Sorry it took awhile to respond, tied up in traffic,

    Alan Balich

    Post Edited (alinious) : 11/23/2005 1:31:59 AM GMT
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-22 23:44
    how do i intizalize loc??

    and when i try to debug the memory it starts at location 0 and then jumps to 10 and stays there never showing me the correct data or location 1-9...

    why is it never storing the number 2 to memory??





    here is the code i've adjusted

    ' {$STAMP BS2pe}
    ' {$PORT COM1}
    ' {$PBASIC 2.5}

    INPUT IN0
    INPUT IN1


    idx·· VAR Byte
    value VAR Byte
    loc·· VAR Byte


    Chk_Inputs:
    · PAUSE 1000
    · IF IN0 = 1 THEN GOSUB SUB1
    · IF IN1 = 1 THEN GOSUB INFO_READ

    GOTO Chk_inputs

    SUB1:
    ·DEBUG " storing·2 to memory location", CR
    · STORE 0
    · WRITE 2, loc
    RETURN

    INFO_READ:

    DEBUG "Location ", DEC idx, " = ", DEC value, CR


    ·STORE 0
    ··· FOR idx = 0 TO 8
    ··· READ idx, value
    ··· idx = (idx + 1)
    ··· IF idx = 8 THEN INFO_READ

    NEXT
    RETURN
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 00:40
    Hello Allan,



    thanks for the code... i understand now...

    if i wanted to start at 0 and go right to 15 how would i do that?
  • aliniousalinious Posts: 51
    edited 2005-11-23 00:44
    Mike_1234,

    When you say start at 0 and go right to 15, do you mean the E2PROM addresses or the values stored at the E2PROM addresses?

    Alan
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 00:46
    the values stored in eeprom

    like storing the numbers 0 - 15
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 00:48
    actually just 0 - 13 because we'll leave the p15 then pin to dump the data
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 00:51
    alan,

    heres an example of what i mean,

    pin 0 = dec 0
    pin 1 = dec 1
    pin 2 = dec 3

    right up to pin 13 = dec 13

    and then pin 15 we'll use to dump the memory
  • aliniousalinious Posts: 51
    edited 2005-11-23 01:27
    Replace Input_Pins_0_3 VAR INA with Input_Pins_0_13 VAR INS.

    Replace RD_E2PROM_Switch PIN 4 with RD_E2PROM_Switch PIN 15.

    Replace the Convert_Decimal with the new one written below.

    Alan

    Convert_Decimal:
    IF (Input_Pins_0_13 = 1) THEN
    Value_To_Store = 0
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 2) THEN
    Value_To_Store = 1
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 4) THEN
    Value_To_Store = 2
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 8) THEN
    Value_To_Store = 3
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 16) THEN
    Value_To_Store = 4
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 32) THEN
    Value_To_Store = 5
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 64) THEN
    Value_To_Store = 6
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 128 ) THEN
    Value_To_Store = 7
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 256) THEN
    Value_To_Store = 8
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 512) THEN
    Value_To_Store = 9
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 1024) THEN
    Value_To_Store = 10
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 2048) THEN
    Value_To_Store = 11
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 4096) THEN
    Value_To_Store = 12
    GOSUB WR_E2PROM
    ENDIF

    IF (Input_Pins_0_13 = 8192) THEN
    Value_To_Store = 13
    GOSUB WR_E2PROM
    ENDIF
    RETURN

    Post Edited (alinious) : 11/23/2005 1:30:04 AM GMT
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 01:32
    Thank you very much Alan,

    With this and a little bit more work ( on my own ) I hope to get an A on my project.

    One last question, when I push the switch to activate an input, I get a big string of numbers, If i use a 1 microfarad cap. will that eliminate that problem.

    I tryed putting in a pause but it isnt very effective.

    Let me know, thanks again!
    Mike
  • aliniousalinious Posts: 51
    edited 2005-11-23 01:44
    Mike_1234,

    You are very welcome. One thing to note is to not be afraid to experiment. If a chip or two burns up now and then, it is no big deal. It is from those mistakes that we learn and sometimes even come to a better understanding. Usually, once you see a chip burn, it very rarely happens again (I will double or triple check my wiring and program code before I download to the stamp). My motto is "I learn when I succeed, but I learn more when I fail."

    I believe a 1 (possibly up to 10) microfarad capacitor should help to reduce the switch bounce (may not completely eliminate), but if you are willing to experiment, read up on the BUTTON command. The BUTTON command is a software way of taking care of the switch bounce.

    Take care,

    Alan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."

    Post Edited (alinious) : 11/23/2005 1:56:04 AM GMT
  • SN96SN96 Posts: 318
    edited 2005-11-23 01:49
    I have been messing around with writing to the eeprom with my BS2 but while experimenting, I found data stored on it from a previous example code that I ran. How can I erase the entire eeprom? I did a search on the forms for this information and all I found was how to write to it.

    I did not want to start a new thread sice we were already talking about eeproms here.

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • aliniousalinious Posts: 51
    edited 2005-11-23 01:59
    SN96,

    You can use a FOR...NEXT Loop to WRITE 0's to all the E2PROM Addresses on the BS2. Writing 0's to all the E2PROM Addresses is an effective way of "erasing" the BS2 E2PROM.

    Example,

    FOR Address = 0 to 2047
    WRITE Address, 0
    NEXT

    Alan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."

    Post Edited (alinious) : 11/23/2005 2:06:01 AM GMT
  • SN96SN96 Posts: 318
    edited 2005-11-23 02:09
    Thanks, thats exactly what I did, however I only set the FOR NEXT to count to 7. I know, I know, you can laugh at me...

    Thanks again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • aliniousalinious Posts: 51
    edited 2005-11-23 02:20
    You are quite welcome. If I had a dime for every "silly" mistake I've made, I'd be a rich man.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."
  • mike_1234mike_1234 Posts: 21
    edited 2005-11-23 04:33
    Do i need to erase the entire memory area after i download my data back to the pc.... this is to ensure when i put the stamp back out into the field that i dont have any kurupt data.

    So then I would just load in that little loop and let it do its thing.

    right?
  • aliniousalinious Posts: 51
    edited 2005-11-23 15:12
    mike_1234,

    Yes, I would erase the E2PROM slot you are using if I was putting the unit back into the field to collect a new set of data. Although, if you start a new data log in the field, the new data will over write the old data, but if you stop the data log, it may not necessarily be at the same ending as the old data. Thus, some of the old data from the previous data log may end up in the new data log. Erasing the entire E2PROM slot before starting a new data log will prevent this from happening.

    You can use the FOR...NEXT loop I posted for SN96, but you would want to add the STORE command within the loop in order to erase the E2PROM slot you are using for your data log.

    Alan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."
Sign In or Register to comment.