G2.2.1 Majority Gate from Primitives

EasyImplementIcarus · browser samples / server checksReview the topic

Build a three-input majority circuit from AND and OR gate primitives and match its truth table on every row.

Hardware context: A three-input voter for a sensor that is read on three wires, and six unlabelled gate chips. Build the majority voter from three AND gates and one OR gate.

A flight computer reads the same sensor three times, on three wires. One reading may be wrong. A voter passes on the value that at least two of the three wires agree on.

This is an Implement problem. Write the voter maj3 from gate primitives. Its output y is 1 when two or three of the inputs are 1. The starter places two gates and tests one pair of inputs only.

A gate primitive is one line: the gate type, a name, and the wires in brackets. The output comes first, then the inputs. A gate may have more than two inputs.

Signals in the Timeline

SignalWidthRole
row3input of each check
Full specification
The module (keep the name and the ports)
module maj3 (
  input  logic a,
  input  logic b,
  input  logic c,
  output wire  y
);
  // your gates
endmodule
How a gate primitive is written
wire w;                 // a wire between two gates
and g1 (w, a, b);       // w = a AND b: output first, then the inputs
or  g2 (y, w, c);       // y = w OR c
RuleDetail
Functiony is 1 when at least two of a, b and c are 1. Otherwise y is 0.
GatesThe primitives and, or, not, nand, nor, xor and xnor are available.
WiresDeclare each wire between two gates with the keyword wire.
TimingThe check changes the inputs and reads y one nanosecond later.

Examples

Example 1

Two Votes for 1
Input
abc = 110
Output
y = 1

The inputs a and b are 1 and c is 0. Two of three wires say 1, so the voter passes on a 1.

Example 2

One Vote for 1
Input
abc = 100
Output
y = 0

Only a is 1. The two other wires agree on 0, so the output is 0.

Example 3

Three Votes for 1
Input
abc = 111
Output
y = 1

All three wires say 1. Every pair agrees, and the output is 1.

Constraints and Contract

  • Keep the module name maj3 and its four ports.
  • The inputs are always 0 or 1. The output must depend only on the present inputs.

Hints

Hint 1

Two votes agree on 1 when a pair of inputs is 1 and 1. Three inputs have three pairs.

Hint 2

One AND gate per pair tells you whether that pair agrees on 1. The output is 1 when any of the three AND gates gives 1.

Hint 3

The row 111 needs no gate of its own. Every pair is 1 and 1 there, so the OR gate already gives 1.

What the grader checks: The check applies all eight input rows, and then twelve more rows in another order. It reads y one nanosecond after each change. It compares y with a count of the 1s on the inputs. It checks the function only, not how you wrote it. Its cell rule refuses gate primitives, so it cannot grade them here.

23 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Two Votes for 1

Input
abc = 110
Expected output
y = 1

The inputs a and b are 1 and c is 0. Two of three wires say 1, so the voter passes on a 1.

Run samples executes all 3 public checks. Check all tests runs 23 checks on the server.

Icarus · browser samples / server checks