High Level Design

As mentioned in the introduction that we got the idea of this minesweeper project from the popular Minesweeper games that come with the Windows operating system.

Our original plan for the system is a simple scheme as shown in the figure below.


The microcontroller will be running the video generation code that we used in the lab [3]. There are 60 lines of free time in each frame, and we will fit the mouse interfacing code and games’ code in these lines.  

We thought this scheme is feasible because some of the more complicated computation is required only in the initialization stage. We should be able to optimize the remaining codes to be fast enough for the video generation code. However, we found out later that it is not feasible to interface with the mouse from the video generation code that we used in the lab [3].  

The mouse’s clock speed is too slow to be compatible with the video generation code [3].  Although, it appears as there are 60 lines of free time in each frame in the video generation code, the sync pulse generation interrupt event still happen at the end of each lines. The code in this 60 lines interval will be interrupted for 60 times. This is unacceptable for the mouse because each byte of data from the mouse cannot be completely transmitted in one line. This turn out that there is no way to read a complete byte of data from the mouse without interruption.  

Reason for using two microcontrollers  

· The mouse’s clock speed is in the range of 10-16.7KHz [1].

· Time to transmit one bit is about 1/16.7Khz » 60ms.

· There are a total of 11 bits to transmit one byte of data [1], and this will require 60ms ´ 11=660ms.

· Clock is generated by the mouse, and the microcontroller has to read a complete 11 bits of data whenever the mouse send it. There is free time while waiting for each bit, but the microcontroller must read each bit at the fixed interval according to the clock. The best way to make sure that the microcontroller read each bit synchronized with the clock, is to use an interrupt to detect the edge of the clock.

· The interrupt used to generate the sync pulse in the TV code triggered at a period of about 63us. If we use another interrupt that is triggered by the clock's edge (rising or falling edge depends on read or send data to mouse), the interrupt will be triggered at a period of about 60ms. Both interrupt cannot be disabled at any time, and it is impossible to coordinate these 2 interrupts from interfering each other.

· Even if we read the mouse data during the 60 lines of free time, the sync pulse generation interrupt will still continue to trigger at the fixed interval and it will interrupt the transmission from the mouse.

· Therefore, the TV generation code has no free time of 660ms for reading a byte from the mouse without any interruption.

Using two microcontrollers

We decided to use two microcontrollers for the project. One microcontroller handles the TV screen drawing and the other controller handle the mouse interfacing and games computation.

Microcontroller 1 (mc1): Generate video signal and display it on TV.

Microcontroller 2 (mc2): Read mouse’s data and handle the games computation.

mc1 and mc2 are communicating to each other through UART. mc1 send information about location of screen that need to be updated and the image to be displayed at that location. The schematic diagram of the system is shown below.



Schematic diagram of the system.

Microcontroller 1 (mc1): TV Controller

The code that we used in this microcontroller is started from the video generation code that we used in the lab [3]. Analog voltage signal is generated at the 2 bit DAC (Digital to Analog Converter) to draw image on the TV screen. We added routines to draw the minesweeper board, update cells on the board, and communicate with mc2. The TV generation code is so busy that there is little time left for doing anything complex. This also posed a constraint on how fast it can read data from mc2.

Microcontroller 2 (mc2): Games and Mouse Controller

The code in this microcontroller takes care of the low level interfacing with the mouse as well as the games' computation. It sends instructions to mc1 through the serial communication port (UART). Cursor's movement emulation, update on the board image, and games status (start/stop/win) are computed in this microcontroller and sent to mc1 to instruct mc1 on what is needed to be drawn on the TV screen.

Hardware and Software Tradeoff

The use of two microcontrollers actually simplified the programming task. We do not need to worry too much about speed and memory usage when writing the programs. The cost of using two microcontrollers is not a big disadvantage because microcontroller is relatively cheap.