I suspect I'm misusing macros, but I have a NeoPixel ring, and after discovering meta commands and daemon.g I may have gotten carried away
Also I'm trying my hardest to avoid using an SBC if I can.
Fundamentally, I'm trying to keep my NeoPixel control routine to under 500mS to prevent taking control away from the firmware for too long.
Here's a trial I've been running:
daemon.g:
while global.runDaemon
M98 P"statusled/main.g"
G4 P500
statusled/main.g
var time_b = state.upTime + (state.msUpTime / 1000)
while iterations < 1
M98 P"statusled/effects/fade.g" D"I" C{global.STATUSLED_RED}
M98 P"statusled/effects/fade.g" D"O" C{global.STATUSLED_RED}
var time_a = state.upTime + (state.msUpTime / 1000)
var time_d = var.time_a - var.time_b
if var.time_d > 0.5
var str = "Warning: StatusLED took " ^ var.time_d ^ "s (> 0.5s) to run. Check SD read speed!"
M118 P0 S{var.str} L1
fade.g:
var e = global.STATUSLED_STRIP_ID
var s = global.STATUSLED_NUM_LEDS
var d = global.STATUSLED_MAX_BRIGHTNESS / global.STATUSLED_FADE_DURATION
var b = param.D == "O" ? global.STATUSLED_MAX_BRIGHTNESS : 0x0
if param.D == "O"
set var.d = -var.d
while iterations < global.STATUSLED_FADE_DURATION
set var.b = var.b + var.d
M150 E{var.e} P{floor(var.b)} S{var.s} R{param.C[0]} U{param.C[1]} B{param.C[2]} W{param.C[3]} F0
G4 P1
fade.g just adjusts the brightness of the LED's every mS to fade in or out a given colour.
Depending on what I set STATUSLED_FADE_DURATION to, I can easily exceed 500mS, so it's configured at the moment to be very low e.g. 50mS.
This whole routine (all code above) takes around 0.43s to execute.
However, when doing some refactoring, I swapped out the M150 command in fade.g for a macro call called solid.g like so:
solid.g is just an M150 wrapper which updates all LED's to a single colour negating the need to pass the S param to M150.
M98 P"statusled/effects/solid.g" B{floor(var.b)} C{param.C}
This takes 1.19s. I was surprised until I realised the firmware is probably reading this file from SD and executing it on every loop iteration.
I'm using a SanDisk Ultra Class 10 A1 SD card with an advertised read speed of 98MB/s. The speed test gave me:
M122 P104 S1
Testing SD card write speed...
SD write speed for 1.0MByte file was 4.98MBytes/sec
Testing SD card read speed...
SD read speed for 1.0MByte file was 1.81MBytes/sec
From reading the Duet documentation, those speeds are actually pretty good, so I have some questions:
- What limits the Duet in terms of SD card transfer speeds? Hardware?
- Is the read buffer fixed at 512B (i.e. in hardware) or can it be increased in the firmware?
- Is caching of macro's, either after reading from SD, or after parsing a possibility?
- Apart from calling as few macros as possible, doing fancy fade effects etc, is there anything I can do to improve execution speed?
- Should I really be using an SBC for this, and just passing the M150's to the firmware?
As I said at the beginning, I'm aware I'm using macro's in ways in which they were probably not intended, but there's so much potential...
Thanks for your time