Main Content

An ATSAMD21 (same as Arduino Zero) handles parallax scrolling, 16-bpp graphics at 40-fps on a 160x128 TFT LCD

A poor’s man hand-held console is made using a small Cortex M0+ board (Arduino Zero compatible), some switches, a widespread 1.8 160x128 pixels TFT display and few other external components. In this project we focus on a platform game. The framerate is fixed at 40 fps (without frame cap, the frame rate would vary between 41 and 51 fps), and the graphics engine can handle dual playfield with parallax scrolling, at 16bpp (65536 colors). Some more optimization is still possible, without using assembly, which could lead to a better constant fps value. The graphics engine can be used for many other types of games: racing game, shoot em up, etc. Sound samples and music (not yet implemented) will be stored on an SD card, which can be mounted on the SD card slot on the bottom side of the TFT module board. Still missing: game score and player life/energy overlays. In this example, the game graphics is from Sunny Land free game art from ansimuz (see links)

Introduction
I wanted to see how far I could push the Cortex M0+ of the Arduino Zero. I think it is a balanced microcontroller: not too limited like an AVR, not too fancy, like a Cortex M4 (which has enough computing power even to run Doom).

I wanted to do something that could be challenging and, at the same time, funny. Well, I love 2D platform games. Why not starting from them?

Even if 2D platform games might seem outdated, they still require a good amount of memory, and if no hardware 2D acceleration is present, all the data must be processed by the CPU or, if present, by the DMA.

Initially I went on the conservative way: the ATSAMD21 specifies a maximum SPI frequency of about 12MHz, and by specification, the ST7735 controller allows a maximum SPI frequency of 15MHz (66ns SCLK time). Therefore I set the SPI frequency to 12 MHz and I also fixed the frame rate to 25 fps (without cap, the refresh frequency fluctuated from 28 to 33 Hz. I wanted to save a couple of fps because I will need to implement the sound later).

However I have recently realized that both the display and the ATSAMD21 can work at 24 MHz! That’s a good overclock amount! (still the CPU is not overclocked!)

Now, the uncapped frame rate goes up to 51 fps, and, with capping a constant 40-fps frame rate can be achieved!

Specifications achieved so far:
Resolution: 160 x 128 pixel
Color depth: 16 bpp
Dual playfield with parallax scrolling
Multiple on-screen sprites.
Frame rate: minimum 40 fps using an out-of-spec 24 MHz SPI frequency value. Using a 12 MHz SPI, we can achieve more than 28 fps.”

Link to article