G9.13.1 A Transmission-Gate Latch from Switches

MediumImplementIcarus · browser samples / server checksReview the topic

Build a latch from eight switches: an input gate, two inverters in a loop, and a feedback gate on the other phase.

Hardware context: A latch cell and a master-slave flip-flop of a custom register file, built from transmission gates. Build a latch or flip-flop cell from transmission gates and inverters.

A custom register file needs a small latch cell. It must pass d to y while clk = 1, and hold the last value while clk = 0. Both clock phases, clk and clkb, are routed to the cell.

This is an Implement problem. Build tglatch from at most eight transistor cells. The check applies rows of clk and d, one per nanosecond, and reads y after each.

If two drivers fight, y reads x. If nothing drives the loop, the inner node floats and y reads x as well. The check also counts your transistors.

Signals in the Timeline

SignalWidthRole
rows24input of each check
Full specification
The module (keep the name, the ports and the two supply nets)
module tglatch (
  input  logic clk,
  input  logic clkb,   // always the complement of clk
  input  logic d,
  output wire  y
);
  supply1 vdd;   // the positive supply: always 1
  supply0 gnd;   // ground: always 0
  // your transistors
endmodule
clky
1follows d
0holds the value it had when clk fell
switches.sv: the two transistor cells (read-only). The terminals are out, in, ctrl
// switches.sv: the two transistor cells (read-only).
// Terminals are (out, in, ctrl), in the order of the nmos and pmos primitives.
// Each cell adds 1 to the transistor counter of the check when the simulation starts; a pfet also counts as a PMOS.
module nfet (output wire out, input wire in, input wire ctrl); nmos (out, in, ctrl); initial tb.transistors++; endmodule   // on when ctrl is 1
module pfet (output wire out, input wire in, input wire ctrl); pmos (out, in, ctrl); initial begin tb.transistors++; tb.pfets++; end endmodule   // on when ctrl is 0

RuleDetail
TransistorsOnly nfet and pfet cells, eight at most. Each transmission gate needs its PMOS: at least four pfet cells in all.
Clocksclkb is always the complement of clk. Every script starts with clk = 1.
Resulty after each of eight rows, shown as 0, 1, x or z. Then the transistors over the budget and the pfet cells missing, which must both be 0.

Examples

Example 1

Open, Then Hold a 1 While d Changes
Input
(clk, d) = 10, 11, 01, 00, 01, 00, 10, 11
Output
y_row1 = 0 (0), y_row2 = 1 (1), y_row3 = 1 (1), y_row4 = 1 (1), y_row5 = 1 (1), y_row6 = 1 (1), y_row7 = 0 (0), y_row8 = 1 (1), transistors_over_budget = 0, built_from_switch_cells = yes (1), pfet_cells_missing = 0

While clk = 1, y follows d to 1. While clk = 0, y stays 1 whatever d does. When clk returns to 1, y follows d again.

Example 2

Hold a 0 While d Changes
Input
(clk, d) = 11, 10, 00, 01, 01, 00, 01, 11
Output
y_row1 = 1 (1), y_row2 = 0 (0), y_row3 = 0 (0), y_row4 = 0 (0), y_row5 = 0 (0), y_row6 = 0 (0), y_row7 = 0 (0), y_row8 = 1 (1), transistors_over_budget = 0, built_from_switch_cells = yes (1), pfet_cells_missing = 0

The latch closes on 0 and keeps it through four changes of d.

Example 3

d Changes While Open
Input
(clk, d) = 10, 11, 10, 11, 01, 10, 00, 01
Output
y_row1 = 0 (0), y_row2 = 1 (1), y_row3 = 0 (0), y_row4 = 1 (1), y_row5 = 1 (1), y_row6 = 0 (0), y_row7 = 0 (0), y_row8 = 0 (0), transistors_over_budget = 0, built_from_switch_cells = yes (1), pfet_cells_missing = 0

While open the latch is transparent: every change of d reaches y in the same row.

Constraints and Contract

  • Inputs are known 0/1 values; each row is held for one nanosecond and y is read at its end.
  • In the row where clk falls, d does not change: that would break the hold time.
  • Keep the module name, the ports and the supply nets vdd and gnd.

Hints

Hint 1

Two inverters in a loop hold a value. Name the node between the input gate and the first inverter x.

Hint 2

The input gate connects d to x while clk = 1. Its NMOS takes clk and its PMOS takes clkb.

Hint 3

The feedback gate connects y back to x while clk = 0, so its NMOS takes clkb and its PMOS takes clk.

What the grader checks: Five directed and four seeded scripts apply eight rows each. After every row y is read as 0, 1, x or z and compared with a latch model in JavaScript. The cells are counted, and so are the pfet cells: a latch whose pass gates are bare NMOS fails. Only nfet and pfet cells and wires are accepted inside the module. Switch cells model on and off only: setup, hold and delay are measured in lesson G9.13.

9 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 1 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

Open, Then Hold a 1 While d Changes

Input
(clk, d) = 10, 11, 01, 00, 01, 00, 10, 11
Expected output
y_row1 = 0 (0), y_row2 = 1 (1), y_row3 = 1 (1), y_row4 = 1 (1), y_row5 = 1 (1), y_row6 = 1 (1), y_row7 = 0 (0), y_row8 = 1 (1), transistors_over_budget = 0, built_from_switch_cells = yes (1), pfet_cells_missing = 0

While clk = 1, y follows d to 1. While clk = 0, y stays 1 whatever d does. When clk returns to 1, y follows d again.

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

Icarus · browser samples / server checks