Skip to content

Commit f8f9d8f

Browse files
committed
Adding documentation for DAC module and its testbench
1 parent a759b7b commit f8f9d8f

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

modules/dac/include/dac.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,48 @@
55
#include "vunit.hpp"
66

77

8+
/**
9+
* @brief Digital to Analog Converter module representation
10+
* This module generates an analog signal based on the [Vmin, Vmax] voltage
11+
* range
12+
*
13+
* @tparam BITS - the number of output bits of the digital code
14+
* @tparam VMIN - lowest voltage value
15+
* @tparam VMAX - highest voltage value
16+
* @tparam VU - voltage unit based on VUnit
17+
*/
818
template <unsigned int BITS = 8, int VMIN = 0, int VMAX = 5, VUnit VU = VUnit::v>
919
SCA_TDF_MODULE(dac)
1020
{
1121
protected:
12-
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
22+
// Min voltage value based on the voltage units
1323
const double V_MIN = static_cast<double>(VMIN) / static_cast<double>(VU);
24+
// Max voltage value based on the voltage units
25+
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
26+
// Max digital output code
1427
const double MAX_DIG = static_cast<double>((1 << BITS) - 1);
1528
public:
29+
// Input digital code
1630
sca_tdf::sca_in<sc_dt::sc_uint<BITS> > in;
31+
// Output analog voltage
1732
sca_tdf::sca_out<double> out;
1833

19-
SCA_CTOR(dac) : in("in"), out("out") {
34+
/**
35+
* @brief Construct a new dac object
36+
*
37+
*/
38+
SCA_CTOR(dac) : in("in"), out("out")
39+
{
40+
// Propagation time from input to output
2041
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
2142
}
2243

44+
/**
45+
* @brief Convert the digital signal into analog signal
46+
* The N-bit digital code is converted into an analog signal in a voltage
47+
* range from Vmin to Vmax
48+
*
49+
*/
2350
void processing()
2451
{
2552
double dig_in = static_cast<double>(this->in.read().to_uint());
@@ -28,4 +55,5 @@ SCA_TDF_MODULE(dac)
2855
this->out.write(ana_out);
2956
}
3057
};
58+
3159
#endif // IPS_DAC_MODEL_HPP
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
#ifndef IPS_TEST_DAC_HPP
2-
#define IPS_TEST_DAC_HPP
1+
#ifndef IPS_SEQ_ITEM_DAC_HPP
2+
#define IPS_SEQ_ITEM_DAC_HPP
33

44
#include <cstdlib>
55

66

7+
/**
8+
* @brief This class is used to generate the digital code for the test
9+
*
10+
* @tparam N
11+
*/
712
template <unsigned int N>
8-
SCA_TDF_MODULE(test_dac) {
13+
SCA_TDF_MODULE(seq_item_dac)
14+
{
915
public:
1016
sca_tdf::sca_out<sc_dt::sc_uint<N> > o_dig;
1117

12-
SCA_CTOR(test_dac) {
18+
SCA_CTOR(seq_item_dac)
19+
{
1320
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
1421
}
1522

@@ -19,4 +26,4 @@ SCA_TDF_MODULE(test_dac) {
1926
}
2027
};
2128

22-
#endif // IPS_TEST_DAC_HPP
29+
#endif // IPS_SEQ_ITEM_DAC_HPP

modules/dac/src/tb_dac.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
#include <systemc-ams.h>
22
#include "dac.hpp"
3-
#include "test_dac.hpp"
3+
#include "seq_item_dac.hpp"
44

55
#define N 8
66

77

88
int sc_main(int, char*[])
99
{
10+
// Max number of sequence items to test
11+
const int MAX_SEQ_ITEMS = (1 << N) - 1;
12+
13+
// Signals to connect
1014
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig;
1115
sca_tdf::sca_signal<double> s_ana_out;
1216

13-
const int MAX_ITER = (1 << N) - 1;
14-
17+
// DUT
1518
dac<N> ips_dac("ips_dac");
1619
ips_dac.in(s_dig);
1720
ips_dac.out(s_ana_out);
1821

19-
test_dac<N> ips_test_dac("ips_test_dac");
20-
ips_test_dac.o_dig(s_dig);
22+
// Sequence item generator for DAC
23+
seq_item_dac<N> ips_seq_item_dac("ips_seq_item_dac");
24+
ips_seq_item_dac.o_dig(s_dig);
2125

26+
// Dump waveform
2227
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_dac");
2328
sca_util::sca_trace(tf, s_dig, "in");
2429
sca_util::sca_trace(tf, s_ana_out, "out");
2530

26-
sc_start(MAX_ITER * 0.1, SC_US);
31+
// Start time
32+
std::cout << "@" << sc_time_stamp() << std::endl;
33+
34+
// Run test
35+
sc_start(MAX_SEQ_ITEMS * 0.1, SC_US);
36+
37+
// End time
38+
std::cout << "@" << sc_time_stamp() << std::endl;
2739

2840
sca_util::sca_close_vcd_trace_file(tf);
2941

modules/utils/include/vunit.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#ifndef IPS_VUnit_HPP
22
#define IPS_VUnit_HPP
33

4+
5+
/**
6+
* @brief Presents the voltage units
7+
*
8+
*/
49
enum class VUnit {
10+
// Normal volts
511
v = 1,
12+
// Milivolts
613
mv = 1000,
14+
// Microvolts
715
uv = 1000000,
816
};
917

0 commit comments

Comments
 (0)