EEPROM status and retrieving data

marcos.placona

Senior Member
Hi, I've been playing around with a 08M's eeprom, and although everything works on my sample code, I've been trying to insert data into my eeprom dynamically (i.e. the picaxe reads from an infra red source and stores some data)

I read from the documentation that by simply using eeprom ("a_number"), it will store this data from where it was left off.

This all sounds good, but I wonder if there's any way to know where exactly on the eeprom I'm writing data.

Also, I would like to know if it's possible to detect when the eeprom is full, so I don't keep writing to it.

What I want to accomplish is:

I have a servo motor hooked to the picaxe, and an infrared sensor capturing data from a remote control.

On each key of the remote control, it will give the coordinates to my servo. i.e. 1 goes to position 75, 2 goes to position 125, 3 goes to position 225 and so on

What I would like to do, as store this infrared commands into the eeprom, and be able to repeat once all the information is stored into it, so I could run a procedure like:

1(left==75),2(middle==125),1(left==75),3(right==225),1(left==75).

Click 5 for example, which would trigger a "store" sub, that would store all that positions into the eeprom, and then run the stored procedure automatically.

I reckon that to be able to do this, I will need to know how many movements have been stored, as well as how many movements are still left to store.

Thanks in advance for any help,
 

hippy

Ex-Staff (retired)
The EEPROM command pre-loads Eeprom Data prior to download, presumably you are using WRITE to update it ?

The compiler will indicate if you attempt to pre-load more Eeprom space than there is for EEPROM commands. For tracking WRITE's you need to keep track of where and how much is written. How much more can be stored is how much Eeprom there is less how much has been used.
 

marcos.placona

Senior Member
Excellent, this is what I was expecting, and yes, I'm using write to update it. one thing I'm not sure about, is how to delimit the values from the eeprom, i.e.:

When passing:

1(left==75),2(middle==125),1(left==75),3(right==22 5),1(left==75).

I'll be storing the servo positions to my eeprom. When I want to then read it back, I'll loop through the number of data stored using read to read from the eeprom, and would like to use it directly with my servopos command.

When storing data on the eeprom, can I use a delimiter for example, so i know the data is separated by a "," for example, therefore everything before the comma is the number I want to use?

I'm sure I'm completely wrong with my approach, but i can't find enough documentation on it.

Cheers
 

hippy

Ex-Staff (retired)
You don't need any delimiters. Think of Eeprom as a chest of drawers, each drawer numbered; whatever data is stored in a drawer can be retrieved from that drawer so ...

WRITE 3, 29 would store the number in drawer 3

READ 3, b0 would retrieve the number stored in drawer 3, b0 would be set to 29.
 

marcos.placona

Senior Member
You don't need any delimiters. Think of Eeprom as a chest of drawers, each drawer numbered; whatever data is stored in a drawer can be retrieved from that drawer so ...

WRITE 3, 29 would store the number in drawer 3

READ 3, b0 would retrieve the number stored in drawer 3, b0 would be set to 29.
Thanks Hippy, that's one of the best explanations I've ever seen on this forum. Don't mean to be unfair with the others or anything, but you example was simply spot on, and I could visualize it.

I'm all sorted now. I'm gonna start moving it all to an 18x + i2c eeprom. As far as I'm aware, it should all still work the same way, but writing stuff to the external chip is that correct?

Does the "chest of drawers" idea also apply to external I2C eeproms?

Thanks again
 

hippy

Ex-Staff (retired)
Yes, externally it's just a bigger set of drawers with a slightly different syntax...

I2CSLAVE - Indicate which set of drawers and how they are accessed

I2CWRITE <drawerNumber>, ( <dataToStore>)

I2CREAD <drawerNumber>, ( <variableToReadDataInto> )
 

lanternfish

Senior Member
Hi Marcos

Hippy's explanations of the simpler and not simpler aspects of PICAXE programming and hardware interfacing make life so much easier for many of us here.

Once you have mastered the 'drawer' concept and have eveything working well, you may consider this:

As you seem to be only using the numbers 1, 2, and 3, and these numbers are, respectively, 00000001, 00000010 and 00000011 in binary, with a bit of code trickery you can compress your input data by a factor of 4, increasing your storage by a factor of 4.

For example, if your input was 1,2,3,1,3,2,1,3 it would normally be stored (starting at 'drawer 0') as:

Code:
drawer 0    00000001  ; 1
drawer 1    00000010  ; 2
drawer 2    00000011  ; 3
drawer 3    00000001  ; 1
drawer 4    00000011  ; 3
drawer 5    00000010  ; 2
drawer 6    00000001  ; 1
drawer 7    00000011  ; 3

8 bytes
By compressing this you would end up with:

Code:
drawer 0    01 10 11 01    ; 1 2 3 1
drawer 1    11 10 01 11    ; 3 2 1 3

2 bytes
And a 00 reading will indicate an unused 'block'/instruction.

If you are using more positions this would have to be adapted to suit

A bit of work :eek: writing the compression/decompression program. Something for the future, maybe?

Cheers
 
Last edited:

westaust55

Moderator
extrenal i2c EEPROM

When considering external EEPROM’s, please take into consideration the EEPROM internal paging scheme if you will be writing data to the EEPROM as multiple bytes per PICAXE writei2c command.
For example the 24LC256 has a 64 byte page structure ( that is addresses 0 to 63). Writing single bytes of data at a time is never a problem but if writing multiple bytes and you reach the end of a 64 byte page, then the EEPROM internal address pointer rolls over back to the first byte.

By way of example,
say you are going to write 6 PICAXE byte variable s of date stating at address 60

Writei2c 60, (b0, b1, b2, b3, b4, b5, b6)

Var = > EEPROM Loc’n
B0 = > 60
B1 = > 61
B2 = > 62
B3 = > 63
B4 => 00
B5 = > 01
B6 = > 02

But if we start at EEPROM memory location 64, then:
writei2c 64, (b0, b1, b2, b3, b4, b5, b6)

Var = > EEPROM Loc’n
B0 = > 64
B1 = > 65
B2 = > 66
B3 = > 67
B4 => 68
B5 = > 69
B6 = > 70
 
Top