-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseline_corr.cpp
191 lines (153 loc) · 4.68 KB
/
baseline_corr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "I2C.h"
#include "ExternalADC.h"
#include <iostream>
#include "Fpga.h"
#include "CurrentMonitor.h"
#include "Salt.h"
#include "fastComm.h"
#include "Dig_Clk_test.h"
#include "Ana_tests.h"
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
#include "socal/alt_gpio.h"
int main(int argc, char *argv[])
{
// ExternalADC *adc1115 = new ExternalADC(0b01001000,0b11110011,0b11110011);
/*ExternalADC *adc1115 = new ExternalADC(0b01001000,1);
adc1115->access_device();
uint16_t adc_counts = 0;
double v = 0;
adc1115->read_adc(&adc_counts);
adc1115->inVolts(&adc_counts, &v);
*/
/*
uint32_t data = 0;
printf("DATA 0: 0x%08x\n",data);
Fpga *fpga = new Fpga();
fpga->read_fpga(0x00010040,&data);
uint32_t direction = 0x0f000000;
fpga->write_fpga((uint32_t)ALT_GPIO1_SWPORTA_DDR_ADDR,direction);
fpga->write_fpga((uint32_t)ALT_GPIO1_SWPORTA_DR_ADDR,direction);
printf("DATA 1: 0x%08x\n",data);
*/
/*
uint8_t dataW = strtoul( argv[ 1 ], NULL, 0 );
uint8_t register_add = strtoul( argv[ 2 ], NULL, 0 );
uint8_t r_w = 0;
r_w = strtoul( argv[ 3 ], NULL, 0 );
I2C *salt = new I2C(1,0x50);
salt->access_device();
uint8_t data = 0;
if(r_w==0){
salt->read_buffer(register_add, &data);
printf("DATA before write: 0x%02x in 0x%02x\n",data,register_add);
//uint16_t dataW = 0x05;
salt->write_buffer(register_add, dataW);
salt->read_buffer(register_add, &data);
printf("DATA after write: 0x%02x in 0x%02x\n",data,register_add);
}
if(r_w==1){
salt->read_buffer(register_add, &data);
printf("DATA: 0x%02x in 0x%02x\n",data,register_add);
}
if(r_w==2){
salt->write_buffer(register_add, dataW);
}
*/
//Example how to define different configuration
// but this config is default one as well
/*
uint16_t cur_counts = 0;
float amp = 0;
CurrentMonitor *cur1 = new CurrentMonitor(1,0b01000000);
cur1->access_device();
cur1->set_config_bits(0b00011111,0b00000100);
cur1->set_calib_bits(0b00000000,0b00100000);
cur1->define_setup();
cur1->read_current(&cur_counts);
cur1->convert_to_amp(&cur_counts,&);
printf("Monitor 1: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
CurrentMonitor *cur2 = new CurrentMonitor(1,0b01000001);
cur2->access_device();
cur2->set_config_bits(0b00011111,0b00000100);
cur2->set_calib_bits(0b00000000,0b00100000);
cur2->define_setup();
cur2->read_current(&cur_counts);
cur1->convert_to_amp(&cur_counts,&);
printf("Monitor 2: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
*/
// initial definitions
Fpga *fpga = new Fpga();
Salt *st = new Salt(1,5);
FastComm *fastComm = new FastComm(fpga);
Dig_Clk_test *dig_com = new Dig_Clk_test(fpga,st,fastComm);
Ana_tests *ana_func = new Ana_tests(fpga,st,fastComm);
/*
cout << "I2C check:" << endl;
if(dig_com->I2C_check())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
cout << "DLL configuration:" << endl;
if(dig_com->DLL_Check())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
cout << "PLL configuration:" << endl;
if(dig_com->PLL_Check())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
cout << "FPGA-DAQ sync:" << endl;
if(dig_com->DAQ_Sync())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
// reset TFC
dig_com->TFC_Reset();
// Synch between DSR and TFC
cout << "DSR and TFC synch:" << endl;
if(dig_com->TFC_DAQ_sync())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
cout << "TFC commands check:" << endl;
if(dig_com->TFC_Command_Check())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
// Do baseline corr
*/
cout << "Baseline corrections:" << endl;
if(ana_func->Baseline_corr())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
/*
cout << "Pedestal substraction:" << endl;
if(ana_func->Check_PedS())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
cout << "Mean Common Mode Subtraction:" << endl;
if(ana_func->Check_MCMS())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
// Get noise
cout << "Noise MCMS run:" << endl;
if(ana_func->Get_noise(100,"MCMS","NZS"))
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
// ana_func->Check_Gain();
cout << "done " << endl;
/*
Salt *st = new Salt();
uint8_t data = 0;
st->read_salt(0b101,0, &data);
printf(" 0x%02x \n",data);
*/
return 0;
}