line

PIC32MX Single Chip Vide Game System

line

Feb. 7, 2015

PIC32MX is a Microchip's single chip microcomputer. I succeeded in making some color video games using this single chip microcomputer with very simple circuit.
Generally, a dedicated controller is used to view the picture on TV, but in this system, only a PIC32MX generates color image signals in software without other special chips. Therefore, parts used in this system are PIC32MX, several resistors and capacitors, a crystal oscillator, some input buttons... you will notice the circuit is very simple. With just slightly these parts, you can enjoy the color video games.
I repeated the experiment and succeeded in making practical single chip color video signal output system. Although very simple, it also has a mono audio output.
On this page, I will introduce three games that I have made. TETRIS and PACMAN work with inexpensive 28-pin dual inline package. Because it is so simple, you can try even on the breadboard. Since it requires a large memory capacity and execution speed, the third game works with a different circuit.

Note that the video output is limited to NTSC system used in such as North America and Japan. It does not work for PAL and SECAM.

For detail about NTSC, see the following.
http://en.wikipedia.org/wiki/NTSC

board
Game board


circuit
Schematic (Click to enlarge)


TETRIS

Since I have succeeded in the experiment of general purpose character-based color video output system, I wrote a TETRIS program as an application. In general, color graphics require large video memory to store images, but this system works with PIC32MX120F032B / PIC32MX220F032B that has only 8K bytes RAM because of character-based graphics.

How to play

Program the HEX file to the PIC32 with PICKit3, for example, and connect this system to the video input and audio input of TV. Then turn the power switch of the system on, and you will see title of TETRIS. Push START button to play the game. You will hear Russian folk music. Move blocks by 'LEFT' and 'RIGHT' buttons, rotate by 'UP', and drop by 'DOWN' buttons.

How to use this system

This system is designed to be used for general purposes for displaying the color fonts on TV. By calling a init function at the first of the program, this system continuously output the color composite signal by the timer interrupt, without consciousness.
Only writing the character code and color code to TVRAM array, you can display a colored font on the TV screen. You can configure the color codes with the palette function.

Download

When you use source files, add all of the files .c and .h into the project, and build it.
The tools version I used is :
MPLAB IDE v8.80, and MPLAB C32 C Compiler v2.02.

Download source and hex files

TETRIS
Screenshot of TETRIS


Text vram
Structure of text video memory

PACMAN

Next I have succeeded in resolution 256x224 dots, 16 colors graphics video output system, and I made a PACMAN program as an application. Because the system requires 28K bytes for video memory, you need PIC32MX150F128B or PIC32MX250F128B that has 32K bytes RAM. Except that the PIC chip has changed, it is the same circuit as the one used in TETRIS.

How to play

Program the HEX file to the PIC32 and connect the system to a TV. Turn the power on, then push START button, and the game will start with the famous start music. Move the pacman with direction buttons, and eat all cookies up.

How to use this system

This system is designed to be used for general purposes for displaying color graphics on TV. By calling a init function at the first of the program, this system continuously output the color composite signal by the timer interrupt, without consciousness.
VRAM array constitutes the video memory, that is configured 4 bits color per dot as shown, and just writing to the array you can display color dots. You can configure the color with the palette function.

Download

When you use source files, add all of the files .c and .h into the project, and build it. Note that you should configure the Optimazation Level '1' or higher. Level '1' is available also on free edition of MPLAB Compiler.
The tools version I used is :
MPLAB IDE v8.80, and MPLAB C32 C Compiler v2.02.

Download source and hex files

PACMAN
Screenshot of PACMAN


Text vram
Structure of graphic video memory

VELUDDA (My original shooter game)

I made another system for more advanced games. The device I chose is PIC32MX370F512H that has 128K bytes RAM and runs at 100MHz. In this system, you can enlarge, reduce and rotate the screen. You can configure the start position and scanning directions of the video signal in the video memory of 256x256 dots, 256 colors to rotate and scale the image. In addition, by changing the resistances value of the DA converter, reproducibility of color has been improved. Because of SMD chip, the soldering work is more difficult than DIP chip. For this system, I created the original shooter game named "VELUDDA" with scroll and rotation.

How to play

Program the file 'veludda.hex' to the PIC32MX370F512H and connect the system to a TV. Turn the power on, then push START button, then you'll see your round flying ship over the ground. Your mission is to annihilate the enemy. Turn left and right by LEFT and RIGHT buttons, accelerate by UP buttons, shoot enemy by FIRE button.

Download

When you use source files, add all of the files .c, .h and .s into the project, and build it. Note that you should configure the Optimazation Level '1' or higher. Level '1' is available also on free edition of MPLAB X Compiler.
MPLAB IDE does not support this device, please use the MPLAB X. Also use XC32 v1.32 or earlier, not support XC32 v1.33 or later.
The tools version I used is :
MPLAB X v2.10, XC32 v1.31

Download source and hex files

VELUDDA
Screenshot of VELUDDA

circuitSchematic (Click to enlarge)

VELUDDA's board
PCB

How it works

There were some single chip TV games that generate a video signal with PIC since 1990s. But they generated only black-and-white signals, not color signals, because the color composite video signal is very complicated and requires fast and precise control. By the appearance of the 16-bit or 32-bit PIC, it has become possible to generate a color composite video signal with single chip.
In color video signal, in addition to synchronization signal and the luminance signal same as BW video, two color difference signals are composited. Color difference signals are modulated by 3.579545MHz wave called color-sub-carrier, and it represent color by the amplitude and phase. The signal waveform can be calculated from the each RGB brightness, and by sending signals on several times frequency of color sub-carrier, a TV recognize the color video information.
Therefore, by using a 3.579545MHz crystal for system clock of PIC, with 15 or 16 times of the PLL setting, outputting signals at constant instruction intervals, PIC generates a color signal continuously in software.
In addition, not included in the black-and-white signal, a color burst signal must be sent for each horizontal line. The signal is intended to tell the reference phase of the color-sub-carrier to TV, and 9 cycles of sine wave are put on between the horizontal sync and video image signal.
Actually, those signals are sent with a 5 bits DA converter formed by resistances connected to GPIO of PIC.
Also, audio output is realized simply in PWM function that can make any frequency of square wave.

hlines
Scan lines of NTSC video signal


hlines
Phase and Amplitude of 8 colors
(The dashed line is color burst signal)


hlines
Formulas from RGB to NTSC


Conclusion

By the evolution of the microcomputer, the color video game has become to be made by single chip. The TV system has been changed from analog to digital, and HDMI interface has become mainstream, but the composite video interface is still alive because of many compatible devices, I think it will survive for the time being. Because these color TV game systems are made for general purpose, you can make games and applications easily with these systems. I think that it can also be applied to hobby of electronic works, not only to games. Now let's challenge it.

Copyright (C) KenKen All Rights Reserved.