PDA

View Full Version : BS2P-40 - how do you write to external EEPROM????



sabrekittie
06-11-2005, 04:55 AM
http://forums.parallax.com/images/smilies/confused.gif·· Ok - we are working with a BS2P40 to program our hot tub.· The one thing we have not been able to find any references to is how to write information and retrieve that information to an EXTERNAL EEPROM.

We are using the heck out of SPRAM and the internal EEPROM space..... But we want to be able to store data on an external EEPROM for retrieval after power failure, or to store data when the system makes a change.·

In case you are wondering we are programming a hot tub - pump speed, blower on/off, temp control etc.· (Thanks for the previous help on the clock problem).

Any references we can access or help would be greatly appreciated.

Newzed
06-11-2005, 05:05 AM
All EEPROMs have diifferent commands, and they all use shiftin and shiftout commands. except the I2C versions.· Take a look at my AT45DB041 EEPROM;

http://hometown.aol.com/newzed/page4.html

Sid

sabrekittie
06-11-2005, 05:26 AM
Ok - for clarification we have the Xicor X25640 8kB EEProm.
We have tried running the demo program and it will "appear" to write and retrieve the info... however, we have been unable to get it to write and read to multiple addresses, multiple pieces of information.

i.e. - store current temp at addressa
then read same info at a later time to update temp

store time/temp of last pump cycle for which the stamp will read every so often to know when to run pump cycle again... i.e. two hours later.

We know we are over thinking a lot of this but you have to start somewhere.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Newzed
06-11-2005, 05:35 AM
There is a limit on what you can write to any EEPROM with a Stamp.· Each byte that is written must be a variable, and you soon run out of variables.· You might take a look at the BS2pe - it has eight banks of 2048 bytes each for EEPROM storage.· I use the pe to store all the data from my RFID inventory program, and the data is non-volatile.· It can be read back at any time.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Need a bezel for your LCD?

Newzed@aol.com (mailto:Newzed@aol.com)
·

Chris Savage
06-11-2005, 06:08 AM
Sid,

·· I'm not sure your statement is entirely accurate...If I read that correctly, it implies that you can't write to more locations that you have bytes of RAM available, and that's not the case at all.· You can write to the entire EEPROM space using the same variable.

·· Now, if you're writing the time, date, temp, etc.· Each of those will be a variable which you can write, but you can write new data from those variables into new locations in EEPROM at will.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Jon Williams
06-11-2005, 06:09 AM
Even the BS2p has eight banks and with the STORE instruction you can read and write across them -- if your main code fits into bank one this leaves you with a 14K block of EE that's as easy to get to as READ and WRITE. The help file shows how.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

sabrekittie
06-11-2005, 06:21 AM
We will actually have programming running on the BS2P40 that has sub routines for items that will be running independantly per the programming - pump cycling - 2 hrs at a time 4 times a day and automatic temperature adjustment to be sure the tub does not drop below 50 degrees (nothing worse than a frozen hot tub). Routines to set the temperature, turn heating element 1 or 2 on or off according to the temperature requirements, switching pump on/off - hi/lo, turning blower on/off, and programming to adjust date and time as needed.

Right now the internal eeprom (1 bank) is 51% full. He is using SPRAM to switch and connect between functions. We are afraid with all the variables we are using and information being pulled from the clock, temperature module, and the 3 touch sensors that we use to make adjustments (using LCD as a display). That we will run out of internal eeprom space to accomodate all the info we want to track, as well as have room to run the programs.

We want to be able to set information on the external eeprom as a default every 24 hours. So that at (i.e.) midnight it reads the temp, time, pump cycle status, etc and writes it to the external in case of a power failure. So that when power comes back up the first thing the chip will do is check for the default settings on the eeprom and reset from there.

I guess one important factor is this is sort of a trial run on setting programming and what we learn here will ultimately be used in setting and programming staging systems for a very large two stage model rockets (www.maxiomega.com).

Eventually on top of all the functional processes for the tub we want to add control programming for lighting and music (I know we dream big).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Newzed
06-11-2005, 06:22 AM
Chris, what I tried to say that each byte of data you store has to be a variable.· If you have 30 different bytes of data, all different, ·then you can't store them all because you don't have that many variables.· The most you could possibly store is 26.

Sid

.

Orion
06-11-2005, 06:48 AM
You can store more than that, you just can't "work" with more than 26 bytes at a time.

example

read 10 words of temp,digital I/O data
write the 10 words to epprom
read next 10
write ....
loop till your hearts content.

Newzed
06-11-2005, 06:57 AM
Suppose you have 20 bytes of data coming from an external source and that you get a packet every five minutes.· You can store the 20 byte packets one after the other until you run out of EEPROM, but you will never be able to store and recall more than 20 bytes of data.· I'm assuming the program itself takes four bytes - com, ix, packet number and channel number.· I've been this route and in one of my programs I am limited to 17 bytes of data because the program requires nine bytes for its own use.

Sid

Orion
06-11-2005, 07:08 AM
I see. I thought the stamp was in control of all the I/O, not reading a long serial stream from an external source.· You could still use the scratchpad on the bs2p to get up to 128 bytes.

Newzed
06-11-2005, 07:14 AM
From the way she described the problem, I assume all the data like temp, rpm, etc. was coming from an external sensor, probably fed into an ADC.· The time could be generated locally and if she used only hours and minutes that would only take two byte.· If she wants date then that is two more.· Temp would take one byte, rpm two bytes - already I'm up to 7 bytes and I think she had a lot more data she wanted to store.

Sid

Orion
06-11-2005, 09:10 AM
If the stamp is in control of it all, it’s not a problem….too a degree, ie. no more program space.· I have one bs2pe controlling 8 (8 bit analog channels) and 16 digital inputs 16 digital outs.· These are mainly setup with independent settings, total of 80 bytes of settings. ·All of the inputs get logged to a AT45DB045 with timestamp hr:mins day:month (every minute = pretty graph).· This is only the start of this project.· Many more will be added and, biggest problem as I see it will be filling all 8 banks of program space.· Here a quick generic breakdown of how I pull it off:
·
I use Jon’s examples of “task manager” programming from the nuts and volts columns to break my program’s tasks among a few banks of memory.·
·
Bank0: “Main”
·
·This bank inits all the hardware and controls the flow of the total program.·
·
In my case it fires up a rtc ds1302, inits 2x MCP23016, inits 2x PCF8591, sets all the outputs to off on 2x 75hc595, reads last settings from external eeprom and loads them into scratchpad, one time on power up.· After this it’s in it main loop “branch”ing out to the other tasks.· Current order: getting inputs, control sequences, setting outputs.· Once a minute it branches to the logging bank.· This bank also checks the status of the siteplayer between tasks for changes in the settings, if so then it moves to bank 3 and pulls from siteplayer and pushes the settings to scratchpad.
·
Bank1: “Get I/O”
·
Reads all the inputs and outputs, pushes them to scratchpad. How??· Read the mcp23016 push to scratchpad, switch I2C address repeat, and REUSEING the variables.· Move on to the PCF8591 and ditto. This bank also runs after the next bank to set the outputs.
·
Bank2: “Control Sequences”
·
This bank loads in a handful of settings/inputs from scratchpad and process them, then loads a second batch, processes…..repeat till finished, REUSEING variables as much as possible.
·
Bank3: “Logging”
·
Handles logging the data from the I/O.· All the current inputs and outputs are contiguous in the scratchpad memory, with the time and date right after.· This bank just moves it from the scratchpad to the eeprom and keeps track of where it’s at, which is stored on the RAM of the ds1302.· One other task of this bank is to push I/O points to a siteplayer.· The RAM portion of both the ds1302 and AT45DB045 have battery backup, so no biggie if power is lost or damaging eeprom memory with frequent updates.
·
Bank4: “Diagnostics”
·
This bank does some simple checks to see that all the hardware is alive.· It runs after the initial power up past all the hardware setups.· It basically checks that the RTC is counting time and that the registers of the I/O chips are what they should be.
·
·
I still have 3 banks not is use yet.· Granted my scratchpad is about 90% filled but with another bank (or fit it in 0-4) of program space, it wouldn’t be hard to borrow some techniques from the PC (memory pageing/swaping).· Just page the last 100 bytes of scratch pad to an external RAM, and load in a different 100 bytes.· This has all has some disadvantages of requiring a far deal of code etc, but all of my inputs and outputs don’t need to switch at lighting speeds, once a minute would be fine.· Currently it runs about 2 – 3 times a second, till it logs the data.· The biggest speed issue I have now is waiting for all that data to flow out of the AT45DB041.· Unloading of 4046 pages of 132 bytes takes a few.· A upgrade to the bs2px for a ~3 time speed boost, is in the near future.
·
Hints I can give you for your project.·
·
Check out the NV article on multi-bank programming.· Reuse, reuse, reuse your program variables and load them from the scratchpad.· Everybody will flame me for this (nondescript vars) but, I use variables something like this in all banks.
·
·
' ----[ Variables ]-------------------------------------------------------
·
‘a few variables that many routines the bank will use
RawTime VAR Word···
OutsideTemp VAR Byte
·
‘variables that will be used and reused
WorkByte1 VAR Byte
WorkWord1 VAR Word
WorkWord2 VAR Word
WorkWord3 VAR Word
WorkWord4 VAR Word
WorkWord5 VAR Word
WorkWord6 VAR Word
·
·
To keep my sanity I will put comments over the WorkWordX to tell me what it is in logic statements. A spreadsheet is VERY handy to keep all the memory locations straight.· You could code constants for the GETs, but I prefer spreadsheet over 2 pages of constants. Example
·
·
GET 64,Word WorkWord1···· 'LightsOnTime
GET 66,Word WorkWord2···· 'LightsDuration
GET 68,Word WorkWord3···· 'Lights Offset
·
··········· ················'LightsOnTime· ·····················LightsDuration· + Lights Offset
·IF (Rawtime >= WorkWord1) AND (Rawtime < (WorkWord2+WorkWord3)) THEN
·
The above is just a piece of the full code to stage on/off some lights.· The next control sequence would reload the Work variables with new values and run the next routine.· None of my banks relies on carrying over of variables from one bank to the next. ·They are all loaded from scratchpad, processed, repeat.· A lot of thought needs to go into how you break up your program and gather routines that need the same variables together on the same bank.

Post Edited (Orion) : 6/11/2005 1:15:52 AM GMT