Start Back Next End
  
ZBasic System Library
143
ZBasic Microcontrollers
GetElapsedMicroTime
Type
Function returning UnsignedLong
Invocation
GetElapsedMicroTime(timeBuf)
GetElapsedMicroTime(timeBuf, timeBuf2)
Parameter
Method
Type
Description
timeBuf
ByRef
Microtime_t structure or array of Byte
The earlier time data.
timeBuf2
ByRef
Microtime_t structure or array of Byte
The later time data.
Discussion
This function is useful for implementing higher precision timing than can be obtained using
Register.RTCTick.  It calculates the elapsed time between an earlier instant in time (as captured by
GetMicroTime()) and a later instant in time.  If the second parameter is not provided, the later instant is
represented by the RTC time data at the time of the call.
The pre-defined structure, Microtime_t, can be incorporated in your application using the directive
Option Include Microtime_t.  Using this structure instead of an array of bytes is preferable not
least because it automatically adapts if you change the target device.
The return value has units of the period of the frequency at which the TCNT register of the RTC timer
changes, i.e. 1/F_RTC_TIMER (typically about 4.34uS for ZX devices).  The value of
Register.RTCTimerFrequency may be useful for converting the return value to seconds.
The array must contain at least 5 bytes (6 bytes for xmega devices), populated by a previous call to
GetMicroTime().  The return value will range from 0 to the equivalent of about 15,000 seconds.  A
return value of &HFFFFFFFF indicates that an overflow has occurred, i.e. an elapsed time that is too
large to represent.
Although this function does not take into account the value of the “day” counter of the RTC, it does
properly handle an elapsed time that spans one midnight rollover.
Example
Dim t0(1 to 5) as Byte  ' must be 6 bytes for xmega devices
Call GetMicroTime(t0)
<other code>
Dim delta as UnsignedLong
delta = GetElapsedMicroTime(t0)
Compatibility
This function is not available on ZX models that are based on the ATmega32 processor (e.g. the ZX-24)
nor is it available if the RTC is not enabled in your application.  Moreover, it is not available in BasicX
compatibility mode.  
See Also
Previous page Top Next page