Instructions
  • This activity helps you build a SPICE code for a D-Latch step by step.
  • Each colored code block below is a part of the final code. Fill in the blanks in each block.
  • Arrange the blocks in the correct order (see steps below).
  • Click Validate to check your code. If correct, you will see a report and graphs.
  • Click Reset to start over. Click View PTM_45nm.txt to see the MOSFET model file.
Steps to Build Your Code:
  1. Model File: Add the MOSFET model file and set parameters.
  2. Voltage Source: Define the voltage source for your circuit.
  3. Subcircuits: Describe the inverter, pass transistor, and 2:1 mux subcircuits and their connections.
  4. D-Latch Subcircuit: Define the D-Latch subcircuit using the above subcircuits.
  5. Instantiate Subcircuit: Use the D-Latch subcircuit in your main code.
  6. Input Waveform: Set up the input signals for simulation.
  7. Control Statements: Add commands to run and plot the simulation.
  8. End: Finish your SPICE code.
Spice Code
  • .include


    * Parameter Declarations

    .PARAM supply=1.1
    .PARAM Lmin=45nm
    .PARAM Wmin=45nm
    .PARAM Wp={2*Wmin}
    .global vdd gnd

  • * Netlist statement to define voltage source

     

  • * Defining the inverter subcircuit
    .subckt inverter in out
    MP1 out in vdd vdd pmos w={Wmin} L={Lmin}
    Mn1 out in 0 0 NMOS W={Wmin} L={Lmin}
    .ends inverter

    * Defining the pass transistor subcircuit
    .subckt pass_transistor control in out
    Xinv control not inverter
    MP1 out not in vdd pmos w={Wp} L={Lmin}
    MN1 out control in 0 nmos W={Wmin} L={Lmin}
    .ends

    * Defining the 2:1 MUX subcircuit
    .subckt mux a b s out
    Xinvs s s_ inverter
    Xpt1 s_ a out pass_transistor
    Xpt2 s b out pass_transistor
    .ends

  • * Define sub-circuit

    .subckt       
          inverter
          inverter
              mux
    .ends

  • *netlist statement to call the gate sub circuit *gate inputs are 'a', 'b' and the gate output is 'out'

           

  • *Declaring Input Waveform
    .PARAM trfin=10p
    .PARAM t1 = 10n
    .PARAM t2 = 20n
    .PARAM t3 = 30n
    .PARAM t4 = 40n
    *Transient Analysis
    .tran 6p 100n

    *Use below line for input (declaring input pwl Waveform)
    *'V1' is the PWL source name, 'a', 'clk' are the input names

    V1 a 0 PWL (0 0 't1' 0 't2' 0 't2+trfin' 'supply' 't3' 'supply' 't4' 'supply')
    V2 clk 0 PWL (0 0 't1' 0 't1+trfin' 'supply' 't2' 'supply' 't3' 'supply' 't3+trfin' 0 't4' 0 )
  • *Control Statements
    .control
    run

    *plots inputs
    plot v(a) v(clk)

    *plots output
    plot v(out)

    .endc
  • *End of the code
    .end
Observations