Skip to content

Latest commit

 

History

History
90 lines (80 loc) · 5.35 KB

0102-2023-06-25.md

File metadata and controls

90 lines (80 loc) · 5.35 KB

25 Jun 2023

Previous journal: Next journal:
0101-2023-06-22.md 0103-2023-06-26.md

Raybox-bridge: What language?

Python on Windows

  • I tried using Python 3.11.4 with Pygame, and even before I got into trying to send data to the Pico-DE0, it was starting to look like Python would be just too slow.
  • However, I might've created problems for myself by:
    1. Using time.monotonic_ns(); it seems time.perf_counter_ns() might be better for my needs.
    2. Running this from within VSCode.
  • For whatever reason, VSCode slows it down, maybe because of the Integrated Terminal's performance.
  • I found that tweaking a bit and running from a Windows Terminal met the target performance. The outer loop goes thru an average of ~3500 iterations per "tick" (where I've defined a tick to be 5ms), where it basically just tests for reaching/exceeding a tick's worth of time and checks for Pygame events. Output of the current code looks something like this on my i7-7700:
    pygame 2.4.0 (SDL 2.26.4, Python 3.11.4)
    Hello from the pygame community. https://www.pygame.org/contribute.html
         5.0842: Hit    1 of    1 ticks at      5.0174ms. Delta: 5.0583ms. Loops: 1983
        10.0222: Hit    2 of    2 ticks at     10.0174ms. Delta: 5.0006ms. Loops: 2384
        15.0260: Hit    3 of    3 ticks at     15.0174ms. Delta: 5.0037ms. Loops: 2538
        20.0246: Hit    4 of    4 ticks at     20.0174ms. Delta: 5.0007ms. Loops: 1764
        25.0229: Hit    5 of    5 ticks at     25.0174ms. Delta: 5.0006ms. Loops: 2148
        30.0228: Hit    6 of    6 ticks at     30.0174ms. Delta: 5.0009ms. Loops: 3198
        35.0219: Hit    7 of    7 ticks at     35.0174ms. Delta: 5.0003ms. Loops: 3380
        40.0225: Hit    8 of    8 ticks at     40.0174ms. Delta: 5.0009ms. Loops: 3608
        45.0224: Hit    9 of    9 ticks at     45.0174ms. Delta: 5.0015ms. Loops: 3912
        50.0234: Hit   10 of   10 ticks at     50.0174ms. Delta: 5.0002ms. Loops: 2727
    ...
    4985.0219: Hit  997 of  997 ticks at   4985.0174ms. Delta: 5.0004ms. Loops: 3148
    4990.0205: Hit  998 of  998 ticks at   4990.0174ms. Delta: 5.0006ms. Loops: 3226
    4995.1848: Hit  999 of  999 ticks at   4995.0174ms. Delta: 5.1650ms. Loops: 3129
    5000.0215: Hit 1000 of 1000 ticks at   5000.0174ms. Delta: 5.0003ms. Loops: 3050
    ---
    5000.2230: Hit 1000 of 1000 ticks at   5000.0174ms. Delta: 5.0003ms. Total time: 5000.2122
    Min loops:  1721
    Max loops:  4095
    Avg loops:  3314
    Max delta:  5.611ms
    Avg delta:  5.004ms
    Pygame events: 4750
    
    Each "hit" is where it would get to send data within the desired "tick" window, i.e. it hits its scheduling.
  • I ran this same code for 100,000 iterations (500 seconds) and it missed the window 12 times (0.012%).

Alternatives

  • I can already do SDL on Windows, so C++ is an option. This should reduce all processing overheads to a minimum, which means it would basically just be the USB-CDC overhead and response time of the Pi Pico (Pico-DE0 board).
  • In any case, I think I need to make firmware for the Pico-DE0 that is optimised for this job, so we only need to send one command with all the necessary register parameters and let the Pico-DE0 send it to the FPGA design as fast as it can.
  • PIO is another option; offload the job.
  • Cython and Codon could be interesting to look into for compiling Python code.

Notes

Next steps

  • Try a really simple VGA/cursor/GPIO experiment: Make a VGA design that just renders a cursor (even just a rectangle) on-screen at a given X/Y position, and make that position come from momentary GPIO states... intentionally doing it in a way that could experience race conditions (i.e. not registered). Then work out which actual GPIOs to map bits to on the Pico, perhaps providing an abstraction function. Hopefully this should reveal things like tearing when moving the mouse really fast.
  • This will probably only need 19 bits (X is 10, Y is 9), and we have maybe up to 26 bits total, so we could use the extra 7 bits for some mouse button and keyboard states and mousewheel mapping to cursor colour.
  • Then try to work on building an actual firmware command to accept a full state transfer, which the Pico will then clock out to an update to the VGA design that is registered and possibly even has a buffer. That could also be triggered by an IRQ from the design back to the Pico?
  • Finally start trying to work that into the Raybox design.