Data Sheet

dScript
dScript User Manual v2.15
Non-volatile variables
Some modules have an EEPROM for storing a small number of variables when power is
switched off. The dS1242 & dS3484 have a 512 byte EEPROM on board.
Either string or var variables can be located in this non-volatile memory. To declare a non-
volatile var use eevar, eeint16 or eeint8. For example:
eevar HourCounter
To declare a 4 byte array for emulating latching relays use eeint8
eeint8 RelayStore[4]
Only variables and strings can be stored in non-volatile memory, I/O ports and other objects
cannot.
When you read or write to a non-volatile variable, you are really reading and writing to a cache
memory. The underlying EEPROM is only written when something actually changes. This means
you can update your variables as often as you like with the same value. For instance to update
"RelayStore" with the status of Relay1 you could put the following in a loop.
if(Rly1) then RelayStore[0] = 1 else RelayStore[0] = 0 endif
The loop may be executed as fast as you wish, only a change in the state of RelayStore[0] will
get written to the EEPROM. As EEPROMs have a limited write endurance, this prevents
unnecessary wear.
A simple and eloquent method to update RelayStore is to give it its own thread.
eeint8 RelayStore[2]
thread RelayUpdate 50
RelayUpdate:
if(Rly1) then RelayStore[0] = 1 else RelayStore[0] = 0 endif
if(Rly2) then RelayStore[1] = 1 else RelayStore[1] = 0 endif
threadsuspend
main: if(RelayStore[0]) then Rly1 = 1 else Rly1 = 0 endif
if(RelayStore[1]) then Rly2 = 1 else Rly2 = 0 endif
threadstart RelayUpdate
do
... Do things ...
loop
In the start up section of main: there are a couple of lines of code to initialise the relays with
their stored settings. The RelayUpdate thread is then started which will keep the relays
updated every 50mS.
Take care when making variables non-volatile. EEPROMs have a limited write endurance of
about 1000000 (1 million) and if you change the values too frequently you can quickly reach
the end of their life. dScript can write a new EEPROM value every 320mS. If you do so you will
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
15