G4.3.4 Cascade Two Decoders into a 4-to-16

MediumImplementIcarus · browser samples / server checksReview the topic

Build a 4-to-16 decoder with active-low outputs from two 3-to-8 decoder cells and no other gate.

Hardware context: Relay boards, a repair board and a controller with active-low device lines, all driven by 3-to-8 decoders. Cascade two 3-to-8 decoders into sixteen chip selects with their enables alone.

A board needs sixteen active-low chip selects, and its parts list has two 3-to-8 decoders. Each decoder has three enables: g1 is active-high, and g2a_n and g2b_n are active-low.

This is an Implement problem. Write dec4to16 from the two decoder cells of the read-only library. When en_n is 0, output y_n[a] is 0 and the other fifteen are 1. When en_n is 1, all sixteen outputs are 1. Use no cell other than the two decoders, at most one more gate.

The check applies four inputs per case, one every 4 ns, and records all sixteen outputs after each. It also counts your cells.

Signals in the Timeline

SignalWidthRole
script20input of each check
Full specification
The module (keep the name and the ports)
module dec4to16 (
  input  logic [3:0]  a,         // the address, 0 to 15
  input  logic        en_n,      // active-low enable of the whole decoder
  output wire  [15:0] y_n        // active-low outputs: y_n[a] = 0 when enabled
);
  // your netlist
endmodule
deccells.sv: the cell library (read-only), the same as in problem G4.3.2
// deccells.sv: the cell library (read-only). Every cell takes 1 ns. Ports: outputs first.
// The cells count themselves: tb.n_dec for the decoder, tb.n_gate for every other cell.
// DEC38: a 3-to-8 decoder with active-low outputs. It is enabled when g1 = 1, g2a_n = 0 and g2b_n = 0;
// then y_n[k] = 0 for k = {a2, a1, a0} and every other output is 1. Disabled, all outputs are 1.
module DEC38 (output wire [7:0] y_n, input wire a2, a1, a0, g1, g2a_n, g2b_n);
  assign #1 y_n = (g1 && !g2a_n && !g2b_n) ? ~(8'b1 << {a2, a1, a0}) : 8'hFF;
  initial tb.n_dec++;
endmodule
module INV   (output wire y, input wire a);                   not  #1 (y, a);          initial tb.n_gate++; endmodule
module NAND2 (output wire y, input wire a, b);                nand #1 (y, a, b);       initial tb.n_gate++; endmodule
module NAND3 (output wire y, input wire a, b, c);             nand #1 (y, a, b, c);    initial tb.n_gate++; endmodule
module NAND4 (output wire y, input wire a, b, c, d);          nand #1 (y, a, b, c, d); initial tb.n_gate++; endmodule
module OR4   (output wire y, input wire a, b, c, d);          or   #1 (y, a, b, c, d); initial tb.n_gate++; endmodule
module AND4  (output wire y, input wire a, b, c, d);          and  #1 (y, a, b, c, d); initial tb.n_gate++; endmodule

en_nay_n
1anyall sixteen bits 1
0kbit k is 0, every other bit is 1

The result fields are y_n_step0 to y_n_step3, in hex, and over_budget.

Examples

Example 1

Addresses 0 to 3
Input
a=0, a=1, a=2, a=3
Output
y_n_step0 = 0xfffe, y_n_step1 = 0xfffd, y_n_step2 = 0xfffb, y_n_step3 = 0xfff7, over_budget = no

The low decoder pulls one of its outputs low; the high decoder keeps all eight of its outputs high.

Example 2

Addresses 8 to 11
Input
a=8, a=9, a=10, a=11
Output
y_n_step0 = 0xfeff, y_n_step1 = 0xfdff, y_n_step2 = 0xfbff, y_n_step3 = 0xf7ff, over_budget = no

Now a[3] = 1, so only the high decoder is on, and the selected line is in the upper half.

Example 3

Disabled, on Both Halves
Input
disabled (a=3), disabled (a=12), a=12, disabled (a=0)
Output
y_n_step0 = 0xffff, y_n_step1 = 0xffff, y_n_step2 = 0xefff, y_n_step3 = 0xffff, over_budget = no

With en_n = 1 nothing is selected, whatever the address and whichever half it falls in.

Constraints and Contract

  • Inputs are known 0/1 values. Each input is held for 4 ns before the outputs are read.
  • Keep the module name and the ports. Connect cell outputs to whole halves of y_n with constant part-selects.

Hints

Hint 1

Both decoders see the same three low address bits. The top bit decides which of the two is enabled.

Hint 2

One decoder must be on when a[3] = 0 and the other when a[3] = 1. Each decoder has an active-low enable and an active-high one.

Hint 3

The overall enable en_n must turn both decoders off. Each has a spare active-low enable for it.

What the grader checks: Seven directed and six seeded cases of four inputs each cover every address in both halves, enabled and disabled. All sixteen outputs are compared with a model written in JavaScript. The source may hold only cell instances: two decoders and at most one other gate.

13 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 4 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

Addresses 0 to 3

Input
a=0, a=1, a=2, a=3
Expected output
y_n_step0 = 0xfffe, y_n_step1 = 0xfffd, y_n_step2 = 0xfffb, y_n_step3 = 0xfff7, over_budget = no

The low decoder pulls one of its outputs low; the high decoder keeps all eight of its outputs high.

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

Icarus · browser samples / server checks