Please enable JavaScript to view this site.

MaxxECU Documentation

time.now() - Returns the number of milliseconds elapsed since ECU startup (system tick) as an integer.

 

The value wraps around at 2^32 ms (approximately 49.7 days). To measure elapsed time correctly across wrap-around, always use time.since() rather than subtracting timestamps manually.

Lua code:

local start = time.now()

 

time.since(timestamp) - Returns the number of milliseconds that have passed since "timestamp".

Parameter: "timestamp" (integer): A value previously returned by time.now().

Returns: elapsed milliseconds (integer).

Uses unsigned 32-bit subtraction internally, so it handles wrap-around correctly as long as the interval is under ~24.8 days.

Lua code:

local start = time.now()

-- ... do work ...

local elapsed = time.since(start)

print("Took " .. elapsed .. " ms")

 

time.delay(ms) - Pauses the script for approximately "ms" milliseconds, yielding control to the ECU during the wait.

This is the preferred way to control loop timing and is equivalent to a yield-based busy wait.

Parameter: "ms" (integer): Duration in milliseconds

Lua code:

-- Run at approximately 20 Hz

while true do

   -- do work

   time.delay(50)

end

 

yield() - Yields execution to the ECU scheduler without any delay.

The script resumes as soon as the scheduler returns to it.

Use yield() in tight loops where you want maximum speed but still need to share CPU time. Use time.delay() when you want to control how often the loop runs.

Lua code:

while true do

   -- process all pending CAN frames as fast as possible

   while can.count() > 0 do

       local frame = can.recv()

       -- handle frame

   end

   yield()

end

 

 

For more information about the MaxxECU user scripts, see User Scripts (LUA), or directly reference the LUA api reference and LUA examples. For more all available LUA settings and options, see Script Code, Script Input Control, Output Functions and Script RT values.