diff --git a/D-flipflop with Notgate and Nand gates/NAND.cc b/D-flipflop with Notgate and Nand gates/NAND.cc new file mode 100644 index 0000000..a44e6cc --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/NAND.cc @@ -0,0 +1,9 @@ +#include "NAND.h" + +void NANDGATE:: NANDGATE_method (void){ +c=(!(a&&b)); +} + +NANDGATE:: ~NANDGATE(){ + +} diff --git a/D-flipflop with Notgate and Nand gates/NAND.h b/D-flipflop with Notgate and Nand gates/NAND.h new file mode 100644 index 0000000..3b6309d --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/NAND.h @@ -0,0 +1,19 @@ +#include + + +SC_MODULE (NANDGATE){ + sc_in a, b; + sc_out c; + + +void NANDGATE_method(); +~NANDGATE(); + +SC_CTOR (NANDGATE){ + SC_METHOD (NANDGATE_method); + sensitive < + +SC_MODULE(NOT){ + + sc_in not_a; + sc_out not_b; + + SC_CTOR(NOT){ + SC_METHOD(invert); + sensitive< +#include "NOT.h" +#include "NAND.h" + +SC_MODULE (dff) { + sc_in clk; + sc_in din; + sc_signal sig1, sig2, sig3, sig4, sig5; + sc_out dout; + + + NANDGATE nand1; + NANDGATE nand2; + NANDGATE nand3; + NANDGATE nand4; + NOT notgt; + + void dff_method(void); + ~dff(); + SC_CTOR (dff): nand1("Instance1"), + nand2("Instance2"), + nand3("Instance3"), + nand4("Instance4"), + notgt("not gate instance") + + { + + notgt.not_a(din); + notgt.not_b(sig1); + + nand1.a(din); + nand1.b(clk); + nand1.c(sig2); + + nand2.a(clk); + nand2.b(sig1); + nand2.c(sig3); + + nand3.a(sig2); + nand3.b(sig5); + nand3.c(sig4); + + nand4.a(sig4); + nand4.b(sig3); + nand4.c(sig5); + + + SC_METHOD (dff_method); + sensitive << clk.pos(); +}; + +}; diff --git a/D-flipflop with Notgate and Nand gates/dff.o b/D-flipflop with Notgate and Nand gates/dff.o new file mode 100644 index 0000000..7475996 Binary files /dev/null and b/D-flipflop with Notgate and Nand gates/dff.o differ diff --git a/D-flipflop with Notgate and Nand gates/driver.cc b/D-flipflop with Notgate and Nand gates/driver.cc new file mode 100644 index 0000000..c4c002b --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/driver.cc @@ -0,0 +1,12 @@ +#include "driver.h" + +void driver::drive(void){ + while(1){ + d_din = 1; + wait(10,SC_NS); + d_din = 0; + wait(5,SC_NS); + + } + +} diff --git a/D-flipflop with Notgate and Nand gates/driver.h b/D-flipflop with Notgate and Nand gates/driver.h new file mode 100644 index 0000000..883311d --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/driver.h @@ -0,0 +1,12 @@ +#include + +SC_MODULE(driver){ + sc_out d_din; + + void drive(void); + + SC_CTOR(driver){ + SC_THREAD(drive); + } + +}; diff --git a/D-flipflop with Notgate and Nand gates/driver.o b/D-flipflop with Notgate and Nand gates/driver.o new file mode 100644 index 0000000..3df5cf2 Binary files /dev/null and b/D-flipflop with Notgate and Nand gates/driver.o differ diff --git a/D-flipflop with Notgate and Nand gates/main.cpp b/D-flipflop with Notgate and Nand gates/main.cpp new file mode 100644 index 0000000..e1b3c70 --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/main.cpp @@ -0,0 +1,34 @@ +#include +#include "dff.h" +#include "driver.h" +#include "monitor.h" + + + +int sc_main(int argc, char* argv[]) +{ + sc_signal s_din, s_dout; + sc_clock clock("clk",10,SC_NS,0.5); + + dff dff1("dff"); + driver dr("driver"); + monitor mon("monitor"); + + dr.d_din(s_din); + dff1.din(s_din); + mon.m_din(s_din); + + dff1.dout(s_dout); + mon.m_dout(s_dout); + + dff1.clk(clock); + + sc_trace_file *fp; + fp=sc_create_vcd_trace_file("vcd_trace"); + fp->set_time_unit(1, SC_NS); + sc_trace(fp, s_din, "Input_Signal"); + sc_trace(fp, s_dout, "Output_Signal"); + sc_start(20, SC_NS); + sc_close_vcd_trace_file(fp); + return 0; +} diff --git a/D-flipflop with Notgate and Nand gates/main.o b/D-flipflop with Notgate and Nand gates/main.o new file mode 100644 index 0000000..dcbec2f Binary files /dev/null and b/D-flipflop with Notgate and Nand gates/main.o differ diff --git a/D-flipflop with Notgate and Nand gates/makefile b/D-flipflop with Notgate and Nand gates/makefile new file mode 100644 index 0000000..551a432 --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/makefile @@ -0,0 +1,21 @@ +GTKWAVE:=$(which gtkwave) +all: dff + +dff: + @echo 'building file $(@F)' + $(CXX) -I/usr/local/systemc-2.3.2/include -O0 -g3 -Wall -c dff.cc driver.cc monitor.cc NAND.cc main.cpp + $(CXX) -L/usr/local/systemc-2.3.2/lib-linux64 -o "dff" dff.o driver.o monitor.o NAND.o main.o -lsystemc + ./dff + gtkwave -c 4 vcd_trace.vcd + + +prerequisites: +ifneq ('$(GTKWAVE)', "/usr/bin/gtkwave") + @echo 'installing gtkwave, please be patient' + sudo apt-get install -y gtkwave +endif + + +clean: + rm -f dff *.o vcd_trace.vcd +.PHONY: dff diff --git a/D-flipflop with Notgate and Nand gates/monitor.cc b/D-flipflop with Notgate and Nand gates/monitor.cc new file mode 100644 index 0000000..ee5f9a9 --- /dev/null +++ b/D-flipflop with Notgate and Nand gates/monitor.cc @@ -0,0 +1,8 @@ +#include "monitor.h" +#include + +using namespace std; + +void monitor::mon(void){ + cout<<"at "< + +SC_MODULE(monitor){ + sc_in m_din, m_dout; + + void mon(void); + + SC_CTOR(monitor){ + SC_METHOD(mon); + sensitive< +It takes an n-digit binary number and decodes it into 2n data lines. +It does the reverse of encoding.
+

There are 4 AND gates.A new module is created called and_gate and included in the file .cpp with the main function. Two instances of the module are created in the main function. +

+In the following truth table, only the output D0 is high when the both inputs zero, the output D1 is high when the the first input is zero and the second input is 1, the output D2 is high when input A0 is 1 and A1 is one and the output D3 is high when both inputs are high. it decodes a two digit binary number. +Only one signal is high(selected) when the right binary number is available on the input.
+Its truth table: +

+ +

+ +###Circuit: +

+ +

+ +Model of computation: +

+ +

+Results: +The above MOC was implemented in systemc (code in this folder) and the following output found from traced signals.
+Traced signals timing diagram: +

+ +

+ + +# project1 +# decoder +# project1 +# project1 +# decoder-2 +# decoder-2 diff --git a/decoder2by4_detailed/andgate.h b/decoder2by4_detailed/andgate.h new file mode 100644 index 0000000..dc755dd --- /dev/null +++ b/decoder2by4_detailed/andgate.h @@ -0,0 +1,42 @@ +/* + * andGates.h + * + * Created on: May 22, 2018 + * Author: ruthie + */ +#ifndef ANDGATES_H_ +#define ANDGATES_H_ +#include + +SC_MODULE(and_gate){ +//input and output ports + +sc_in a, b; +sc_out c; + + +//constructor: where the processes are bound to simulation kernel +SC_CTOR(and_gate){ + SC_METHOD(gate); + sensitive << a << b; + //dont_initialize(); +} + +~and_gate(){ +//delete stuff :P +} + +void gate(void){ + c = a && b; +} +}; + + + + +#endif /* AND_GATE_H_ */ + + + + + diff --git a/decoder2by4_detailed/decoder b/decoder2by4_detailed/decoder new file mode 100644 index 0000000..608ad23 Binary files /dev/null and b/decoder2by4_detailed/decoder differ diff --git a/decoder2by4_detailed/decoder2by4.cpp b/decoder2by4_detailed/decoder2by4.cpp new file mode 100644 index 0000000..4bb30b9 --- /dev/null +++ b/decoder2by4_detailed/decoder2by4.cpp @@ -0,0 +1,85 @@ +/* + * decoder_2by4.cpp + * + * Created on: May 22, 2018 + * Author: ruthie + */ +#include "../decoder1by2/decoder_1by2.h" +#include "driver.h" +#include "andgate.h" +#include "monitor.h" +#include + +int sc_main(int argc, char *argv[]){ +//some signals for interconnections + +sc_signal ini,inj,in1,in2,in3,in4, out1, out2,out3,out4; +//modules instances +driver dr("driver"); +and_gate and1("gate_instance_1"); +and_gate and2("gate_instance_2"); +and_gate and3("gate_instance_3"); +and_gate and4("gate_instance_4"); +decoder dec1_0("decoder"); +decoder dec1_1("decoder_instance"); + +monitor mn("monitor"); +//interconnections between modules +dr.d_a(ini); +dr.d_b(inj); + +mn.m_a(ini); +mn.m_b(inj); + +dec1_0.a(ini); +dec1_1.a(inj); + +dec1_0.b(in1); +dec1_0.c(in2); +dec1_1.b(in3); +dec1_1.c(in4); + + +and1.a(in1); +and1.b(in3); +and1.c(out1); + +and2.a(in1); +and2.b(in4); +and2.c(out2); + +and3.a(in2); +and3.b(in3); +and3.c(out3); + +and4.a(in2); +and4.b(in4); +and4.c(out4); + +mn.m_c(out1); +mn.m_d(out2); +mn.m_e(out3); +mn.m_f(out4); + + +//create a trace file with nanosecond resolution +sc_trace_file *tf;//class trace instantiated with a pointer(stores the address of a variable) +tf = sc_create_vcd_trace_file("timing_diagram"); +tf->set_time_unit(1, SC_NS);// signal sampled after every nano second +//trace the signals interconnecting modules +sc_trace(tf, ini, "binary_input1"); // signals to be traced +sc_trace(tf, inj, "binary_input2"); // signals to be traced +sc_trace(tf, out1, "output_1"); +sc_trace(tf, out2, "output_2"); +sc_trace(tf, out3, "output_3"); +sc_trace(tf, out4, "outout_4"); + +//run a simulation for 20 systemc nano-seconds +if( !sc_pending_activity() ) +sc_start(20,SC_NS); +//close the trace file +sc_close_vcd_trace_file(tf); +return 0; +} + + diff --git a/decoder2by4_detailed/decoder2by4.o b/decoder2by4_detailed/decoder2by4.o new file mode 100644 index 0000000..c4e49dc Binary files /dev/null and b/decoder2by4_detailed/decoder2by4.o differ diff --git a/decoder2by4_detailed/driver.h b/decoder2by4_detailed/driver.h new file mode 100644 index 0000000..46dee8b --- /dev/null +++ b/decoder2by4_detailed/driver.h @@ -0,0 +1,42 @@ +/* + * driver.h + * + * Created on: May 22, 2018 + * Author: ruthie + */ +#ifndef DRIVER_H_ +#define DRIVER_H_ + +#include + +SC_MODULE(driver){ +sc_out d_a,d_b; + +SC_CTOR(driver){ + SC_THREAD(drive); +} + +void drive(void){ + while(1){ + d_a=0; + d_b=0; + wait(5,SC_NS); + d_a=0; + d_b=1; + wait(5,SC_NS); + d_a=1; + d_b=0; + wait(5,SC_NS); + d_a=1; + d_b=1; + wait(5,SC_NS); + } +} +}; +#endif /* DRIVE2_H_ */ + + + + + + diff --git a/decoder2by4_detailed/monitor.h b/decoder2by4_detailed/monitor.h new file mode 100644 index 0000000..b4defdf --- /dev/null +++ b/decoder2by4_detailed/monitor.h @@ -0,0 +1,32 @@ +/* + * monitor.h + * + * Created on: May 22, 2018 + * Author: ruthie + */ +#ifndef MONITOR_H_ +#define MONITOR_H_ +#include +#include + +using namespace std; + +SC_MODULE(monitor){ +sc_in m_a, m_b, m_c, m_d, m_e, m_f; + +SC_CTOR(monitor){ + SC_METHOD(monita); + sensitive<