Extra data storage for 40X

grosey

New Member
Hi guys,

Im working on a project using an LCD to control my sound system. As part of this, it uses the eeprom command to store the visual text that needs to be displayed. However, I have found that there is not enough memory within the chip, and I need a few extra bytes which i cannot squeeze out! Is it possible for me to use some of the availiable program memory as storage space? I also need to be able to change it on the fly, ie- change the value of the stored value while the program is running.

Cheers guys,
 

Andrew Cowan

Senior Member
No - you can't use eeprom as program space. maybe upgrade to a 40X1 (or a 40X2 in march?)

Eeprom can be used to change a value of a stored value while the program is running.

I shouldn't be too hard to make a long program shorter - can you use some 'letpins' commands? Subroutines?

However you can use external eeprom to store values
(not program, on the 40X)

A
 
Last edited:

BeanieBots

Moderator
Maybe you should explain in a little more detail.
For a start, my understanding of your question is the OPPOSITE of the way Andrew has replied.
Also, you say you need to change the value from the program.
That means the values are actually within the program already and having them ALSO stored within EEPROM simply uses up program space for no particular reason. For text, that would be very memory wasteful. For numbers, why does it need to be stored?

Maybe post your code so far. It's almost certain that it's size can be reduced without effecting performance or functionality.
 

inglewoodpete

Senior Member
Have a look at the Table and ReadTable commands for 28x1 and 40x1. You can put data/text in spare program flash memory, as long as its stored at download time.

Edit: Whoops! I see you're using a 40X, not a 40x1. If you just need data storage for strings, which is how I read your post, then you will probably find the 40x1 as the best solution - since it is normally a pin-for-pin drop in replacement. The Table command gives you an additional 256 bytes of storage.

Incidentally, I used a 40x1 for my Home Theatre controller (I believe they call them 'receivers' for some obscure reason).
 
Last edited:

hippy

Ex-Staff (retired)
Using Eeprom to store text to display, and needing it to be updated, is not the best approach. Using SFR (Peek/Poke) or the Scratchpad (Get/Put) would probably be more appropriate.
 

westaust55

Moderator
Im working on a project using an LCD to control my sound system.
Tounge in cheek, would like to see an LCD module used to control a sound system. Character recognition inbuilt to the stereo?



I need a few extra bytes which i cannot squeeze out! Is it possible for me to use some of the availiable program memory as storage space? I also need to be able to change it on the fly, ie- change the value of the stored value while the program is running.

EEPROM has a limited life. Namely about 100,000 write operations to each location (but an infinite number of reads can be done to each location).
RAM would be better option.

Small i2c and SPI RAM chips are available but for larger storage you would need to look at F-RAM. Some SPI serial RAM do get up to 256 kbits = 32 kBytes.
Both typs cost a lot more than EEPROM per byte of storage but certainly very do-able.


A bit more information about your project might be good.

Do you have a DS1307 (or DS1338) real time clock already? These have 56 bytes of RAM that can be used.

Do you need the memory to hold the data when the power is removed? ie need NV RAM.
 
Last edited:

donrecardo

Senior Member

EEPROM has a limited life. Namely about 100,000 write operations to each location (but an infinite number of reads can be done to each location).
RAM would be better option.


Hi
Please dont get the wrong idea and think I am picking faults with your answer , but I was only just a few moments ago looking at EEPROM chips on Rapid .
In particular the 24LC02B which is just a small 2K chip.
I need to measure and display how far my model loco has travelled . That part I have ( with the help of yourself and others) now got sorted out. I planned not only to display the distance on LCD but each time it changed to also store it in EEPROM , so next time I run the train it will retrieve the last saved value and carry on from there rather than starting the count from zero each time the train goes out on a run .
I plan to measure in 1/1000ths of a mile increments so if as you say I can only expect to make 100,000 writes to the chip then after 100 miles the chip may be failing , and thats only 400 laps of the track .
According to Microchips data sheet for the 24LC02B it says ...

• 1,000,000 E/W cycles ensured

Now that would give me 4000 laps which would just about wear the wheels out so would do fine .
So is it 100,000 or 1,000,000
or maybe there is a better way to store the running total than using EEPROM at each data change . I had thought of having a push button to store the total once at the end of the day but with my memory I would forget to push the switch before turning off the power to the train

Don
 

westaust55

Moderator
Yes, you are correct, missing a zero.

PIC (PICAXE) and 24LCxxx series EEPROMS have
"1,000,000 write EEPROM endurance"

Question remains:
Do you need the memory to hold the data when the power is removed?

How much memory do you need?

If back-up is not required on power down (depends how your PICAXE 40X is powered here) and only need around 40 bytes then look at hippys suggestion in post 6

If more memory or NV memory required then external EEPROM or RAM will be required.

If you are happy with the 1,000,000 write life then EEPROM will suffice.
 
Last edited:

Dippy

Moderator
And with a little bit of thought you can write to different bits of memory to extend it even further - alluded to by Westaust, but I'm just stressing it.
 

BeanieBots

Moderator
or maybe there is a better way to store the running total than using EEPROM at each data change . I had thought of having a push button to store the total once at the end of the day but with my memory I would forget to push the switch before turning off the power to the train
Got a spare input?
Use it to detect power off, then save to EEPROM only when required.
 

hippy

Ex-Staff (retired)
To use Eeprom for frequent logging it is often possible to only log every 'N' times and accept that there will be some loss of accuracy over time. Depending on how long a run is ( before being powered down ) and the normal number of events to log during that time, N can often be quite large without any significant error arising.

You could use this method, plus a "store" button at the end of the day so it will always be accurate, and if you forget to press the button it will still be quite accurate.
 

donrecardo

Senior Member
Question remains:
Do you need the memory to hold the data when the power is removed?

How much memory do you need?

If back-up is not required on power down (depends how your PICAXE 40X is powered here) and only need around 40 bytes then look at hippys suggestion in post 6

If more memory or NV memory required then external EEPROM or RAM will be required.

If you are happy with the 1,000,000 write life then EEPROM will suffice.
Hi,
thanks for the clarification on the eeprom write life .

On the question of how much memory I need , I actually need to store very little. Infact just one 6 figure number. That number will change (increment by 1) at maybe once a second, and each time it changes I need to save the changed number . The previous number won't be needed any more, so its ok to keep writing the number to the same location. The important thing is I need to keep that number safe even when all power is removed, so that next time I power up I can resume counting from the previous days total

I thought at first that perhaps I could store it in the internal eeprom of the 40X1 but am not sure if will it get erased each time I power up. More importantly, even if this would work , knowing there is a limit to the number of times I can write to a chip , it might be cheaper to wear out a 30p eeprom chip than a 40X1

Don
 

donrecardo

Senior Member
Got a spare input?
Use it to detect power off, then save to EEPROM only when required.
I like the sound of this but it has me puzzled, if it has detected power is off , then where would it get power from for doing the save ?
The locomotive, who's distance travelled it is measuring runs on two car type batteries ( heavy !! ) , and to transport it to and from the track the batteries have to be removed to reduce the weight , so when I say I need to save the data before powering off I dont mean before switching off the drive motor , I mean completely removing the source of power from the loco. So once this is removed , where will it get the power to make a save ?

Also , just incase a fault occurs in the drive system then a circuit breaker drops out isolating the batteries from the circuit , so again there would be no power to make the save.
I suppose ideally what I need is a circuit with its own small battery that could cut in when it detects loss of main circuit power and that would stay on long enough to complete the save routine . unfortunately I dont know how to make such a circuit

Don
 

BeanieBots

Moderator
Simple, honest.
The PICAXE and whatever else, (maybe LCD screen) use very little power.
I'd also guess that you run 12v into a 7805 (or similar) regulator?

Put a diode between 12v and regulator input.
Put a large cap on regulator input.
Potential divider on power side of diode into PICAXE.
When the power in goes off, the potential divider input will drop instantly.
The cap will keep the regulator going for several seconds, far more than needed to save the data.

1000uF will drop 1v in 1S for a 1mA load. Scale accordingly.
The regulator won't droop until about 7v.
 

donrecardo

Senior Member
Simple, honest.
The PICAXE and whatever else, (maybe LCD screen) use very little power.
I'd also guess that you run 12v into a 7805 (or similar) regulator?

Put a diode between 12v and regulator input.
Put a large cap on regulator input.
Potential divider on power side of diode into PICAXE.
When the power in goes off, the potential divider input will drop instantly.
The cap will keep the regulator going for several seconds, far more than needed to save the data.

1000uF will drop 1v in 1S for a 1mA load. Scale accordingly.
The regulator won't droop until about 7v.
That sounds ideal . I am not sure if I understood your circuit properly or not . I have drawn out what I think you were telling me . If you have a second would you take a look and see if its what you were meaning
I put it here but will remove it once you have checked it out
( ignore the name of the file , it was easier to overwrite another that was allready there)

http://donrecardo.pwp.blueyonder.co.uk/base+bearings.jpg

Don
 

BeanieBots

Moderator
That's spot on.
Do you know how much current your PICAXE circuit uses?
You might get away with a smaller cap, but you might need a larger one.
 

westaust55

Moderator
erasing PICAXE EEPROM

Hi,
thanks for the clarification on the eeprom write life .


I thought at first that perhaps I could store it in the internal eeprom of the 40X1 but am not sure if will it get erased each time I power up.
The PICAXE EEPROM is not erased when the power is removed.

PICAXE EEPROM is only erased when the program or a new program is downloaded from the PC to the PICAXE.
 

donrecardo

Senior Member
That's spot on.
Do you know how much current your PICAXE circuit uses?
You might get away with a smaller cap, but you might need a larger one.
I just measured the current and it varies because the picaxe is connected to an axe033 which has the option of the 1 Hz led fitted so while the led is on the circuit shows its drawing 10.5ma and with the led off its 4.7ma. I thought it would have been much higher than that.

Here is another question for you. Normally any circuit for a 7805 regulator includes a small capacitor on both the input and output side of the regulator often around 100nF.
Should I still have these two smaller caps installed , as well as the 1000uF

Also , the two car batteries are driving the 4 X 150W motors which propel the loco. I would guess they produce electrical noise which may or may not be smoothed out by the car batteries behaving as large capacitors, but my worry is that the input to my picaxe, which will trigger that power has been shut down is connected to the potential divider which is on the other side of the diode ( on the battery side) . Should I have more filter caps on that side of the circuit, perhaps between ground and the picaxe input pin ? and if so what sort of value cap?

Regards
Don
 

donrecardo

Senior Member
The PICAXE EEPROM is not erased when the power is removed.

PICAXE EEPROM is only erased when the program or a new program is downloaded from the PC to the PICAXE.
So for the small amount of data I need to store there would be plenty of room in the picaxe eeprom.

I just had a play and wrote the number 7 to eeprom address 0.
I read it back and it was there as expected , I then removed the power supply
then put it back and just as you said the data was still there. So far so good.

Now my data will be in a variable , lets call it B0. the variable will keep incrementing by one each time the loco travels another 1/100th of a mile , so on detecting that the power supply has failed I need to write the contents of the variable to eeprom as a number , so just to try it out I wrote ....
Code:
for b0 = 1 to 9
eeprom 0,(#b0)
next b0
but that gives a syntax error . It doesn't seem to want to write the contents of a variable.
How will I get around this ?

Don
 

BeanieBots

Moderator
Just write the actual number, not the number converted to ASCII for displaying.

Write address,b0 '(not #b0)

EEPROM is only for loading data at program download time.
 

donrecardo

Senior Member
Just write the actual number, not the number converted to ASCII for displaying.

Write address,b0 '(not #b0)

EEPROM is only for loading data at program download time.
I had forgotten all about the write command. I had read about it in the manual but I never had reason to write data to memory before so I never got to use it but I just tried it now and it works fine

Thanks Beanie

Don
 
Top