Timing the flashes, Act 2

Since our last post on Monday, Vlaya and I have been writing code to trigger flashes when the Phyllo is at precise angular positions.

Flashing via SPI

As mentioned here, to flash the LEDs we need to send a SPI frame “FLASH” from the main board to all the led-driving PCBs signaling them to turn their LEDs on right now and for how long.

Checking the timings

On top of sending a SPI frame, we also set the Timer channel we use to trigger the flashes in output mode “Toggle”. Using a Saleae Logic analyzer to  monitor all these outputs allows us to export the precise timings of both the moment the Timer channel is toggled and the moment the SPI frame is sent. We then process the exported file into a python script Vlaya wrote in order measure different latencies and jitters.

Results so far

Here’s what we measured:

  • We used the timing of the Timer toggle to verify that they were always off by less than 1 timer tick. The small jitter which results from this is tiny enough to be negligible.
  • We measured the latency between the time at which the Timer toggles and when the  “FLASH” SPI frame is actually sent. The worst case variation of that latency is around 80µs.

Given the rotation speeds we aim for (up to at least 20 RPS), this variation in latency (it’s not the latency itself the problem, if it were constant there would be no jitter at all) would lead to an angular jitter that would become noticeable at higher speeds, but would probably still be acceptable. However, we need to keep in mind that we have 3 SPI buses and only tested sending on one so far. The latency variation could then presumably be thrice as big.

Next steps

The 80µs latency jitter is probably caused by other interrupts taking priority over the interrupt in which the SPI frame is sent. The actual latencies we measured were sometimes as short as 13µs, and as long as 93µs.

A good solution would be to use the Timer channel to trigger a Direct Memory Access request instead of an interrupt. The DMA would then write the data to be sent directly to the TX buffer in the SPI peripheral, completely bypassing the processor and accompanying interruption-caused jitter.

Using the DMA multiplexer on the STM32H743, it seems like we should be able to use the same DMA request line to trigger 3 DMA requests (one for each SPI bus). We still need to investigate this.

We’ll keep you posted 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *