- A Logic Circuit Simulation Library in C++ |
This example will illustrate the propogation through the off-the-shelf NOT gates provided in libLCS. Two NOT gates with the clock pulse as inputs are set up. One of the NOT gates has a propogation delay which is more than the clock pulse width, and the other has a propogation delay which is less than clock pulse width. Since the propogation delay is inertial, the NOT gate with propogation delay more than the clock pulse width does not respond to the input clock pulse.
#include <lcs/not.h> #include <lcs/clock.h> #include <lcs/simul.h> #include <lcs/changeMonitor.h> using namespace lcs; int main() { Bus<> s1(1), s2(1); Clock clk = Clock::getClock(); Clock::setPulseWidth(5); // Initialising an NOT gate with a propogation delay of // three system time units. This delay is less than the // pulse width of the clock signal. Not<3> n1(s1, clk); // Initialising an NOT gate with a propogation delay of // seven system time units. This delay is more than the // pulse width of the clock signal. Not<7> n2(s2, clk); // Initialising change monitors to monitor the output of // the two AND gates. ChangeMonitor<> s1m(s1, "Output 1"), s2m(s2, "Output 2"); Simulation::setStopTime(50); Simulation::start(); return 0; }
The following is the output when the above program is compiled and run is as follows.
At time: 8, Output 1: 0 At time: 13, Output 1: 1 At time: 18, Output 1: 0 At time: 23, Output 1: 1 At time: 28, Output 1: 0 At time: 33, Output 1: 1 At time: 38, Output 1: 0 At time: 43, Output 1: 1 At time: 48, Output 1: 0