openMemristorPDK Guide
Guide · Section 8 · The digital side · Part 4 · about 10 min · 7 steps

A controller made of real logic gates

Build a 4-bit memory with a controller, then let Yosys turn the controller into real logic gates from IHP's SG13G2 library. You only ever need to click whatever is inside the red box, or type exactly what is in a black box.

Do A digital twin in Verilog first: it uses the same terminal.

click here Click any screenshot to see it full size Keys in the player: ← → Space Esc
About 10 minutes

Step by step

A memory needs a little circuit that says "write a 1 into cell 3" or "read cell 0" and makes the right pulses, long enough for a memristor to switch. That circuit is ordinary digital logic: you write it in Verilog, and Yosys turns it into real logic gates from IHP's standard-cell library.

1

The controller

Four files in openMemristorPDK/digital/memory2x2/, all ready (you can also open each one from the Library Manager: cells mem_ctrl, memory2x2, memory2x2_tb, Verilog row):

mem_ctrl.v
The controller, below. This is the part that becomes gates.
memory2x2.v
A 4-bit memory: the controller plus four copies of the memristor twin from A digital twin in Verilog.
memory2x2_tb.v
The test: write 1 0 0 1 into cells 0 to 3, read them back, then write a 0 into cell 0 and read it.
Makefile, synth.ys
The commands, so you only have to type make sim, make synth or make gates.
mem_ctrl.vVerilog
// mem_ctrl.v -- a tiny controller for a 4-bit memristor memory.
// It turns "write a 1 into cell 2" or "read cell 3" into the right
// pulses, long enough for a memristor to switch:
//   write: PULSE clock cycles of set or reset on one cell,
//   read:  READ  clock cycles of read on one cell, then it keeps the bit.
// With a 10 ns clock, PULSE = 8 gives an 80 ns pulse, like the xschem
// testbenches. This file is real logic: Yosys turns it into gates.
// (No `timescale here: it has no delays, only clock ticks.)

module mem_ctrl #(parameter PULSE = 8, parameter READ = 4) (
  input  wire       clk,
  input  wire       rst,       // 1: stop and start over
  input  wire       start,     // 1 for one clock: begin an operation
  input  wire [1:0] op,        // 0 = read, 1 = write 1, 2 = write 0
  input  wire [1:0] addr,      // which cell: 0, 1, 2 or 3
  input  wire [3:0] q,         // what the cells show while being read
  output wire [3:0] set,       // write-1 pulse, one wire per cell
  output wire [3:0] reset,     // write-0 pulse, one wire per cell
  output wire [3:0] read,      // read pulse, one wire per cell
  output reg        data_out,  // the last bit read
  output reg        busy       // 1 while an operation is going on
);
  reg [1:0] cur_op;
  reg [1:0] cur_addr;
  reg [3:0] count;

  // Only the chosen cell gets a pulse: 1 shifted to its position.
  wire [3:0] chosen = 4'b0001 << cur_addr;

  assign set   = (busy && cur_op == 2'd1) ? chosen : 4'b0000;
  assign reset = (busy && cur_op == 2'd2) ? chosen : 4'b0000;
  assign read  = (busy && cur_op == 2'd0) ? chosen : 4'b0000;

  always @(posedge clk) begin
    if (rst) begin
      busy     <= 1'b0;
      count    <= 4'd0;
      data_out <= 1'b0;
      cur_op   <= 2'd0;
      cur_addr <= 2'd0;
    end else if (!busy) begin
      if (start) begin              // remember what to do, then start
        busy     <= 1'b1;
        cur_op   <= op;
        cur_addr <= addr;
        count    <= 4'd0;
      end
    end else begin
      count <= count + 4'd1;
      if (cur_op == 2'd0 && count == READ - 1) begin
        data_out <= q[cur_addr];    // the end of a read: keep the bit
        busy     <= 1'b0;
      end else if (cur_op != 2'd0 && count == PULSE - 1) begin
        busy     <= 1'b0;           // the end of a write
      end
    end
  end
endmodule
clk
The clock: a signal that ticks every 10 ns. The controller does one small step per tick.
busy, count
While busy is 1, count counts the ticks: 8 for a write (80 ns), 4 for a read.
chosen
A 1 shifted to the chosen cell's position: only that cell gets the pulse.
always @(posedge clk)
"At every clock tick". The regs changed here (busy, count, ...) become flip-flops: tiny memories inside the logic.
2

Open a terminal

In the container desktop, click the terminal icon in the bottom panel.

3

Go to the memory's folder

Type these two commands, pressing Enter after each.

$ cd openMemristorPDK/digital/memory2x2
$ ls
4

Simulate the memory

make sim compiles and runs the test with Icarus Verilog, as in A digital twin in Verilog. Type clear and Enter first if you want an empty terminal.

$ make sim
What it showsThe controller wrote 1 0 0 1 into the four memristors and read it back, then changed cell 0 to 0. The same pattern as the crossbar, now driven by a circuit instead of by hand-made voltage pulses.
5

Turn it into gates

make synth runs Yosys on the controller.

$ make synth
How to read it The controller became 65 gates, all from IHP's library: sg13g2_nand2_1 is a 2-input NAND gate, sg13g2_nor2_1 a 2-input NOR, and so on. The 10 sg13g2_dfrbpq_1 are flip-flops: busy (1), count (4), the operation (2), the address (2) and data_out (1). 10 bits, 10 flip-flops. Chip area: 996 µm², a square about 32 µm wide, thinner than a hair. Half of it is the flip-flops. Only the controller becomes gates. The memristors stay memristors: they aren't logic.
mem_ctrl_gates.v (two of the 65 gates)Verilog, made by Yosys
  sg13g2_nand2_1 _049_ (
    .A(busy),
    .B(_020_),
    .Y(_022_)
  );
  sg13g2_dfrbpq_1 _098_ (
    .CLK(clk),
    .D(_004_),
    .Q(cur_op[0]),
    .RESET_B(1'h1)
  );
6

Simulate the gates

make gates synthesizes again, then runs the same test with the 65 gates instead of the original Verilog, using IHP's own models of each gate.

$ make gates
The same answers1 0 0 1, then 0: the gates do exactly what the Verilog said. This check is a normal step in real chip design.
7

Clean up and close

make clean deletes everything the other commands made. Then close the terminal.

$ make clean
$ exit