todbot / CircuitPython_GC9A01_demos

Demos showing how to use CircuitPython displayio driver for GC9A01 round LCDs
MIT License
58 stars 14 forks source link

Speed up refresh rate #6

Closed fmohtadi99 closed 2 months ago

fmohtadi99 commented 2 months ago

As I tested, SPI frequency is set to 250000 which is very low to refresh the screen. Is there any way to increase it to the highest possible frequency (130_000_000 AFAIK)?

todbot commented 2 months ago

You can increase the SPI frequency pretty easily in the fourwire object constructor. Pass in a baudrate argument with the bus speed you want. So your display constructor line would look something like this if you want the speed to be 32 MHz:

spi = board.SPI()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst, baudrate=32_000_000)
display = gc9a01.GC9A01(display_bus, width=240, height=240, backlight_pin=tft_bl)

You may notice in the docs that it defaults to 24 MHz (24_000_000), which is pretty fast, almost the fastest you can get SPI. CircuitPython will make a best-effort to get as close to the speed you specify, but it depends on which chip you're on, what its clock speed is, and sometimes even which SPI port you're using.

You will not be able to hit 130 MHz unless. That is outside the range of SPI. Even the fastest SPI bus (used for accesses to a memory chip) top out at 80 MHz.

You say you are seeing SPI speed of 250000. How are you determining that?

fmohtadi99 commented 2 months ago

and sometimes even which SPI port you're using

So, you mean there may be difference between SPI ports. Right?

How are you determining that?

print(spi.frequency)
// 250000

Running on Raspberry Pi Pico

todbot commented 2 months ago

and sometimes even which SPI port you're using

So, you mean there may be difference between SPI ports. Right?

Yes, but it's very rare and only available to you if you're building your own board.

print(spi.frequency)
// 250000

If you're doing that before instantiating the fourwire bus, then you're seeing the default SPI bus speed (and it defaults to a slow-ish speed that's known to work across all devices). The fourwire bus will change the SPI bus speed to whatever is specified in its constructor, by default that's 24 MHz.