Skip to content

Commit

Permalink
update noise output
Browse files Browse the repository at this point in the history
  • Loading branch information
cbetanco committed Aug 7, 2018
1 parent d044eff commit 5969f4c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 45 deletions.
122 changes: 87 additions & 35 deletions Ana_tests.C
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,17 +105,20 @@ void Ana_tests::Get_run(string option, int runs, string outText) {

}

// vector<int> 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; i<runs; i++)
Expand All @@ -123,7 +127,8 @@ void Ana_tests::Get_run(string option, int runs, string outText) {
m_noise_rms = calculateSD(avg_chip, runs);

output_file(runs, avg_ADC, avg_chip, avg_noise, length_avg, outText, option);


//cout << "test4" << endl;
}

// creates output file with run(s) results
Expand Down Expand Up @@ -168,17 +173,22 @@ bool Ana_tests::Baseline_corr() {
// set commom baseline to all channels
salt_->write_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++) {
Expand All @@ -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;


}

Expand Down Expand Up @@ -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++) {

Expand All @@ -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++) {
Expand All @@ -312,28 +345,47 @@ void Ana_tests::adc_output() {
}

// make histogram
// vector<int> 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<int> 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] <i+1) counter++;

// }

// hist.push_back(counter);

// }
//cout << "defining histo" << endl;
//cout << "size is " << size << endl;
//cout << "start is " << start << endl;

//for(int i=0; i < 128; i++)
//for(int j=0; j < 64; j++)
// adc_hist[i][j]=0;

if(start+bins > 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) {
Expand Down
8 changes: 5 additions & 3 deletions Ana_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Fpga.h"
#include "fastComm.h"
#include <fstream>
#include <vector>
//#include <vector>

using namespace std;

Expand All @@ -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<int> 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<int> m_hist[128];
int m_hmin;
int m_bins;
Expand All @@ -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<int> hist;
bool Check_PedS();
bool Check_MCMS();
Expand Down
12 changes: 5 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -194,15 +189,18 @@ 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;
}
// ana_func->Check_Gain();
}




/*
Salt *st = new Salt();
Expand Down

0 comments on commit 5969f4c

Please sign in to comment.