Lab 10: Sequential Circuits


In this lab, you will use Logisim to create both simple and not so simple clocked circuits.

For help on how to install Logisim, see Lab 9.

Exercise 10.1

You must design and build a traffic light controller, according to the following specifications:

  1. The light will be placed at a pedestrian crossing. It has two inputs, which signal the presence of someone waiting to cross, or crossing.

  2. When both inputs are low, the light should be green.

  3. When one (or both) inputs change from low to high, the light should change from green to yellow on the next clock cycle.

  4. When the light is yellow, it should change to red on the next clock cycle, and remain red as long as either of the input sensors is high.

Download and open the file lab10ex1.circ, which shows the inputs and outputs of your circuit. Everything else is up to you.

For this exercise, you must only use flip-flops and standard gates (AND, OR, etc), and, of course, a clock.

Test and save your circuit

To test your circuit, use Logisim’s simulator. In the “Simulate”, check “Simulation Enabled”, and “Ticks Enabled”. This will cause the clock to tick. You can control how fast by selecting the tick frequency in the same menu. To test this circuit, you will want to use a fairly slow clock (1 or 2 Hz) so you can see what is happening. Use the poke tool (poke tool icon ) to change the values of the inuts. If you switch of the automatic ticking, you can also tick the clock by clicking it with the poke tool

Save your circuit in a new file (using “Save As…” from the File menu). This is the first file you must submit for this assignment.

Exercise 10.2

Next, for something slightly more advanced, let’s build an arcade game. (Ok, it’s not much of a game. But you can improve it!)

Download the file videogame.circ and open it in Logisim. The project contains three main components: the game component (labelled “Scribbler”, and connected to a joystick), the screen (a square matrix of pixels, attached to a video controller) and a RAM, which functions as a frame buffer. These components (game, video controller and RAM) are connected to two busses, one for address and one for data.

As was mentioned in the lecture last week, a bus is used to connect many devices. The problem is making sure that no two devices write to the bus at the same time. In our system, the game module and the video controller both need to access the frame buffer (RAM). Your task is to design a “bus controller”, a circuit that controls both devices so that they take turns accessing the frame buffer.

What is a frame buffer?

A frame buffer is a memory that stores what is shown on the screen. Our arcade game has an 8x8 pixel monocrome screen (that is, each pixel can only be on or off). The screen is logically organised by rows, so the frame buffer stores 8 rows of 8 bits each. (Hence, the address has 3 bits.) When a bit is 1, that means the pixel at that position should be on, and when it’s 0 the pixel should be off. The video controller reads one row of the frame buffer at a time, and updates the corresponding line on the screen. When it has gone through all 8 lines, it starts over with the first.

To see how it works, you can connect a pin set to one to the wires labelled “Video controller has access” and “Activate RAM output”, a pin set to zero to the wire labelled “Game has access”, and run the circuit. The video controller will now continuously copy the contents of the frame buffer to the screen. Using the poke tool, you can select an entry in the RAM and type in a new value (a two-digit hexadecimal number). You should see the screen change.

What the bus controller must do

Both the game module and the video controller has a single input bit which controls when they are allowed to access the bus. (In both components, it also serves as an activation signal, meaning they do nothing when the access bit is not set. However, it would be possible for the game module, for example, to still do some work on each clock tick even when it does not have access to the bus.) When the access bit is zero, the component will not write to either the address or the data bus.

The frame buffer (RAM) always reads from the address bus. It also has a control bit (“Activate RAM output”) which controls whether it will write to the data bus the contents at the given address, or read what’s on the data bus and store it at the given address. It reads and stores when the control bit is zero, and outputs when the control bit is one. The game module has an output, labelled “Write to RAM”, which signals if the game wants to read (zero) or write (one) when it is active.

The bus controller must do three things: First, ensure that in every clock cycle, at most one of the game module and the video controller has access to the bus. Second, it must set the RAM control bit according to the wishes of the component that currently has access. The video controller only reads the RAM, while the game module signals with an output bit whether it wants to read or write (as explained above). Finally, because the bus access bits also serve as activation signals, the bus controller also manages the relative speed of the two components.

For the game to work, your controller must:

  1. activate the game module for two consecutive clock ticks;
  2. activate neither component for two consecutive clock ticks;
  3. activate the video controller for eight consecutive clock ticks;

and then repeat the cycle.

Test and save your circuit

The game module implements a very simple “scribble pad” function: it simply lights up the pixel at the current position of the joystick, and leaves that pixel on. Thus, if you move the joystick around (with the poke tool) when the clock is ticking, you should see the screen filling up with lit pixels. To clear it, press the the “clear screen” button next to the frame buffer.

To test the game, you probably want to run the clock at a higher frequency (128 Hz, or even up to 1 KHz). You can run it at a lower frequency, or even tick the clock manually, as a debugging measure.

Save your circuit in a new file (using “Save As…” from the File menu). This is the second file you must submit for this assignment.

Some important notes

The following are some hints about how things work in Logisim, and about what are acceptable solutions.

  • The tri-state component is called a “Controlled Buffer” in Logisim. It can be found in the “Gates” section of the component library. As you can see by inspecting the game module and video controller subcircuits, it is essential for building components that communicate with a bus.

  • NEVER GATE THE CLOCK. Also do not use the clock signal as the control input for a tri-state component.

  • In simulation, Logisim displays wires in different colors depending on their state. A blue wire has a “high-impedance” (also called “floating”) value. This value behaves like a 1, unless some component pushes it down to 0. A red wire indicates an error value, usually because multiple components are trying to output different values to it at the same time. (See section “Wire colors”, under “Wire bundles”, in the built-in User’s Guide.)

    Your finished circuit should NEVER show red wires. (The arcade game circuit, when you first load it, does. This is because the access control bits are floating (blue), which means several components are writing to the bus at the same time. If you add a 0-valued pin to each of them, the red wires should turn black.)

  • Also, you should never write a floating value to a flip-flop or register. It may work in the simulation, but leads to problems in real circuits.

  • Some of the components you’re likely to use (registers, for example) have multi-bit wires for inputs and/or outputs. The number of bits is called the “width” of the wire. You can (usually) configure the with of inputs/outputs in the component attributes. For example, the frame buffer RAM has “Address Bit Width” set to 3 and “Data Bit Width” set to 8. If you try to connect ports or wires with different with, Logisim will draw the wire in bright orange and show an error message. To get the individual bits of a multi-bit wire, or to compose several wires into a multi-bit wire, use the splitter component. (You saw an example of this in Lab 9, which used a splitter to compose the width-4 input wire for the hex display component.)

Exercise 10.3

Now, it is time to make the game more exciting. (Ok, it’s not exactly going to be exciting. But better than a scribble pad.)

Using the arcade game circuit, with your bus controller in place, replace the “Scribbler” component with the “Move-A-Dot” component from the library. (You should make a copy of the file you saved your solution to exercise 2 in first, so you don’t accidentally overwrite it.) The Move-A-Dot component should fit in exactly the same position as Scribbler, and has the same inputs and outputs. It implements a different game: It keeps a single pixel on the screen, which moves in the direction you move the joystick, and stays still when the joystick is centered. If it moves off one side of the screen, it wraps around and enters from the other side.

Using the Move-A-Dot circuit as a starting point, make a better game! You can, for example,

  • Make it so that the pixel continues moving and only changes direction when the joystick is moved, and stops when the direction is reversed from where it is currently going.

  • Make it bounce off the walls instead of wrapping around.

  • Add obstacles (also drawn on the screen) that the pixel cannot move through (stops or bounces off).

  • Make the pixel leave a trail behind it. The trail can be of a fixed length (for example, three steps behind) or growing continuously.

  • Yes, you can implement the “worm)” game if you want.

Note that the two sample games we provided both need only two active clock cycles to make a full state update of the frame buffer. (For example, Move-A-Dot erases the pixel in the old position on the first tick and writes it in the new position on the second.) However, your game may need more ticks in between each screen update. If so, you will need to change your bus controller accordingly, to give the game enough time.

Test and save your circuit!

Save your circuit in a new file (using “Save As…” from the File menu). This is the third file that you should submit for this assignment.

Submission and marking

Exercise 10.1 and 10.2 account for 75% of the mark of this assignment. Exercise 10.3 is 25%.

You must submit one Logisim circuit file for each exercise, through wattle.

20 May, 2015
1886 words


Written by
Tags
labs

Quick links

2015 S1 lecture schedule:
  • Tue 2-3 CSIT N101
  • Wed 2-3 CSIT N101
  • Thu 12-1 ENG T

Note: The Thu 12-1 lecture slot is used in _some weeks_.

Quick-access class pointers: This will be updated to incldue links, such as the EdX teaching system.