Introduction High Level Design Software/Hardware Results Conclusion Appendices Game Play Pictures

HIGH LEVEL DESIGN

Rationale and sources of our project idea

Our project idea comes from the hugely successful 1985 Nintendo Duck Hunt game. We have all played that game and are interested in recreating the classic game using two Atmel Mega32 microcontrollers.

Background math

The math behind our duck hunt game is based on the lunar lander video game we did in our lab. We decided to express distance in our game in terms of pixels and time in term of frames, so the speed of a duck will be expressed as pixels/frames. For the video generation part of our game, we need to keep track of the speed, and direction of two ducks flying on the screen (in the two duck mode of the game). Each ducks can move in possibly 8 directions (up, down, left, right and four diagonal directions), and have a minimum speed of 0 and a maximal speed that is depended on whether if the duck is being controlled by a player or is it on a random movement course. When the duck is controlled by a player, the max speed is 1 pixel/frame in vertical and horizontal directions and slightly faster in diagonal directions. When the duck is uncontrolled, it moves at the same 1 pixel/frame for all 8 directions because we normalized the speed at diagonal directions to match that of the vertical and horizontal.

Our version of Duck Hunt included both sound effects and music. A second MCU was necessary for sound because we wanted to play back sampled sounds in flash and we were afraid that one MCU alone would not be able to handle the TV signal, game logistics, Sega controller, and sound at once. The high level design of the sound was based on Pulse Width Modulation performed on a second MCU. Music was created using the DDS method similar to the Cricket Call Synthesizer Lab. A sine table was loaded into memory and the width of the pulse on the output of the PWM (via the OCR) was determined by the sine table value. Stepping through the sine table more quickly produced higher frequency notes while stepping through the sine table slowly created low frequency notes. The speed at which the sine table was stepped through was determined by an increment value that was added to an accumulator, which was the index into the sine table. We used a timer interrupt that updated the accumulator every time the timer overflowed. The value of the increment to add to the accumulator in order to get the desired frequency is determined by:

1/frequency = (size of accumulator/increment) x (# counts in a pulse/clk frequency)
increment = (2^32)x(256/16,000,000)x(frequency)
increment = 68719x(frequency)

An array of frequency values were loaded into flash corresponding to the notes in a song. The highest frequency note played was 2349 Hz. According to the formula above, this gives an increment size of 161,420,931. With this size increment, there would be about 27 samples taken from the sine table which is still pretty accurate for one cycle of a sine.

Logical Structure