Scarab  v2.4.9
Project 8 C++ Utility Library
test_digital.cc
Go to the documentation of this file.
1 /*
2  * test_digital.cc
3  *
4  * Created on: Feb 15, 2019
5  * Author: N.S. Oblath
6  *
7  * Expected output (approximately for the floating-point side of the DAC tests)
8  *
9  * ADC Unsigned Test
10  * -0.1 --> 0
11  * 0 --> 0
12  * 0.1 --> 26
13  * 0.5 --> 128
14  * 0.9 --> 230
15  * 1 --> 255
16  * 1.1 --> 255
17  *
18  * ADC Signed Test
19  * -0.6 --> -128
20  * -0.5 --> -128
21  * -0.4 --> -102
22  * 0 --> 0
23  * 0.4 --> 102
24  * 0.5 --> 127
25  * 0.6 --> 127
26  *
27  * DAC Unsigned Test
28  * 0 --> 0
29  * 0 --> 0
30  * 26 --> 0.101562
31  * 128 --> 0.5
32  * 230 --> 0.898438
33  * 255 --> 0.996094
34  * 255 --> 0.996094
35  *
36  * DAC Signed Test
37  * -128 --> -0.5
38  * -128 --> -0.5
39  * -102 --> -0.398438
40  * 0 --> 0
41  * 102 --> 0.398438
42  * 127 --> 0.496094
43  * 127 --> 0.496094
44  *
45  */
46 
47 #include "digital.hh"
48 
49 #include <iostream>
50 #include <vector>
51 
52 using namespace scarab;
53 
54 int main()
55 {
56  std::cout << "ADC Unsigned Test" << std::endl;
57  // 8 bit digitized data
58  // V offset = 0 V
59  // V range = 1 V
60  // Expected analog data: varying between 0 V and 1 V
61  dig_calib_params t_params_1;
62  get_calib_params( 8, 1, 0., 1., true, &t_params_1 );
63 
64  std::vector< double > t_inputs_1{ -0.1, 0., 0.1, 0.5, 0.9, 1.0, 1.1 };
65  std::vector< unsigned > t_outputs_1;
66 
67  for( auto t_input : t_inputs_1 )
68  {
69  t_outputs_1.push_back( a2d< double, unsigned >( t_input, &t_params_1 ) );
70  std::cout << t_input << " --> " << t_outputs_1.back() << std::endl;
71  }
72 
73  std::cout << std::endl;
74 
75  std::cout << "ADC Signed Test" << std::endl;
76  // 8 bit digitized data
77  // V offset = 0 V
78  // V range = 1 V
79  // Expected analog data: symmetric about 0 V with maximum deviation of +/- 0.5 V
80 
81  dig_calib_params t_params_2;
82  get_calib_params( 8, 1, 0., 1., true, &t_params_2 );
83 
84  std::vector< double > t_inputs_2{ -0.6, -0.5, -0.4, 0., 0.4, 0.5, 0.6 };
85  std::vector< int > t_outputs_2;
86 
87  for( auto t_input : t_inputs_2 )
88  {
89  t_outputs_2.push_back( a2d< double, int >( t_input, &t_params_2 ) );
90  std::cout << t_input << " --> " << t_outputs_2.back() << std::endl;
91  }
92 
93  std::cout << std::endl;
94 
95  std::cout << "DAC Unsigned Test" << std::endl;
96  for( auto t_output : t_outputs_1 )
97  {
98  std::cout << t_output << " --> " << d2a< unsigned, double >( t_output, &t_params_1 ) << std::endl;
99  }
100 
101  std::cout << std::endl;
102 
103  std::cout << "DAC Signed Test" << std::endl;
104  for( auto t_output : t_outputs_2 )
105  {
106  std::cout << t_output << " --> " << d2a< signed, double >( t_output, &t_params_2 ) << std::endl;
107  }
108 
109  return 0;
110 }
111 
112 
Collection of parameters used for converting between analog and digital data.
Definition: digital.hh:43
int main()
Definition: test_digital.cc:54
void get_calib_params(unsigned n_bits, unsigned data_type_size, double v_offset, double v_range, bool bits_r_aligned, dig_calib_params *params)
Calculate the digitizer calibration parameters with basic parameters: number of bits, Voffset, and Vrange.
Definition: digital.cc:18