Datasheet
Chapter 3: EEPROM Tricks and Program Tips · Page 133
' qtiThreshold VAR Word ' Stores black/white threshold
temp VAR Word ' <--- New temporary variable
multi VAR Word ' <--- New multipurpose variable
As mentioned earlier, a variable doesn't have to store the QTI decay black/white
threshold value because it doesn't change after it is set at the beginning of the program.
This makes it a prime candidate for EEPROM storage. We can use a
DATA directive to
set aside a word-size variable to hold this threshold value.
√ Add this
DATA directive to give this EEPROM address the Symbol name
QtiThresh.
' -----[ EEPROM Data ]-------------------------------------------------
QtiThresh DATA Word 0 ' Word for QTI threshold time
Even though the DATA directive writes a 0 to this EEPROM location when the program is
downloaded, a
WRITE command can change this value after the program starts running.
Any value that is stored in EEPROM will remain there even if the power is disconnected
from the SumoBot. The only things that can change that value are another
WRITE
command, or a download with a
DATA directive that overwrites it.
All commands in the Calibrate_Qtis subroutine that involve the qtiLeft, qtiRight,
or
qtiThreshold variables can be replaced with commands that use temp and multi.
Each command that got replaced was commented, with an apostrophe
' placed to the left
of it. Each command that was added has a comment to the right with either
' <--- Add
or
' <--- New. Notice that multi and temp are also used to calculate the threshold
time. Notice also that the threshold value is then copied from the
multi variable to the
byte at the
QtiThresh address in EEPROM.
√ Go through and examine each commented command and its replacement in this
entire subroutine.
' -----[ Subroutine - Calibrate_Qtis ]---------------------------------
Calibrate_Qtis:
HIGH qtiPwrLeft ' Turn left QTI on
HIGH qtiSigLeft ' Discharge capacitor
PAUSE 1
' RCTIME qtiSigLeft, 1, qtiLeft ' Measure charge time