Scarab  v2.4.2
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 
8 #include "digital.hh"
9 
10 #include <iostream>
11 #include <vector>
12 
13 using namespace scarab;
14 
15 int main()
16 {
17  std::cout << "ADC Unsigned Test" << std::endl;
18  dig_calib_params t_params_1;
19  get_calib_params( 8, 1, 0., 1., true, &t_params_1 );
20 
21  std::vector< double > t_inputs_1{ -0.1, 0., 0.1, 0.5, 0.9, 1.0, 1.1 };
22  std::vector< unsigned > t_outputs_1;
23 
24  for( auto t_input : t_inputs_1 )
25  {
26  t_outputs_1.push_back( a2d< double, unsigned >( t_input, &t_params_1 ) );
27  std::cout << t_input << " --> " << t_outputs_1.back() << std::endl;
28  }
29 
30  std::cout << std::endl;
31 
32  std::cout << "ADC Signed Test" << std::endl;
33  dig_calib_params t_params_2;
34  get_calib_params( 8, 1, -0.5, 1., true, &t_params_2 );
35 
36  std::vector< double > t_inputs_2{ -0.6, -0.5, -0.4, 0., 0.4, 0.5, 0.6 };
37  std::vector< int > t_outputs_2;
38 
39  for( auto t_input : t_inputs_2 )
40  {
41  t_outputs_2.push_back( a2d< double, int >( t_input, &t_params_2 ) );
42  std::cout << t_input << " --> " << t_outputs_2.back() << std::endl;
43  }
44 
45  std::cout << std::endl;
46 
47  std::cout << "DAC Unsigned Test" << std::endl;
48  for( auto t_output : t_outputs_1 )
49  {
50  std::cout << t_output << " --> " << d2a< unsigned, double >( t_output, &t_params_1 ) << std::endl;
51  }
52 
53  std::cout << std::endl;
54 
55  std::cout << "DAC Signed Test" << std::endl;
56  for( auto t_output : t_outputs_2 )
57  {
58  std::cout << t_output << " --> " << d2a< signed, double >( t_output, &t_params_2 ) << std::endl;
59  }
60 
61  return 0;
62 }
63 
64 
int main()
Definition: test_digital.cc:15
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)
Definition: digital.cc:18