Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions D-flipflop with Notgate and Nand gates/NAND.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "NAND.h"

void NANDGATE:: NANDGATE_method (void){
c=(!(a&&b));
}

NANDGATE:: ~NANDGATE(){

}
19 changes: 19 additions & 0 deletions D-flipflop with Notgate and Nand gates/NAND.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <systemc.h>


SC_MODULE (NANDGATE){
sc_in <bool> a, b;
sc_out <bool> c;


void NANDGATE_method();
~NANDGATE();

SC_CTOR (NANDGATE){
SC_METHOD (NANDGATE_method);
sensitive <<a<<b;


};

};
Binary file added D-flipflop with Notgate and Nand gates/NAND.o
Binary file not shown.
24 changes: 24 additions & 0 deletions D-flipflop with Notgate and Nand gates/NOT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef INVERTER_H_
#define INVERTER_H_
#include<systemc.h>

SC_MODULE(NOT){

sc_in<bool> not_a;
sc_out<bool> not_b;

SC_CTOR(NOT){
SC_METHOD(invert);
sensitive<<not_a;

}

~NOT(){

}

void invert(void){
not_b=!not_a;
}
};
#endif /* INVERTER_H_ */
40 changes: 40 additions & 0 deletions D-flipflop with Notgate and Nand gates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Implementing a D-flipflop in systemc
A D-type flip-flop has two stable states and a delay in one clock cycle. They are used in many applications like in digital television.
It has two outputs where one is an inverse of the other and the input are either 0 or 1. This is either low or high voltage. The given clock synchronizes the circuit

# How it's made
The abstract implementation is made from a provided code base. What was added was the extra functionality for the design.
NAND gates were used where among the first sets was an inverter.
Signals were connected between all the four instances of NAND gates that were created. The output was routed to the monitor as well as the inputs in order to compare the two.

### Requirements
This project was made using the systemc c++ library. The library is required to implement the functionality of the code or even change it.
Running "make" requires you to have the program installed.
Building the program also checks if the software, gtkwave is installed and if it's not, then it may be installed as it's needed to graphically view the outputs.

### Running the program
Clone the repository from github to your drive using or download the zip file and paste it in the desired drive.
Extract the contents of the zip folder to the drive then run the code:
```sh
$ make all
```
NOTE: This must be done in the same drive.

### Cleaning up

```sh
$ make clean
```
## NOTES:
1. The .cc files contain the implementation of the modules included.
2. The .h files contain the declaration of the modules.
3. The .h files must be included in other files where the respective classes are needed to be implemented.
4. This project requires the systemC library to create and upgrade.
5. The base code for the D-flipflop module was acquired from a different github repository:

```sh
https://github.com/Muriukidavid/systemc-examples
```

### Conclusions
The desired output was visualized on the program, gtkwave. This is an indicator that the implementation of the D-flipflop indeed does work.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added D-flipflop with Notgate and Nand gates/dff
Binary file not shown.
10 changes: 10 additions & 0 deletions D-flipflop with Notgate and Nand gates/dff.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "dff.h"

void dff:: dff_method (void){
dout=din;

}

dff:: ~dff(){
//delete gt1;
}
52 changes: 52 additions & 0 deletions D-flipflop with Notgate and Nand gates/dff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <systemc.h>
#include "NOT.h"
#include "NAND.h"

SC_MODULE (dff) {
sc_in <bool> clk;
sc_in <bool> din;
sc_signal <bool> sig1, sig2, sig3, sig4, sig5;
sc_out <bool> 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();
};

};
Binary file added D-flipflop with Notgate and Nand gates/dff.o
Binary file not shown.
12 changes: 12 additions & 0 deletions D-flipflop with Notgate and Nand gates/driver.cc
Original file line number Diff line number Diff line change
@@ -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);

}

}
12 changes: 12 additions & 0 deletions D-flipflop with Notgate and Nand gates/driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <systemc.h>

SC_MODULE(driver){
sc_out<bool> d_din;

void drive(void);

SC_CTOR(driver){
SC_THREAD(drive);
}

};
Binary file added D-flipflop with Notgate and Nand gates/driver.o
Binary file not shown.
34 changes: 34 additions & 0 deletions D-flipflop with Notgate and Nand gates/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <systemc.h>
#include "dff.h"
#include "driver.h"
#include "monitor.h"



int sc_main(int argc, char* argv[])
{
sc_signal<bool> 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;
}
Binary file added D-flipflop with Notgate and Nand gates/main.o
Binary file not shown.
21 changes: 21 additions & 0 deletions D-flipflop with Notgate and Nand gates/makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions D-flipflop with Notgate and Nand gates/monitor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "monitor.h"
#include<iostream>

using namespace std;

void monitor::mon(void){
cout<<"at "<<sc_time_stamp()<<" input is: "<< m_din<<" and output is: "<<m_dout<<endl;
}
14 changes: 14 additions & 0 deletions D-flipflop with Notgate and Nand gates/monitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<systemc.h>

SC_MODULE(monitor){
sc_in<bool> m_din, m_dout;

void mon(void);

SC_CTOR(monitor){
SC_METHOD(mon);
sensitive<<m_din<<m_dout;
dont_initialize();

}
};
Binary file added D-flipflop with Notgate and Nand gates/monitor.o
Binary file not shown.
35 changes: 35 additions & 0 deletions D-flipflop with Notgate and Nand gates/vcd_trace.vcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$date
Jul 08, 2018 18:45:31
$end

$version
SystemC 2.3.2-Accellera --- May 15 2018 10:19:37
$end

$timescale
1 ns
$end

$scope module SystemC $end
$var wire 1 aaaaa Input_Signal $end
$var wire 1 aaaab Output_Signal $end
$upscope $end
$enddefinitions $end

$comment
All initial values are dumped below at time 0 sec = 0 timescale units.
$end

$dumpvars
1aaaaa
1aaaab
$end

#10
0aaaaa
0aaaab

#15
1aaaaa

#20
Binary file added decoder2by4_detailed/IMAGES/circuit.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decoder2by4_detailed/IMAGES/timing_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decoder2by4_detailed/IMAGES/truth_table.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions decoder2by4_detailed/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GTKWAVE:=$(which gtkwave)

all: decoder

decoder:prerequisites
@echo 'building file $(@F)'
$(CXX) -I/usr/local/systemc-2.3.2/include -O0 -g3 -Wall -c decoder2by4.cpp
$(CXX) -L/usr/local/systemc-2.3.2/lib-linux64 -o "decoder" decoder2by4.o -lsystemc
./decoder
gtkwave -c 4 timing_diagram.vcd

prerequisites:
ifneq "$(GTKWAVE)" "/usr/bin/gtkwave"
@echo 'installing gtkwave, please be patient'
sudo apt-get install -y gtkwave
endif

clean:
rm -f decoder *.o timing_diagram.vcd
.PHONY: decoder
41 changes: 41 additions & 0 deletions decoder2by4_detailed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
This is a 2-by-4 decoder with implementation of and logical gates. Its a makefile project and so no need for an IDE.
Just cd into this folder and run the command

make


A line decoder is a device that changes the input code into a set of signals.<br>
It takes an n-digit binary number and decodes it into 2<sup>n</sup> data lines.
It does the reverse of encoding. <br>
<p> 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.
</p>
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. <br>
Its truth table:
<p align="left">
<img src="IMAGES/truth_table.jpg" width="250"/>
</p>

###Circuit:
<p align="left">
<img src="IMAGES/circuit.jpg" width="200"/>
</p>

Model of computation:
<p align="left">
<img src="images/MoC.png" width="400"/>
</p>
Results:
The above MOC was implemented in systemc (code in this folder) and the following output found from traced signals.<br>
Traced signals timing diagram:
<p align="left">
<img src="IMAGES/timing_diagram.png" width="400"/>
<p>


# project1
# decoder
# project1
# project1
# decoder-2
# decoder-2
Loading