
CHAPTER 5 DATA MEMORY
5-5
several things happen. Data saved at line 1000 is
overwritten by the data in line 2000, even though
different write addresses were specified. This brings us
to the second r eason sector size is impor tant.
CAM BASIC forces the requested Flash address down to
an even sector addr ess. In both cases above, data is
written to the Flash starting at address 0, not at 5 or 42.
The easiest way to m ake an even sector address is to
“A ND ” the Flash ad dress w ith &FF80 (as is done in
ARRAY2.BAS program exam ple) when using a 128K
flash or &FF00 with a 512K.
Another consideration is the number of times Flash can
be written to. A tmel specifies anywhere from 1000 to
10,000 or m ore writes. Compared to R AM, this is quite
limiting. Flash should be used to stor e default constants
or data that changes only occasionally.
Writing takes about 90 ms/1000 bytes. During SAVE
time, interrupts (ON COM$, ON KEYPAD, ON BIT,
etc.. ) are rec ognized but not serviced. If these
comm ands must be serviced quicker , w rite data in
smaller blocks.
Using LOAD to transfer data
The LOAD comm and can be used to transfer data from
Flash to RAM or RAM to RAM. Use SAVE to transfer
from RAM to Flash.
LOAD transfers up to 64K blocks of memory at a time.
Use it to transfer an entire data structure containing
recipes, formulas, constants, etc.
The sample program ARRAY3. BAS shows how to move
data from extended memory RAM into CAMBASIC and
back.
INSTALLING 512K RAM
A 512K RAM (part num ber 103 9) can be installe d in
U2. The addition al RAM allows you to increase data
storage, not program size.
Follow these steps to install RAM.
1. Turn off power to the board.
2. Remove existing IC from U 2.
3. Install the 512K RAM . M ake sure pin 1 is
oriented towards the board edge. Pin 1 will be
marked with a dot or notch on top.
4. Move jumper W2[1-2] to [2-3].
You are now ready to power up the board. You can
now PEE K and POKE data into segments 1-7.
CORRUPTED VARIABLES
When your application must r ely on the acc uracy o f data
after power up, corrupted variables become a possibility.
The nature of RAM is it is easily written to. Any
POKE' d data is susceptib le to corr uption. This is
especially true when the board is powered down. U26
monitors the supply voltage and turn s off wr iting when it
is below about 4.65 volts. However, when POKE ing
long data, such as strings and floating point numbers, or
writing to Flash, a power down could interrupt a saving
process. The result is information is corrupted. A
scenario is explained below.
A program is running and saving data. During this time
a reset occurs. A reset can occur due to power loss,
someone pushing the reset button, or a watchdog timer
time out. The data is c orru pted because the com plete
value was not saved.
Since it is impossible to predict or delay a reset, a work
around is to duplicate or triplicate values. That is, you
would have to save the same information in two or three
different places. Usually you only need to save the
pointers to data structures.
When you are w riting ar rays of data (such as show n in
LOG GER .BAS), the sequence your pr ogram should
follow is this: Write data to RAM. Update the pointer.
This pointer could be in duplicate or triplicate. This
way, you only loose one set of data.
When you are saving only one set of data, the following
applies.
For purposes of discussion, data variables are called sets
because it can consist of a mixture of variables, strings
and arrays.
On power up, your program would compare values from
one set to the other one or two. If the two (or three)
agreed, then there was no corruption and the program
can reliably use the values. In practice, you would read
information from set 1, but would save data to all two or
three.
The use of duplicate or triplicate sets depends upon what
the system must or can do if data is corrupted. When
using a duplicate set, a corrupted set indicates that
Commentaires sur ces manuels