7 long unsigned integer math, Long unsigned integer math – High Country Tek DVC80 User Manual

Page 60

Advertising
background image

P/N: 021-00154, Rev. A.6 - updated for V4.7 Tools

Page | 60

To save all of the EE memory, execute this line of code in your application: EECommand = EEWrite. In between
writes you will need to reset the EEcommand to 0. Also, note that the EE memory will only be written to if one
or more of the EE memory variables has changed. So if you insert the EEcommand = EEwrite in your always
bubble or some other frequently executed logic bubble you are very unlikely to exceed the 1 million writes limit
of the memory chips. A typical sequence of code to update EE memory would look like the following:

Dim eememory_update_timer as timer
EEcommand = 0
If (eememory_update_timer = 0s) then
eememory_update_timer = 2s ‘ timer set to > 10ms needed to insure at least one EEcommand = 0
‘ executed between EEcommand = EEwrite commands
EEcommand = EEwrite
End if

To declare an EE memory variable use this line of code: Dim VarName as EEmem
To save all of the EE memory use this command: EECommand = EEWrite

To restore actual EEmemory values to program memory use this line of code: EECommand = EERead
EERead (is rarely used but) would be used if you had changed an EE memory variable in your application but
had not saved it to permanent memory and wished to reset the variable to the permanent EE memory value.

Note: When the DVC5/7/10 powers up the program memory copy of EE memory is automatically initialized to
the values stored in permanent EE memory. Therefore, you do not need to start your program with an EEread
command.

4.7

Long Unsigned Integer Math

All numeric calculations in your application code are executed with 32 bit resolution. Intermediate values are
stored as 32 bit unsigned integers. However, only the lower 16 bits of the numeric result are stored into the
result variable’s memory. This allows for intermediate values to temporally grow larger than 65k to about 4
billion. However, your final result will be restricted to be less than or equal to 65535.

The DVC does only integer math calculations with division resulting in truncation. When you perform division in
a calculation the result will be an integer value with no fractional part or remainder saved. For instance 1 / 2 will
equal 0 rather than 0.5 for any subsequent calculation. Also note that calculations in parentheses will be
performed first. For instance the expression 100*2*(1/2) will equal zero while 100*2*1/2 will equal 100.

Since the DVC does only unsigned math negative numbers are not explicitly saved. So when you wish to
calculate a difference in two variables you will need to write code like:

If (a < b) then
Diff = b-a
Else
Diff = a-b
End if






Advertising
This manual is related to the following products: