This project is a micro controller chess game. The objective has to be able to play chess on a VGA monitor, including an intelligent computer to play against. This all has been accomplished with a microcontroller.
I started this as a project for the college ( I am a Electrical Engineering student ), but it has grow way beyond that. Now it is a complete chess game with a video output, keyboard for user interface, audio for some sound effects, a clock, a temperature meter. All the code was written from scratch, so any questions about the code you can ask me. I took a lot of time to write all this down, and to make the video and audio routines. The code is all well commented (almost all in English) and modular, it shouldn't be hard to understand.
The source code (attached as a RAR file) was all divided in simple modules, so it's easy to debug and re-use. Some cool techniques where used in the routines that are worth a look. The division of the source code is as follows :
- Graphics Routines
- Temperature sensing
- External Flash Memory (NVM)
- Real Time Clock and Calendar (RTCC)
- Analog Clock
- Chess Engine
- Chess Human Interface
- Chess Graphics
- Conway's Game of Life
In the end i had a nice game, not so hard but funny.
Thanks to to my friend Igor for drawing the pieces for me (I suck in Paint).
And if you like the project, and feel it deserves to win, vote in the Microcontroller Contest,and on the Toy contest.To vote go to the following links:
Arthur Benemann, Brazil 2011
Step 1: Hardware
I know that this micro was supposed to be used for motor control, it has all those nice peripherals and the DSP instruction , but let's do not use this stuff now. The things that are interesting are the SPI module that can go up to 10MHz, 40 MIPS core, 8 DMA channels, 4 Output Compare modules, audio DAC.
The clock is run at 80MHz this makes the use of the full processor power, and also can be scaled to get a 10MHz clock for the SPI module this is necessary by the video routine. This clock rate is obtained by the PLL block in the DSPIC33F.
If i don't know what is DMA its a feature that allows some peripherals to transfer memory to or from the data memory without CPU intervention. (wiki reference)
So with the processor chosen the rest it's straight forward.
- Keyboard PS2 connection is as simple as two resistor just for precaution (the 5v input pins of the micro must be used).
- Serial RS232 using a ST232 as transceiver, no interface needed for 3v3.
- The temperature sensor , a LM35 (10mV/ºC) , just need a low pass filter in the output. External
- SST25VF016B Flash memory comunnicate via SPI and is 3v3 so just a direct connection, two resistor are added just in case there is a software problem and two inputs accidentally are connected together.
- Audio output from the DAC it's a 0.7v peak signal. Amplification and ac coupling are made by a capacitor and a LM380 in the typical application from the datasheet, it's capable of outputting 2W with low distortion.
- VGA signal its composed of 2 TTL signal, just a resistor for interfacing, and three analog RGB signals. The input impedance of a monitor is 75 Ohms so just a resistor would fit, but the signal must have a 0,7 amplitude for full intensity in the screen, by Ohms law this gives 9.3mA more than the maximum current of the processor. A 74HCT14 inversor gives the current gain.
The power supply has three output rails. A 5V regulated by a 7805, for the high voltage chips. A 3v3 rail powers the processor and the flash memory, to get 3v3 a LM317 is used just as described in the datasheet. The amplifier is connected to the unregulated supply because it needs the higher voltage to power the speaker.
I designed little modules to plug in a bread board so they can be reused. All these modules are in the project files.Some i have built in a pre drilled pcb so there are no files, but these are simple to be made.
In the beginning of this step there are pictures of the project mounted in my breadboard, the Schematic is also there, but the eagle files are in the project files.
1 CRYSTAL 20MHz
1 CRYSTAL 32.768 kHz
1 LED 5MM
2 220R 1/8W
1 390R 1/8W
5 1k 1/8W
5 1k 1/8W
3 10k 1/8W
4 22pF 50V
7 100nF 16V
4 10uF 25V
1 470uF 16V
1 DB9 Female
1 DB15 Female
1 pinhead bar