Skip to content

Commit b0f4f6c

Browse files
committed
Adding ADC module and its testbench
1 parent b262030 commit b0f4f6c

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

modules/dac/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
SRCDIR+=../../utils/src
5+
INCDIR+=-I$(SYSTEMC_AMS_HOME)/include -I../utils/include
6+
LIBDIR+=-L$(SYSTEMC_AMS_HOME)/lib-linux64
7+
LIBS+=-lsystemc-ams
8+
9+
# Defining preprocessor directive for debug
10+
ifdef IPS_DEBUG_EN
11+
CFLAGS += -DIPS_DEBUG_EN
12+
LFLAGS += -DIPS_DEBUG_EN
13+
endif # IPS_DEBUG_EN
14+
15+
# Defining preprocessor directive for dumping enable
16+
ifdef IPS_DUMP_EN
17+
CFLAGS += -DIPS_DUMP_EN
18+
LFLAGS += -DIPS_DUMP_EN
19+
endif # IPS_DUMP_EN
20+
21+
# Run the compiled file
22+
run:
23+
@./$(TARGET)
24+
25+
# Show waveform
26+
waveform:
27+
@gtkwave ips_dac.vcd

modules/dac/include/dac.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef IPS_DAC_MODEL_HPP
2+
#define IPS_DAC_MODEL_HPP
3+
4+
#include <systemc-ams.h>
5+
#include "vunit.hpp"
6+
7+
8+
template <unsigned int BITS = 8, int VMIN = 0, int VMAX = 5, VUnit VU = VUnit::v>
9+
SCA_TDF_MODULE(dac)
10+
{
11+
protected:
12+
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
13+
const double V_MIN = static_cast<double>(VMIN) / static_cast<double>(VU);
14+
const double MAX_DIG = static_cast<double>((1 << BITS) - 1);
15+
public:
16+
sca_tdf::sca_in<sc_dt::sc_uint<BITS> > in;
17+
sca_tdf::sca_out<double> out;
18+
19+
SCA_CTOR(dac) : in("in"), out("out") {
20+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
21+
}
22+
23+
void processing()
24+
{
25+
double dig_in = static_cast<double>(this->in.read().to_uint());
26+
double ana_out = V_MIN + (dig_in / MAX_DIG) * (V_MAX - V_MIN);
27+
28+
this->out.write(ana_out);
29+
}
30+
};
31+
#endif // IPS_DAC_MODEL_HPP

modules/dac/include/test_dac.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef IPS_TEST_DAC_HPP
2+
#define IPS_TEST_DAC_HPP
3+
4+
#include <cstdlib>
5+
6+
7+
template <unsigned int N>
8+
SCA_TDF_MODULE(test_dac) {
9+
public:
10+
sca_tdf::sca_out<sc_dt::sc_uint<N> > o_dig;
11+
12+
SCA_CTOR(test_dac) {
13+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
14+
}
15+
16+
void processing()
17+
{
18+
this->o_dig.write(static_cast<sc_dt::sc_uint<N> >(rand() % (1 << N)));
19+
}
20+
};
21+
22+
#endif // IPS_TEST_DAC_HPP

modules/dac/src/tb_dac.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <systemc-ams.h>
2+
#include "dac.hpp"
3+
#include "test_dac.hpp"
4+
5+
#define N 8
6+
7+
8+
int sc_main(int, char*[])
9+
{
10+
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig;
11+
sca_tdf::sca_signal<double> s_ana_out;
12+
13+
const int MAX_ITER = (1 << N) - 1;
14+
15+
dac<N> ips_dac("ips_dac");
16+
ips_dac.in(s_dig);
17+
ips_dac.out(s_ana_out);
18+
19+
test_dac<N> ips_test_dac("ips_test_dac");
20+
ips_test_dac.o_dig(s_dig);
21+
22+
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_dac");
23+
sca_util::sca_trace(tf, s_dig, "in");
24+
sca_util::sca_trace(tf, s_ana_out, "out");
25+
26+
sc_start(MAX_ITER * 0.1, SC_US);
27+
28+
sca_util::sca_close_vcd_trace_file(tf);
29+
30+
return 0;
31+
};

modules/utils/include/vunit.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef IPS_VUnit_HPP
2+
#define IPS_VUnit_HPP
3+
4+
enum class VUnit {
5+
v = 1,
6+
mv = 1000,
7+
uv = 1000000,
8+
};
9+
10+
#endif // IPS_VUnit_HPP

0 commit comments

Comments
 (0)