still trying to store data to eeprom
mike_1234
Posts: 21
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
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
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.
Here is what I found wrong with your code at a glance:
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
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
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
thanks for the code... i understand now...
if i wanted to start at 0 and go right to 15 how would i do that?
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
like storing the numbers 0 - 15
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
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
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
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
I did not want to start a new thread sice we were already talking about eeproms here.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
·
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
Thanks again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I learn when I succeed, but I learn more when I fail."
So then I would just load in that little loop and let it do its thing.
right?
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."