In this lab you will use some of the modules of Logisim to construct a big priority encoder from some little priority encoders.
A priority encoder is a logic module with 2n data input bits, numbered from 0 to 2n-1, and n data output bits. The output of the priority encoder is the index of the data input with the highest index number that is 1. For example, if the input is 00110101, the output should be 101; and if the input is 00001111, the output bits should be 011. Priority encoders generally have extra inputs and outputs that enable them to do interesting things in groups.
If you installed a PC card before the days of plug-and-play, you may remember setting a card’s IRQ (Interrupt Request) number. The IRQ was implemented with a priority encoder.
Task 1 — Priority Encoder
Start by going to the explorer plane and clicking on the Plexers expander. Next select a Priority Encoder.
The attribute table should appear to allow customization of the the encoder. Change the number of select bits to 2. This will cause the priority encoder to have four (22) data inputs and two data outputs.
Go ahead and insert a priority encoder into your circuit.
Usually you would use the Logisim’s help menu to find out more about the priority encoder. But to speed this lab up a bit, we’ll use the Logisim library reference, in particular its information about the priority encoder.
From reading this page, you’ll learn the following about the inputs and outputs of the priority encoder when the encoder is facing east.
- To the west are the data inputs.
- To the south is the enable input.
- To the east are the data outputs and the ”group select“, also an output.
- To the north is the enable output.
At this point, you should be concerned that there is only one pin for the data outputs. There really should be two.
Try to wire up input and output pin to your encoder. Be sure to face your pins in the right direction. The one on the bottom faces north, and the one at the top faces south.
Even if your pins are turned in the right direction,
expect Logisim to complain
about Incompatible Widths.
Nonetheless, go ahead and play with the data and enable inputs to see what happens to the enable and group signal outputs. You may need to review the priority encoder page.
It is very important that you understand the role of the enable input and output and the group signal output. If you don’t, you’ll have no fun today.
- If the enable input is off; then both the enable output and the group select output will be off, and the data outputs will be floating (neither on or off). In this case the data inputs are ignored.
- If the enable input is on and all of the data inputs are off; then the enable output will be on, the group select will be off, and the data outputs will be floating.
- If the enable input is on and at least one of the data inputs is on; then the enable output will be off, the group select will be on, and the data outputs will be set to the number of the highest data input that is on.
Experiment with all three of the situations mentioned above. Try to achieve the state where enable out is 0 and group signal is 1. Present this to a lab instructor; but, if they are occupied, go to the next step.
At this point, the purpose of the enable input, group select, and enable output may be a tad confusing. Effectively, enable input is the switch that cause the encoder to do something useful. Group select is used to indicate the the encoder found that one of its data input was 1. The purpose of enable output is to tell another encoder to do something useful. We’ll learn more about it later.
Task 2 — Riding the bus
The data output of the encoder is a bus with two signals. To read the individual signals, we must split the bus.
Under the Wiring expander, you can find a Splitter. Go ahead and select it. Just for fun, place a splitter in your circuit and then play around with its attributes.
Set both the Fan Out and Bit Width In to 12. This is a way to extract the 12 individual bits of a bus of width 12. Notice that the individual output lines are numbered, in largely unreadable digits, with their bit position.
Now set the Fan Out to 3. This causes the bus of width 12 to be divided into three buses of width 4.
Even though the attributes may say “In” and “Out”, the bus transports bits in either direction.
That’s enough playing around. Set both
and Bit Width In to 2.
Connect the wide end of the splitter, the one with the single line,
to the output of the encoder. Then connect two output pins to the
Take some time to try out the inputs and outputs of the priority encoder.
The lab instructor will give you a task, such as “Set the data output bit 0 to 1, data output bit 1 to 0, enable output to 0, and group signal output to 1.” Do it!
Task 3 — Chaining four encoders
There’s a reason why those circuit designers created those enable and group signal output. It wasn’t just because they had two unused pins on the DIP.
Start by neatly stacking four copies of your present circuit
on top of each other.
Our job is to create a single 16-input priority encoder using 4-input priority encoders. The sixteen input pins on the left side of the circuit will be the sixteen encoder inputs. In the next two sections, we’ll create some outputs on the right side of the circuit.
At this point you can click on the data inputs, but the encoders act independently. Try connecting the enable output of the bottom encoder to the enable input to its neighbor. Notice that, when you turn on any data input of the bottom encoder, it changes the outputs of its neighbor. The purpose of the enable input and output is to allow the lower encoder to tell its upstairs neighbor: “Take a break. I have this case covered.” (Be sure that the enable input of the bottom encoder is turned on.)
Start by turning off all sixteen data input bits. Notice that all group signal outputs are off. This is because none of the encoders found a data input that is turned on. In this situation the topmost enable output should be on. This means: “I was asked to find a one, but didn’t see one.”
Next, turn on any one data input bit. The top enable output is now off which means: “I was asked to find a one, and I did!” Also, one of the four group signal output bits is on. This encoder is saying: “Pay attention to me. I’m the encoder that found the one with the highest number”
If you are unsure, talk to a lab instructor.
Task 4 — Getting the first two data outputs correct
The group signal output of the encoder, if any, that found the interesting bit will be on. All other group signal bits are off! In our circuit, the top encoder is handling data inputs numbered 0000 to 0010; next-to-top handles 0100 to 0111; next-to-bottom handles 1000 to 1011; and bottom handles 1100 to 1111.
You can add these as labels to the sixteen inputs, if you wish. The important thing to realize is that the group signal outputs determine the first two bits of the input pin’s number.
Add a fifth four-input priority encoder to your circuit.
(I suggest cut-and-paste followed by some editing.)
Place it to the right of the encoder stack
and route the group signals of the stack encoders to the data
input of this new right encoder.
Make sure that this new encoder has connections for its enable input
A priority encoder with sixteen data inputs should produce four data outputs. Right now we are only producing only two of the four. You must convince yourself of the following:
- The first two data outputs are being produced by the priority encoder on the right.
- The last two data outputs are being produced by one of the encoders in the left stack.
- The encoder on the right is telling you which of the gang of four knows the last two data outputs.
- The encoder on the right is computing appropriate enable and group signal outputs for the big sixteen input encoder.
Show the lab instructor your circuit.
Task 5 — Getting the last two data outputs correct
You’ve probably noticed that that the bus carrying the output of the priority encoder is usually blue. A bus that is connected to neither 0 or 1 floats. Priority encoders can be designed to disconnect from their output bus when they are disabled or have no data inputs that are one.
The easy way to get the last two bits is to just tie the output buses of the four left encoders together. This works because the outputs of at least three of the four encoders will always be floating.
Tie the left encoder outputs together and use it to
generate the last two output bits.
But we’re going to something a bit more elegant. We’ll use a multiplexer. Underneath the Plexers expander there is a Multiplexer gate. Add one of these to your circuit with two data output bits and two select bits. This multiplexer can be used to route four different two buses of width two into a single bus of width two.
The wiring is pretty easy. The data inputs of the multiplexer are connected to the data outputs of the four encoders on the left. The selector input of the multiplex-or is connect to the data output of the right encoder. This allows the right encoder to route the data output of one of the left encoders to the outside world.
You should also tie the enable input of the multiplexer to 1. You’ll find a Constant under the Wiring expander than can be used for this purpose
And, be sure to connect the enable input for the big 16-input
encoder you are constructing to the enable input of the
bottom 4-input encoder.
Test out your circuit, with the multiplexer and seek the approval of a lab instructor.