AlcapDAQ  1
Data Structures | Macros | Functions
X742CorrectionRoutines.h File Reference
#include <string.h>
#include "CAENDigitizer.h"

Go to the source code of this file.

Data Structures

struct  DataCorrection_t
 

Macros

#define MAX_X742_CHANNELS   0x08
 
#define MAX_X742_CHANNEL_SIZE   9
 
#define FLASH(n)   (0x10D0 | ( n << 8))
 
#define SEL_FLASH(n)   (0x10CC | ( n << 8))
 
#define STATUS(n)   (0x1088 | ( n << 8))
 
#define MAIN_MEM_PAGE_READ   0x00D2
 
#define MAIN_MEM_PAGE_PROG_TH_BUF1   0x0082
 

Functions

int32_t LoadCorrectionTables (int handle, DataCorrection_t *Table, uint8_t group, uint32_t frequency)
 
void ApplyDataCorrection (DataCorrection_t *CTable, CAEN_DGTZ_DRS4Frequency_t frequency, int CorrectionLevelMask, CAEN_DGTZ_X742_GROUP_t *data)
 

Macro Definition Documentation

#define FLASH (   n)    (0x10D0 | ( n << 8))

Definition at line 6 of file X742CorrectionRoutines.h.

Referenced by read_flash_page().

#define MAIN_MEM_PAGE_PROG_TH_BUF1   0x0082

Definition at line 10 of file X742CorrectionRoutines.h.

#define MAIN_MEM_PAGE_READ   0x00D2

Definition at line 9 of file X742CorrectionRoutines.h.

Referenced by read_flash_page().

#define MAX_X742_CHANNEL_SIZE   9

Definition at line 5 of file X742CorrectionRoutines.h.

#define MAX_X742_CHANNELS   0x08

Definition at line 4 of file X742CorrectionRoutines.h.

Referenced by LoadCorrectionTables().

#define SEL_FLASH (   n)    (0x10CC | ( n << 8))

Definition at line 7 of file X742CorrectionRoutines.h.

Referenced by read_flash_page().

#define STATUS (   n)    (0x1088 | ( n << 8))

Definition at line 8 of file X742CorrectionRoutines.h.

Referenced by read_flash_page().

Function Documentation

void ApplyDataCorrection ( DataCorrection_t CTable,
CAEN_DGTZ_DRS4Frequency_t  frequency,
int  CorrectionLevelMask,
CAEN_DGTZ_X742_GROUP_t data 
)

Definition at line 198 of file X742CorrectionRoutines.c.

References CAEN_DGTZ_DRS4_1GHz, CAEN_DGTZ_DRS4_2_5GHz, DataCorrection_t::cell, CAEN_DGTZ_X742_GROUP_t::ChSize, CAEN_DGTZ_X742_GROUP_t::DataChannel, i, MAX_X742_CHANNEL_SIZE, DataCorrection_t::nsample, PeakCorrection(), samples, CAEN_DGTZ_X742_GROUP_t::StartIndexCell, and DataCorrection_t::time.

198  {
199 
200  int i, j,rpnt = 0, wpnt = 0, size1, size2,trg = 0,k;
201  long samples;
202  float Time[1024],t0;
203  float Tsamp;
204  float vcorr;
205  uint16_t st_ind=0;
206  uint32_t freq = frequency;
207  float wave_tmp[1024];
208  int cellCorrection =CorrectionLevelMask & 0x1;
209  int nsampleCorrection = (CorrectionLevelMask & 0x2) >> 1;
210  int timeCorrection = (CorrectionLevelMask & 0x4) >> 2;
211 
212  switch(frequency) {
214  Tsamp =(float)((1.0/2500.0)*1000.0);
215  break;
216  case CAEN_DGTZ_DRS4_1GHz:
217  Tsamp =(float)((1.0/1000.0)*1000.0);
218  break;
219  default:
220  Tsamp =(float)((1.0/5000.0)*1000.0);
221  break;
222  }
223 
224  if (data->ChSize[8] != 0) trg = 1;
225  st_ind =(uint16_t)(data->StartIndexCell);
226  for (i=0;i<MAX_X742_CHANNEL_SIZE;i++) {
227  size1 = data->ChSize[i];
228 
229  for (j=0;j<size1;j++) {
230  if (cellCorrection) data->DataChannel[i][j] -= CTable->cell[i][((st_ind+j) % 1024)];
231  if (nsampleCorrection) data->DataChannel[i][j] -= CTable->nsample[i][j];
232  }
233  }
234 
235  if (cellCorrection) PeakCorrection(data);
236  if (!timeCorrection) return;
237 
238  t0 = CTable->time[st_ind];
239  Time[0]=0.0;
240 
241  for(j=1; j < 1024; j++) {
242  t0= CTable->time[(st_ind+j)%1024]-t0;
243  if (t0 >0)
244  Time[j] = Time[j-1]+ t0;
245  else
246  Time[j] = Time[j-1]+ t0 + (Tsamp*1024);
247 
248  t0 = CTable->time[(st_ind+j)%1024];
249  }
250  for (j=0;j<8+trg;j++) {
251  data->DataChannel[j][0] = data->DataChannel[j][1];
252  wave_tmp[0] = data->DataChannel[j][0];
253  vcorr = 0.0;
254  k=0;
255  i=0;
256 
257  for(i=1; i<1024; i++) {
258  while ((k<1024-1) && (Time[k]<(i*Tsamp))) k++;
259  vcorr =(((float)(data->DataChannel[j][k] - data->DataChannel[j][k-1])/(Time[k]-Time[k-1]))*((i*Tsamp)-Time[k-1]));
260  wave_tmp[i]= data->DataChannel[j][k-1] + vcorr;
261  k--;
262  }
263  memcpy(data->DataChannel[j],wave_tmp,1024*sizeof(float));
264  }
265 }
int32_t LoadCorrectionTables ( int  handle,
DataCorrection_t Table,
uint8_t  group,
uint32_t  frequency 
)

Definition at line 126 of file X742CorrectionRoutines.c.

References DataCorrection_t::cell, i, MAX_X742_CHANNELS, DataCorrection_t::nsample, read_flash_page(), and DataCorrection_t::time.

126  {
127  uint32_t pagenum = 0,i,n,j,start;
128  int8_t TempCell[264]; //
129  int8_t *p;
130  int ret;
131  int8_t tmp[0x1000]; // 256byte * 16 pagine
132  for (n=0;n<MAX_X742_CHANNELS+1;n++) {
133  pagenum = 0;
134  pagenum = (group %2) ? 0xC00: 0x800;
135  pagenum |= frequency << 8;
136  pagenum |= n << 2;
137  // load the Offset Cell Correction
138  p = TempCell;
139  start = 0;
140  for (i=0;i<4;i++) {
141  int endidx = 256;
142  if ((ret =read_flash_page(handle,group,p,pagenum)) != 0)
143  return ret;
144  // peak correction
145  for (j=start;j<(start+256);j++) {
146  if (p[j-start] != 0x7f) {
147  Table->cell[n][j] = p[j-start];
148  }
149  else {
150  short cel = (short)((((unsigned char)(p[endidx+1])) << 0x08) |((unsigned char) p[endidx]));
151  if (cel == 0) Table->cell[n][j] = p[j-start]; else Table->cell[n][j] = cel;
152  endidx+=2;
153  if (endidx > 263) endidx = 256;
154  }
155  }
156  start +=256;
157  pagenum++;
158  }
159  start = 0;
160  // load the Offset Num Samples Correction
161  p = TempCell;
162  pagenum &= 0xF00;
163  pagenum |= 0x40;
164  pagenum |= n << 2;
165 
166  for (i=0;i<4;i++) {
167  if ((ret =read_flash_page(handle,group,p,pagenum)) != 0)
168  return ret;
169  for (j=start;j<start+256;j++) Table->nsample[n][j] = p[j-start];
170  start +=256;
171  pagenum++;
172  }
173  if (n == MAX_X742_CHANNELS) {
174  // load the Time Correction
175  p = TempCell;
176  pagenum &= 0xF00;
177  pagenum |= 0xA0;
178  start = 0;
179  for (i=0;i<16;i++) {
180  if ((ret =read_flash_page(handle,group,p,pagenum)) != 0)
181  return ret;
182  for (j=start;j<start+256;j++) tmp[j] = p[j-start];
183  start +=256;
184  pagenum++;
185  }
186  for (i=0;i<1024;i++) {
187  p = (int8_t *) &(Table->time[i]);
188  p[0] = tmp[i*4];
189  p[1] = tmp[(i*4)+1];
190  p[2] = tmp[(i*4)+2];
191  p[3] = tmp[(i*4)+3];
192  }
193  }
194  }
195  return 0;
196 }