SL100: Non-volatile memory
The term non-volatile memory means a form of memory that does not lose its data when the power goes off. It can be implemented using a variety of technologies. Your hard disk drive is non-volatile. The magnetic core memory used in computers in the 60's and 70's was non-volatile. Some systems use a small battery to keep the memory powered up even when main power is off. The technologies commonly used in SPLat boards are known as "EEPROM" and "FLASH" memory.
The board contains two kinds of non-volatile memory: "Permanent" memory and "Shadow" memory. The Permanent memory is the type that has existed in SPLat boards almost from the very beginning. Shadow memory is a much newer development made possible by advances in microcontroller technology.
Permanent memory
This type of non-volatile memory was introduced into SPLat in March 1998. It allows just 13 bytes of RAM (data memory) to be saved into a non-volatile memory as a indivisible (all or nothing) block to be later restored. The two instructions for this are PermStore
and PermRecall
. The data does not survive a new program download.
Shadow memory
This is newer type of non-volatile memory, introduced in March 2002 in language dialect 10. It allows all of RAM to be selectively backed up to a "shadow" memory in blocks of any size, and likewise to be restored in blocks of any size. It also allows the shadow memory to be cleared in blocks, and supports indexed addressing for more sophisticated data management in larger projects.
The term shadow memory comes about because it is a region of non-volatile memory that overlaps the RAM. When a certain RAM location is written to the shadow memory, it is written to the same byte address within the shadow memory as its own RAM address.
The instructions for shadow memory are ShadowWrite, ShadowRead and ShadowClear. All these can be used as indexed as well as non-indexed instructions.
Shadow memory is not affected by downloading a new program to the controller. That means any user setup parameters (for example) will remain unchanged. That represents both an advantage and a risk. If you change your program or we change the way we allocate RAM (defBYTE
etc) you could have problem, because suddenly your parameters are no longer at the expected addresses. You should therefore consider using absolute RAM addresses (mEQU
) to allocate RAM to user parameters.
Comparison between permanent and shadow memory
There are a number of differences between the two types on non-volatile memory:
- Permanent memory can only be written and read all at once, whereas shadow memory can be accessed in any block size.
- Permanent memory has a more robust error checking mechanism. In permanent memory a checksum is written with the data, and if the checksum fails on readback an older version is automatically substituted (with a status signal returned in X). In shadow memory, the data is automatically read back immediately after write, and any error is signalled in the R-register. However, shadow memory has no mechanism for detecting a readback error at a later a time.
- Depending on the specific SPLat model, and the underlying processor and memory technologies, the shadow memory can have significantly less endurance than permanent memory. Endurance is the number of write or erase cycles a memory location can perform before it becomes worn out.
Endurance of non-volatile memories
Certain non-volatile memories have a finite life, as defined by the number of writes or erases (clear cycles) they can endure. For permanent memory this translates to the total number of times a PermStore can be executed before the memory is likely to give erroneous data. For shadow memory it means the number of times any given byte address can be subjected to a ShadowWrite or ShadowClear before it is likely to give errors. You should take great care to not write a program that will write or clear the non-volatile memory so often that it gets worn out too soon.
Example: Say a given non-volatile memory has a stated endurance of 100,000 cycles, and your program counts cans of sardines at a rate of 100 per minute, updating the non-volatile memory after every count. Your board would only last 1000 minutes, or about 2 shifts. If you re-write your program so it only updates the non-volatile memory once per hour, you would get 100,000 hours or about 12 years life, with some loss of accuracy as the trade-off.
CAUTION: You must take into account the possibility of power failing right in the middle of writing to the non-volatile memory. Unless specifically stated for the SPLat product you are using, there is always a possibility that data will be corrupted if that happens. You must therefore ensure, by the design of your system, that there will be no disastrous consequences of corrupted data.
The Permanent Memory has the best protection in this regard. Data is written with a checksum, and the PermRecall instruction provides a result indicator in the R register.
Support in SPLat/PC
Both types of non-volatile memory are supported in SPLat/PC.
The support for permanent memory is documented in the SPLat/PC "classic" help file. In the help file index search for "Permanent memory".
SPLat/PC simulates shadow memory by saving the shadow data in the computer's memory. The data is initialized to all zero's when SPLat/PC is first launched. After that it is affected only by simulated shadow memory instructions. That means you can stop and restart a simulation and the shadow memory data is retained. There is no simulation of an unsuccessful ShadowWrite or ShadowClear.