Skip to content

Commit 5ca3318

Browse files
committed
Adding documentation for ADC module and its testbench
1 parent f8f9d8f commit 5ca3318

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

modules/adc/include/adc.hpp

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

77

8+
/**
9+
* @brief Analog to Digital Converter module representation
10+
* This module generates a N-bit digital signal based on the [Vmin, Vmax]
11+
* voltage 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>
9-
SCA_TDF_MODULE(dac)
19+
SCA_TDF_MODULE(adc)
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 analog voltage
1630
sca_tdf::sca_in<double> in;
31+
// Output digital code
1732
sca_tdf::sca_out<sc_dt::sc_uint<BITS> > out;
1833

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

43+
/**
44+
* @brief Convert the analog signal into digital signal
45+
* The analog signal in a range from Vmin to Vmax is converted into a N-bit
46+
* digital signal
47+
*
48+
*/
2349
void processing()
2450
{
51+
2552
double normalized_ana_in = (in.read() - V_MIN) / (V_MAX - V_MIN);
2653
unsigned int dig_code = static_cast<unsigned int>(normalized_ana_in * MAX_DIG);
2754

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
#ifndef IPS_TEST_ADC_HPP
2-
#define IPS_TEST_ADC_HPP
1+
#ifndef IPS_SEQ_ITEM_ADC_HPP
2+
#define IPS_SEQ_ITEM_ADC_HPP
33

44
#include <cstdlib>
55

66

7+
/**
8+
* @brief This class is used to generate the analog signal for the test
9+
*
10+
* @tparam N
11+
*/
712
template <unsigned int N>
8-
SCA_TDF_MODULE(test_adc) {
13+
SCA_TDF_MODULE(seq_item_adc)
14+
{
915
public:
1016
sca_tdf::sca_out<double> o_ana;
1117
const int MAX_CODE = (1 << N);
1218

13-
SCA_CTOR(test_adc) {
19+
SCA_CTOR(seq_item_adc)
20+
{
1421
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
1522
}
1623

@@ -20,4 +27,4 @@ SCA_TDF_MODULE(test_adc) {
2027
}
2128
};
2229

23-
#endif // IPS_TEST_ADC_HPP
30+
#endif // IPS_SEQ_ITEM_ADC_HPP

modules/adc/src/tb_adc.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
#include <systemc-ams.h>
22
#include "adc.hpp"
3-
#include "test_adc.hpp"
3+
#include "seq_item_adc.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<double> s_ana;
1115
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig_out;
1216

13-
const int MAX_ITER = (1 << N) - 1;
14-
15-
dac<N> ips_adc("ips_adc");
17+
// DUT
18+
adc<N> ips_adc("ips_adc");
1619
ips_adc.in(s_ana);
1720
ips_adc.out(s_dig_out);
1821

19-
test_adc<N> ips_test_adc("ips_test_adc");
20-
ips_test_adc.o_ana(s_ana);
22+
// Sequence item generator for ADC
23+
seq_item_adc<N> ips_seq_item_adc("ips_seq_item_adc");
24+
ips_seq_item_adc.o_ana(s_ana);
2125

26+
// Dump waveform
2227
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_adc");
2328
sca_util::sca_trace(tf, s_ana, "in");
2429
sca_util::sca_trace(tf, s_dig_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

0 commit comments

Comments
 (0)