Created
April 21, 2019 09:51
-
-
Save jdryg/f222fff09055898b5a9cf5e39afe408d to your computer and use it in GitHub Desktop.
CMOS inverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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