From 5969f4c70ea333df013d6a9f6c56bc48c3964793 Mon Sep 17 00:00:00 2001 From: cbetanco Date: Tue, 7 Aug 2018 11:37:01 +0200 Subject: [PATCH] update noise output --- Ana_tests.C | 122 +++++++++++++++++++++++++++++++++++++--------------- Ana_tests.h | 8 ++-- main.cpp | 12 +++--- 3 files changed, 97 insertions(+), 45 deletions(-) diff --git a/Ana_tests.C b/Ana_tests.C index fdf11b8..fccd6de 100644 --- a/Ana_tests.C +++ b/Ana_tests.C @@ -40,6 +40,7 @@ void Ana_tests::Get_run(string option, int runs, string outText) { int parity = 0; int mem_space = 0; int flag = 0; + int length1= 0; unsigned twelveBits; length_read = 255; @@ -104,17 +105,20 @@ void Ana_tests::Get_run(string option, int runs, string outText) { } - // vector h1; - - + + m_hmin = -10; + m_bins = 20; + for(int i = 0; i < 128; i++) { m_avg_adc[i] = avg_ADC[i]; m_std_dev[i] = calculateSD(ADC_runs[i], runs); - //h1 = histogram(m_hmin,m_bins,ADC_runs[i],runs); - //m_hist[i]=h1; + histogram(m_hmin,m_bins,ADC_runs[i],runs, i); + //h1.clear(); } - + + + m_noise = 0; for(int i=0; iwrite_salt(registers::ana_g_cfg, (uint8_t) 0X84); + + //cout << "blah" << endl; //get a number of runs for each baseline value for(int i = 0; i < 256 ; i++) { - + //cout << "testing" << endl; // baseline value written to salt salt_->write_salt(registers::baseline_g_cfg,(uint8_t) i); Get_run("NZS",10,"no_output"); + //cout << "trim dac = " << i << endl; for(int j = 0; j < 128; j++) adc_base[j][i] = m_avg_adc[j]; - + + //cout << "done" << endl; } + cout << "test5" << endl; // loop over all baseline values and channels and find best value (lowest abs(ADC)) for(int j = 0; j < 128; j++) { for(int i=0; i<256; i++) { @@ -196,28 +206,34 @@ bool Ana_tests::Baseline_corr() { // write best value to salt register salt_->write_salt((registers::baseline0_cfg) + j,(uint8_t) baseline[j]); - + //cout << "ch " << j << " set" << endl; } - + + //cout << "test 6" << endl; // write best trim dac setting to file outfile << "AVG = " << avg_baseline << endl; outfile << "STD_DEV = " << calculateSD(baseline,128) << endl; for(int i = 0; i < 128; i++) outfile << dec << baseline[i] << endl; - + + //cout << "test 7 " << endl; // close output files outfile.close(); + //cout << "test 7.1 " << endl; trimdac_scan.close(); + + //cout << "test8" << endl; // revert to individual baseline value for each channel salt_->write_salt(registers::ana_g_cfg, (uint8_t) 0X04); - // cout << "baseline 1 "<< endl; + //cout << "baseline 1 "<< endl; if(avg_baseline == 0) return false; return true; + } @@ -273,16 +289,19 @@ bool Ana_tests::Get_noise(int runs, string data_type, string option) { cout << "NOISE = " << m_noise << " +- " << m_noise_rms << endl; salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0); - //m_hmin=-10; - //m_bins=20; + m_hmin=-10; + m_bins=20; - adc_output(); + //adc_output(); return true; } -void Ana_tests::adc_output() { +void Ana_tests::adc_output(int min, int bins) { + + + int hist[m_bins]; for(int i = 0; i < 128; i++) { @@ -297,6 +316,20 @@ void Ana_tests::adc_output() { } cout << endl; + + cout << noshowpos << dec << min << endl; + cout << bins << endl; + + + + for(int i = 0; i < 128; i++) { + + for(int j=min+32; j< min+32+bins; j++) { + cout << adc_hist[i][j] << "\t"; + + } + cout << endl; + } // cout << m_hmin << endl << m_bins << endl; // for(int i = 0; i < 128; i++) { @@ -312,28 +345,47 @@ void Ana_tests::adc_output() { } // make histogram -// vector Ana_tests::histogram(int start, int bins, int data[], int size) { +void Ana_tests::histogram(int start, int bins, int data[], int size, int ch) { -// int counter = 0; -// vector hist; - -// for (int i = start; i < (start + bins); i++) { - -// counter = 0; - -// for(int j=0; j< size; j++) { + start=start+32; + int counter = 0; + //int hist[64] = {0}; + //adc_hist[ch]=hist; -// if(data[j]>=i && data[j] 64) { + cout << "ERROR::Histogram defined to be out of range" << endl; + return; + } + + for (int i = start; i < (start + bins); i++) { -// return hist; + counter = 0; + + for(int j=0; j< size; j++) { -// } + + // cout << "data[" << dec << j << "] = " << data[j] << endl; + // cout << "i = " << dec << i << endl; + if((data[j]>=(i-32)) && (data[j] <(i+1-32))) counter++; + + } + //cout << "counter is " << counter << endl; + + adc_hist[ch][i]=counter; + + } + + + +} // checks mcmch and mcm_v bool Ana_tests::Check_MCMS(float ADC[128], int mcm1, int mcm2, int mcm_ch, int mcm_v) { diff --git a/Ana_tests.h b/Ana_tests.h index 50aabce..4bd424c 100644 --- a/Ana_tests.h +++ b/Ana_tests.h @@ -8,7 +8,7 @@ #include "Fpga.h" #include "fastComm.h" #include -#include +//#include using namespace std; @@ -29,8 +29,8 @@ class Ana_tests { 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); + void adc_output(int min, int bins); + void histogram(int start, int bins, int data[], int size, int ch); //vector m_hist[128]; int m_hmin; int m_bins; @@ -40,6 +40,8 @@ class Ana_tests { float m_noise_rms; int m_mcm_ch; int m_mcm_v; + // int m_hist[128]; + int adc_hist[128][64]; // vector hist; bool Check_PedS(); bool Check_MCMS(); diff --git a/main.cpp b/main.cpp index 2eb25a7..a45ea2a 100755 --- a/main.cpp +++ b/main.cpp @@ -133,12 +133,7 @@ adc1115->inVolts(&adc_counts, &v); 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")) { @@ -194,8 +189,10 @@ adc1115->inVolts(&adc_counts, &v); // 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")) + if(ana_func->Get_noise(100,"MCMS","NZS")) { cout << "SUCCESS!" << endl << "PASSED!" << endl; + ana_func->adc_output(-10,20); + } else cout << "FAIL" << endl << "FAILED" << endl; } @@ -203,6 +200,7 @@ adc1115->inVolts(&adc_counts, &v); } + /* Salt *st = new Salt();