From c50129d5cbf0351541a0a10a690f8bad78a135e5 Mon Sep 17 00:00:00 2001 From: cbetanco Date: Fri, 3 Aug 2018 14:26:23 +0200 Subject: [PATCH] seperated tests into seperate arguments --- Ana_tests.C | 153 ++++++++++------------ Ana_tests.h | 9 +- Dig_Clk_test.C | 8 +- Salt.cpp | 2 +- fastComm.C | 46 ++++--- main.cpp | 346 ++++++++++++++++++++++++++----------------------- 6 files changed, 292 insertions(+), 272 deletions(-) diff --git a/Ana_tests.C b/Ana_tests.C index 92ab5d8..5cd44e4 100644 --- a/Ana_tests.C +++ b/Ana_tests.C @@ -104,13 +104,15 @@ void Ana_tests::Get_run(string option, int runs, string outText) { } - // cout << "test 0" << endl; + // vector h1; + + for(int i = 0; i < 128; i++) { m_avg_adc[i] = avg_ADC[i]; - //cout << "test" << endl; m_std_dev[i] = calculateSD(ADC_runs[i], runs); - //cout << "test 2 "<< endl; - + //h1 = histogram(m_hmin,m_bins,ADC_runs[i],runs); + //m_hist[i]=h1; + //h1.clear(); } m_noise = 0; @@ -221,9 +223,8 @@ bool Ana_tests::Baseline_corr() { // check noise functionality of chip. Specify run number and data output stream type, i.e. masked ch ("MASK"), sync ch ("SYNC"), after ped sub ("PEDS"), after mcm("MCMS"), and either Normal or NZS data packet -void Ana_tests::Get_noise(int runs, string data_type, string option) { +bool Ana_tests::Get_noise(int runs, string data_type, string option) { - //option = "NZS"; string outText; uint8_t buffer=0x00; @@ -234,8 +235,7 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) { // DSP output salt_->write_salt(registers::ser_source_cfg,(uint8_t) 0x20); - // loop over different data streams, i.e. masked ADC, sync ADC, after ped, after mcms - + // check which data stream is selected if(data_type == "MASK") buffer = 0x00; else if(data_type == "SYNC") @@ -246,6 +246,7 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) { buffer = 0x60; else { cout << "ERROR:: Data stream not properly defined" << endl; + return false; } salt_->write_salt(registers::n_zs_cfg, buffer); @@ -260,32 +261,78 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) { else { cout <<"ERROR::n_zs_cfg not properly defined" << endl; - return; + return false; } // Do Normal packet Get_run(option,runs,outText); - for(int i = 0; i < 128; i++) { + + cout << "NOISE = " << m_noise << " +- " << m_noise_rms << endl; + salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0); + + //m_hmin=-10; + //m_bins=20; + + adc_output(); + return true; + + +} + +void Ana_tests::adc_output() { + + for(int i = 0; i < 128; i++) { + cout << showpos<< fixed << setprecision(3) << m_avg_adc[i] << "\t"; - - } - cout << endl; - for(int i = 0; i < 128; i++) { + } + cout << endl; + + for(int i = 0; i < 128; i++) { + + cout << showpos << fixed << setprecision(3) << m_std_dev[i] << "\t"; + + } + cout << endl; + + // cout << m_hmin << endl << m_bins << endl; + // for(int i = 0; i < 128; i++) { + + // for(int j = 0; j < m_bins; j++) { + + // cout << setprecision(3) << m_hist[i].at(j) << "\t"; - cout << showpos << fixed << setprecision(3) << m_std_dev[i] << "\t"; + // } + // cout << endl; + // } +} + +// make histogram +vector Ana_tests::histogram(int start, int bins, int data[], int size) { + + int counter = 0; + vector hist; + + for (int i = start; i < (start + bins); i++) { + + counter = 0; + + for(int j=0; j< size; j++) { + + if(data[j]>=i && data[j] write_salt(registers::n_zs_cfg, (uint8_t) 0); + hist.push_back(counter); + + } + return hist; - } // checks mcmch and mcm_v @@ -486,7 +533,7 @@ void Ana_tests::Check_Gain() { salt_->write_salt(registers::calib_enable0_cfg,(uint8_t) 0x0F); salt_->write_salt(registers::calib_clk_cfg, (uint8_t) 0x20); - //Get_run("Calib",1,true,"test_pulse"); + //Get_run("Calib",1,"test_pulse"); salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0x60); salt_->write_salt(registers::calib_volt_cfg, (uint8_t) 31); @@ -510,74 +557,10 @@ void Ana_tests::Check_Gain() { } salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0); - */ } + */ -bool Ana_tests::Get_Quad_Coef(float x[], float y[], int PointsNum, float &a, float &b, float &c) { - - - const double S00=PointsNum;//points number - double S40=0, S10=0, S20=0, S30=0, S01=0, S11=0, S21 = 0; - double value = 0, indexPow2 = 0; - const double MINvalue = y[0]; - const double MINtime = x[0]; - int index = -1; - for (int i=0; i +#include using namespace std; @@ -23,17 +24,23 @@ class Ana_tests { void output_file(int runs, float avg_ADC[], float avg_chip[], float avg_noise, float length_avg, string outText, string option); void Trim_dac_scan(); void Check_Gain(); - void Get_noise(int runs, string data_type, string option); + bool Get_noise(int runs, string data_type, string option); bool Check_NZS(); bool Baseline_corr(); float calculateSD(float data[], int runs); float calculateSD(int data[], int runs); + void adc_output(); + vector histogram(int start, int bins, int data[], int size); + //vector m_hist[128]; + int m_hmin; + int m_bins; float m_avg_adc[128]; float m_std_dev[128]; float m_noise; float m_noise_rms; int m_mcm_ch; int m_mcm_v; + // vector hist; bool Check_PedS(); bool Check_MCMS(); bool Check_MCMS(float ADC[128], int mcm1, int mcm2, int mcm_ch, int mcm_v); diff --git a/Dig_Clk_test.C b/Dig_Clk_test.C index a6bc96c..3a2af8e 100644 --- a/Dig_Clk_test.C +++ b/Dig_Clk_test.C @@ -413,7 +413,8 @@ bool Dig_Clk_test::TFC_Command_Check() { // set synch pattern registers salt_->write_salt(registers::sync1_cfg,(uint8_t) 0x8C); salt_->write_salt(registers::sync0_cfg,(uint8_t) 0xAB); - + + // check TFC commands string option[8]; bool pass[8] = {false}; @@ -438,16 +439,17 @@ bool Dig_Clk_test::TFC_Command_Check() { else if(option[i] == "BxVeto") command[79] = 0x10; else if(option[i] == "Snapshot") command[79] = 0x20; else if(option[i] == "Synch") command[79] = 0x40; + + fastComm_->Take_a_run(length_read, data_string, length, 0, command, period, singleShot, true ); for(int j=0; jread_twelveBits(data_string, j); if(twelveBits == 0x0F0) continue; fastComm_->read_Header(twelveBits, bxid, parity, flag, length1); - if(flag == 0) { if(option[i] == "Normal") pass[i] = true; if(option[i] == "BXReset" && bxid == 0) pass[i] = true; diff --git a/Salt.cpp b/Salt.cpp index a39e378..f9ecb68 100644 --- a/Salt.cpp +++ b/Salt.cpp @@ -4,7 +4,7 @@ Salt::Salt(int8_t bus_number,int8_t device_address) : I2C( bus_number, device_address) { - std::cout << "SALT open bus" << std::endl; + // std::cout << "SALT open bus" << std::endl; this->open_bus(); } Salt::~Salt(){} diff --git a/fastComm.C b/fastComm.C index 1f01d5e..31c0c96 100644 --- a/fastComm.C +++ b/fastComm.C @@ -222,24 +222,28 @@ void FastComm::read_daq(uint8_t length, uint32_t (&packet)[5120]) string FastComm::read_daq(uint8_t length) { - uint64_t data; - stringstream data_stream; - // clock_t begin, end;// = clock(); - for(uint i = 0; i < length; i++) - { - fpga_->read_fpga(registers::DAQ_READ0, &data); - // begin = clock(); - data_stream << hex << arrange_Elinks(data); - // end=clock(); - //packet[i]=data; - - } - //double elapsed_sec = double(end - begin) / CLOCKS_PER_SEC; - // cout << "I2C time: " << elapsed_sec << " seconds" << endl; - //cout << "test data stream = " << data_stream.str() << endl; - return data_stream.str(); - // arrange_Elinks(data); - + uint64_t data; + stringstream data_stream; + // clock_t begin, end;// = clock(); + for(uint i = 0; i < length; i++) + { + + fpga_->read_fpga(registers::DAQ_READ0, &data); + // begin = clock(); + + data_stream << hex << arrange_Elinks(data); + // end=clock(); + + //packet[i]=data; + + } + //double elapsed_sec = double(end - begin) / CLOCKS_PER_SEC; + // cout << "I2C time: " << elapsed_sec << " seconds" << endl; + //cout << "test data stream = " << data_stream.str() << endl; + + return data_stream.str(); + // arrange_Elinks(data); + } @@ -288,16 +292,18 @@ void FastComm::Take_a_run(uint16_t length_read, uint32_t (&packet)[5120], uint8_ void FastComm::Take_a_run(uint16_t length_read, string &data, uint8_t length, uint8_t clock_delay, uint8_t command[], uint8_t period, bool singleShot, bool tfc_trig) { - + // string data_stream; this->config_daq(length_read, clock_delay, tfc_trig); //if (tfc_trig) + this->config_tfc(length, command, period, singleShot); + this->Launch_ACQ(tfc_trig); + data = this->read_daq(length_read); - //cout <<"this is a test" << endl; //cout << "string is " << data << endl; //read_NZS_packet(data_stream); reset_DAQ(); diff --git a/main.cpp b/main.cpp index 8f375d2..2eb25a7 100755 --- a/main.cpp +++ b/main.cpp @@ -12,182 +12,204 @@ #include "socal/socal.h" #include "socal/hps.h" #include "socal/alt_gpio.h" +#include +#include 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); + // 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){ + */ + /* + 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); -} -*/ - - - -//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); -*/ - + + 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 << "FAIL" << endl; - - cout << "DLL configuration:" << endl; - if(dig_com->DLL_Check()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; + vector arg; + + if(argc == 1) { + + cout << "ERROR::MUST PROVIDE AN ARGUMENT!!!" << endl; + return 0; + } + + for(int i=1; i < argc; i++) + arg.push_back(argv[i]); + + + for(int i=0; i < arg.size(); i++) { + if( (arg.at(i)== "i2c") || (arg.at(i) == "all")) { + cout << "I2C check:" << endl; + if(dig_com->I2C_check()) + cout << "SUCCESS!" << endl << "PASSED!" << endl; + else + cout << "FAIL" << endl << "FAILED" << endl; + } + + if( (arg.at(i)== "dll_pll") || (arg.at(i) == "all")) { + cout << "DLL and PLL configuration:" << endl; + if(dig_com->DLL_Check() && dig_com->PLL_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; + } + + if( (arg.at(i) == "fpga_daq_sync") || (arg.at(i) == "all")) { + cout << "FPGA-DAQ sync:" << endl; + if(dig_com->DAQ_Sync()) + cout << "SUCCESS!" << endl << "PASSED!" << endl; + else + cout << "FAIL" << endl << "FAILED" << endl; + } + if( (arg.at(i) == "dsr_tfc_sync") || (arg.at(i) == "all")) { + // 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; + } + if( (arg.at(i) == "tfc_cmd") || (arg.at(i) == "all")) { + 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 + if( (arg.at(i) == "baseline_corr") || (arg.at(i) == "all")) { + cout << "Baseline corrections:" << endl; + if(ana_func->Baseline_corr()) + cout << "SUCCESS!" << endl << "PASSED!" << endl; + else + cout << "FAIL" << endl << "FAILED" << endl; + } + + if( (arg.at(i) == "pedestal") || (arg.at(i) == "all")) { + cout << "Pedestal substraction:" << endl; + if(ana_func->Check_PedS()) + cout << "SUCCESS!" << endl << "PASSED!" << endl; + else + cout << "FAIL" << endl << "FAILED" << endl; + } + + if( (arg.at(i) == "mcms") || (arg.at(i) == "all")) { + cout << "Mean Common Mode Subtraction:" << endl; + if(ana_func->Check_MCMS()) + cout << "SUCCESS!" << endl << "PASSED!" << endl; + else + cout << "FAIL" << endl << "FAILED" << endl; + } + + // Get noise + if( (arg.at(i) == "noise_run") || (arg.at(i) == "all")) { + 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 << "PLL configuration:" << endl; - if(dig_com->PLL_Check()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; - - cout << "FPGA-DAQ sync:" << endl; - if(dig_com->DAQ_Sync()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << 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 << "FAIL" << endl; - - cout << "TFC commands check:" << endl; - if(dig_com->TFC_Command_Check()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; - // Do baseline corr - - cout << "Baseline corrections:" << endl; - if(ana_func->Baseline_corr()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; - cout << "Pedestal substraction:" << endl; - if(ana_func->Check_PedS()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; - - - cout << "MCMS:" << endl; - if(ana_func->Check_MCMS()) - cout << "SUCCESS!" << endl << "PASSED!" << endl; - else - cout << "FAIL" << endl << "FAIL" << endl; - /* - ana_func->Get_noise(100,"SYNC","Normal"); - ana_func->Get_noise(100,"PEDS","Normal"); - ana_func->Get_noise(100,"MCMS","Normal"); - - ana_func->Get_noise(100,"SYNC","NZS"); - ana_func->Get_noise(100,"PEDS","NZS"); + Salt *st = new Salt(); + uint8_t data = 0; + st->read_salt(0b101,0, &data); + printf(" 0x%02x \n",data); */ - - // Get noise - ana_func->Get_noise(100,"MCMS","NZS"); - - - // 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; + return 0; + }