Friday, August 22, 2008

Super Mario Look a Like on an LPC2148 ARM Processor

This is one of my most favourite projects that I have ever done for my study. For the course Real Time Systems everyone had to write software for an LPC2148 ARM7 which was able to generate a VGA signal. This project had to be realized individually. One of the requirements was a minimum resolution of 15×10 pixels and the image shown should be read out of RAM and at least changeable (by buttons or the running software itself). It should be realized without usage of external hardware except for some resistors to scale the output signals.
We had to use the ARM development board made by a teacher at our school (Hogeschool Utrecht), it is provided with an LPC2148 and some peripherals which could be usable for other projects. An external add-on board provided the main board with nothing more than a VGA connector connected to the ARM’s IO lines with some resistors in between. Unfortunately the connector was made using only one IO line per colour (RGB) so this fixes the colour depth to only eight different colours.

Since it was Easter and I had too much time on my hands I thought it would be cool to take this project to the next level. The timing generated is equal to the timing used by a resolution of 640×480 but the real resolution is only 128×96. As the vertical resolution is fixed this still means that it needs to print 480 lines per frame. To create square pixels it just prints each line four times.
If you do some calculations you will see that there is only little time left to calculate things, as the processor will be fully used while printing VGA data.

To make sure that the timing of the VGA signal is as good as possible, the core of the software runs on a Fast Timer Interrupt which occurs at every start of a scan line. The program code will jump to some ASM code which generates the correct VGA signals. As this part of the code prints the RAM video buffer the only thing left is the code which changes the data stored in the RAM video buffer.
A gain a little bit more time I decided to make some extra scan lines at the top and bottom of the screen just black. In this time a C routine has the time to do whatever it wants to do with the video buffer. As soon as the ASM routine has displayed the last scan line it sets a flag to inform the C routine that it can change things in the video buffer without accidently showing something half changed on the screen. The C routine is capable of removing sprites from the background and drawing new sprites easily within its time slice. At this moment it will never use more than half of the available CPU time in a worst case scenario.

Just to make it even cooler I used the PWM capabilities of the ARM processor to play the Super Mario tune on a little speaker. You can see the result of this project in the video below, if you have any questions or remarks feel free to contact me or leave a comment.

Joost =)

  1. Mark Schouten

    Tuesday, July 28, 2009 - 22:47:45

    He wat leuk dat je dit gemaakt heb. Ik ben momenteel ook bezig met een vga driver te schrijven voor LPC 2148. Zou ik misschien jou code mogen inzien ?


  2. Ashwin Athani

    Thursday, August 27, 2009 - 10:37:59

    Dear Joost,

    I am quite amazed with your work… Great Job!!! would you be interested in porting this application on our board.?? We at NGX Technologies, Bangalore have come up with a low cost, OPEN and feature rich ARM7 LPC2148 development board…. Have a look at for more details and let me know your thoughts…

    Please feel free to contact me if you have any questions…


Add comment

Fill out the form below to add your own comments

User data

Add your comment

Admin area