Skip to content

Instantly share code, notes, and snippets.

@jdryg
Created April 21, 2019 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdryg/f222fff09055898b5a9cf5e39afe408d to your computer and use it in GitHub Desktop.
Save jdryg/f222fff09055898b5a9cf5e39afe408d to your computer and use it in GitHub Desktop.
CMOS inverter
require('mossim');
function init(component)
component.addInput("A", 1);
component.addOutput("Ab", 1);
m = mos();
local Vdd = mosInput(m, kState1);
local Gnd = mosInput(m, kState0);
Nin = mosInput(m, kStateX);
Nout = mosNode(m);
local Tp = mosTransistor(m, kTransistorTypeP, Nin, Vdd, Nout);
local Tn = mosTransistor(m, kTransistorTypeN, Nin, Nout, Gnd);
mosSimulate(m);
end
function simulate(inputs)
mosSetInputState(m, Nin, inputs[1] == 1 and kState1 or (inputs[1] == 0 and kState0 or kStateX));
mosSimulate(m);
mosDumpState(m);
local out = mosGetNodeState(m, Nout);
local res = { out == kState1 and 1 or (out == kState0 and 0 or V_UNDEFINED) };
return {
{
t = 1, -- Simulation time at which this batch of signals has been generated (must be greater than 0).
outputs = res -- The array of output signals for this timestep. One entry for each output pin.
}
};
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment