LED Ping Pong Game
2016-05-20 | By Onurhan Öztürk
License: None
Introduction
About
How to Play?
There are in total of 10 LEDs which form the grid of this game. During the gameplay only 1 led is ON and position of this LED indicates the current position of the ball. Objective of each player is to hit their “button” to send the ball back to other player. However, this action can only be done when the ball is at last position of the corresponding receiver player. If a player hits the button prior to this, he or she will lose the game. This feature was added to prevent players from spamming the “hit” button. For each round ball has a unique speed which determines the time required for it to move to next grid position. After each round, (a successful hit by player 1), ball will speed up and make it harder to play. Keep in mind that, ball receiving player has to hit the button before it’s too late. If player misses the hit, game will be over and a sequence of led animation will be played to indicate this. After few seconds, game will restart.
Schematic
JTAG Port
For some projects it is good to use DIP package integrated circuits. Even though they have bigger footprints, you can easily program them on a separate programmer then put it on your PCB and you don’t even have to solder them, using a socket is just fine. This allows the reuse of these microcontrollers multiple times for many different projects. However, using DIP packages may not be a good solution always. Due to PCB design of this project, it is much better to use 20TSSOP package and solder the MCU on PCB once and for all. However, in this case you will need an SMD package programmer and program it prior to soldering. But each time you want to reprogram it, you will have to resolder it again and again which is a terrible engineering method. To get rid of tihs, this project is going to implement a JTAG interface on PCB. With the help of JTAG interface, you can program and even on-board debug the program with only 4 wires from TI Launchpad. For C3, you can use a capacitance value down to 1nF but the recommended value by TI is 2.2nF. Higher values will change the RC network which can cause distortions in high speed JTAG signal. Try to follow the reference design. (MSPS430: How to JTAG)
JTAG Power Switch
It is important to equalize the PCB ground and Launchpad ground since the JTAG programmer is located on launchpad. This allows voltage levels on PCB and launchpad to stabilize and form around a common reference point. Keep in mind that voltage is just the difference of potential energy between two points. This makes voltage a “relative” measurement. Therefore to connect different systems together, they must use the same reference point which is ground in most cases. Even though your JTAG will work without the VCC of launchpad, TI also recommends the use of JTAG VCC to be used to prevent miscellaneous bugs and unexpected behaviors. A DPDT switch is enough to switch between battery VCC and JTAG VCC and turn of the battery power. While programming the device, you should turn off the switch and let the MCU use the JTAG VCC!
Low Battery Detection
Just like many other consumer products it is important to warn the user for low battery. For this feature, this project uses the ADC module of MSP430 to sample the battery voltage and check if it is below a critical level. This allows programmers to easily set the critical level. R2 connected to ADC module is to prevent any high current passing through MCU and damaging it. When battery voltage falls below critical level, MCU will turn on the low battery LED.
Reverse Current Protection
It is incredibly easy to mix the positive and the negative terminals of CR2032 coin batteries. Therefore, to prevent a possible damage caused by reverse current, a schottky diode D1 is added in series to power line. A silicon diode could also work but it would have a higher forward voltage drop.
Decoupling Caps
Decoupling caps are necessary for instantaneous current requirements of MCU. CR2032 batteries are famous with their low output current capabilities therefore high capacitance decoupling caps should be used to compensate the microcontroller’s instantaneous current requirements. These current spikes usually occur while changing internal module settings like turning on ADC or timers.
MCU Code
MCU code is very straight forward. Before programming a microcontroller it important to decide which modules and features are going to be used. In this project, GPIO pins are used to drive LEDs, ADC is used to measure the battery voltage and timerA is used to time the ball speeds. After deciding on these, core settings has to be configured to run MCU properly. For this project master clock of 1MHz is enough and there is no need for a watchdog timer. Even though this game can be achieved without using the timer module and running all script in main CPU will work perfectly fine , using timer will save from a lot of power consumption. Since this is a battery run application, it is a good practice for getting into battery management.
It is possible to add player configurable game settings. For example, pressing both player buttons for more than 4 seconds can put MCU in configuration mode and by the help of LEDs you can let players to decide to select modes. Different modes can have different speed configurations for different levels. You can use flash memory of microcontroller to store user inputs. This feature is not included in the source code and you will have to add this on your own.
PCB Layout
Component Selection
LEDs are driven by MSP430 which has 3V high output voltage at GPIO pins. LEDs connected to these pins must have a forward voltage drop less than this value. Plus, current limiting resistors connected in series should also be considered while choosing the LEDs.
Component Placement
Decoupling caps should be close to microcontroller. To make PCB look better, LEDs and buttons are placed on top layer and rest of the circuit is placed on bottom layer. With it’s symmetric battery holders at edges and microcontroller in middle, this PCB has a good visual.
Power and Ground Planes
There are no switching boost regulators and high frequency components and use of planes are not vital nor necessary. But, why not use them if they are included in the price? These planes act like natural decoupling capacitors and help the routing of traces. By only using one via to bottom copper you can save time and lessen the complexity of your PCB design.
Conclusion
Possible Improvements
A good way to improve this project would be adding seven segment displays to show the score of each player. This will allow players to concentrate on game rather than tracking their scores. You can also add a Y axis to add second dimension to game and make it 2D. With this improvement you can add more realistic ball reactions and bouncing from wall effects.
Conclusion
It is sad to see that modern high tech games are replacing old gaming consoles one by one everyday. For new generations this may not mean anything at all but for older people, it is sometimes good to have nostalgy and remember our childhood excitements. LED ping pong game is just a simple example to this, just like tetris and Mario. After assembling your pcb you can now invite your friends for challenge and recall your memories from old days.
This is a good starter level project which does not deal with complex analog designs and background theories.
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum