DRS4 Forum
  DRS4 Discussion Forum  Not logged in ELOG logo
Entry  Fri Dec 20 20:35:31 2024, Matias Henriquez, Problem with C++ script to use DRS4 evaluation board. Not taking data. 1.pngdrs_test.cpp
    Reply  Fri Dec 27 22:04:48 2024, Matias Henriquez, Problem with C++ script to use DRS4 evaluation board. Not taking data. 
       Reply  Mon Jan 6 12:52:23 2025, Stefan Ritt, Problem with C++ script to use DRS4 evaluation board. Not taking data. 
Message ID: 910     Entry time: Fri Dec 20 20:35:31 2024     Reply to this: 912
Author: Matias Henriquez 
Subject: Problem with C++ script to use DRS4 evaluation board. Not taking data. 

Hello,

I need to write a script in C++ to take data using the DRS4 evaluation board v4. For that, I used the drs_exam.cpp example as a reference. This is my code (see attachement 2), which is very similar to the provided example, however the difference is that I need to trigger on CH1 OR CH2. In the next version I will need to trigger with an OR in all channels.

The problem is, my code gets stuck in waiting for trigger or only 1 event occurs (event 0). I read that event and it doesn't even go above 30mV, which was the threshold I set. There are some questions I have:

  1. Why Transparent mode is activated for Hardware Trigger?
  2. Why EnableTCal is activated? is the drs4_exam example based acquires the 100MHz reference just for the sake of the example? or is just a time calibration routine?
  3. Can someone explain the function EnableTrigger(flag1,flag2) in boardType 8? it si not clear to me how the trigger is enabled.
  4. To check that my input signals are correct, I run the drsosc application and I can see the signals with no problem (see attachement 1). However I noticed that I had to configure the trigger delay in the drsosc application, and I don't do that in my c++ code. I will try that later.
  5. How do I perform voltage calibration and time calibration using the c++ functions?

 

Thank you so much for your help.

 

 

 

Attachment 1: 1.png  68 kB  | Hide | Hide all
1.png
Attachment 2: drs_test.cpp  5 kB  | Hide | Hide all
/********************************************************************\

  Name:         drs_exam.cpp
  Created by:   Stefan Ritt

  Contents:     Simple example application to read out a DRS4
               evaluation board

  $Id: drs_exam.cpp 21308 2014-04-11 14:50:16Z ritt $

\********************************************************************/

#include <math.h>

#ifdef _MSC_VER

#include <windows.h>

#elif defined(OS_LINUX)

#define O_BINARY 0

#include <unistd.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>

#define DIR_SEPARATOR '/'

#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "strlcpy.h"
#include "DRS.h"

/*------------------------------------------------------------------*/

int main()
{
   int i, j, nBoards;
   DRS *drs;
   DRSBoard *b;
   float time_array[8][1024];
   float wave_array[8][1024];
   FILE  *f;

   double domino_freq = 2; //Domino Ring Frequency = 2GHz
   double trigger_level_ch1 = 0.03; // Trigger level for channel 1
   double trigger_level_ch2 = 0.03; // Trigger level for channel 2
   //double trigger_level_ch3 = 0.01; // Trigger level for channel 3
   //double trigger_level_ch4 = 0.01; // Trigger level for channel 4

   int trigger_source_reg = (1<<0) + (1<<1);
   //int trigger_source_reg = (1<<0) + (1<<1) + (1<<2) + (1<<3);
   
   /* do initial scan */
   drs = new DRS();

   /* show any found board(s) */
   for (i=0 ; i<drs->GetNumberOfBoards() ; i++) {
      b = drs->GetBoard(i);
      printf("Found DRS4 evaluation board, serial #%d, firmware revision %d\n", 
         b->GetBoardSerialNumber(), b->GetFirmwareVersion());
   }

   /* exit if no board found */
   nBoards = drs->GetNumberOfBoards();
   if (nBoards == 0) {
      printf("No DRS4 evaluation board found\n");
      return 0;
   }

   /* continue working with first board only */
   b = drs->GetBoard(0);

   /* initialize board */
   b->Init();

   /* set sampling frequency */
   b->SetFrequency(domino_freq, true);

   /* enable transparent mode needed for analog trigger */
   b->SetTranspMode(0);

   /* set input range to -0.5V ... +0.5V */
   //b->SetInputRange(0.5);

   /* use following line to set range to 0..1V */
   b->SetInputRange(0.45);
   
   /* use following line to turn on the internal 100 MHz clock connected to all channels  */
   //b->EnableTcal(1);

   /* use following lines to enable hardware trigger on */
   if (b->GetBoardType() >= 8) {        // Evaluaiton Board V4&5
      b->EnableTrigger(1, 0);           // enable hardware trigger
      //b->SetTriggerSource(1<<0);        
   } else if (b->GetBoardType() == 7) { // Evaluation Board V3
      b->EnableTrigger(0, 1);           // lemo off, analog trigger on
      //b->SetTriggerSource(0);          
   }
   //b->SetTriggerLevel(0.05);            // 0.05 V
   b->SetTriggerPolarity(false);        // positive edge
   
   /* use following lines to set individual trigger elvels */
   b->SetIndividualTriggerLevel(1, trigger_level_ch1);
   b->SetIndividualTriggerLevel(2, trigger_level_ch2);
   //b->SetIndividualTriggerLevel(3, trigger_level_ch3);
   //b->SetIndividualTriggerLevel(4, trigger_level_ch4);
   //Set Trigger Configuration
   // OR Bit0 = CH1, Bit1 = CH2, Bit2 = CH3, Bit3 = CH4, Bit4 = EXT
   // AND Bit8 = CH1, Bit9 = CH2, Bit10 = CH3, Bit11 = CH4, Bit12 = EXT
   // TRANSP Bit15
   b->SetTriggerSource(trigger_source_reg); 
   
   b->SetTriggerDelayNs(0);             // zero ns trigger delay
   
   /* use following lines to enable the external trigger */
   //if (b->GetBoardType() == 8) {     // Evaluaiton Board V4
   //   b->EnableTrigger(1, 0);           // enable hardware trigger
   //   b->SetTriggerSource(1<<4);        // set external trigger as source
   //} else {                          // Evaluation Board V3
   //   b->EnableTrigger(1, 0);           // lemo on, analog trigger off
   // }

   /* open file to save waveforms */
   f = fopen("data.txt", "w");
   if (f == NULL) {
      perror("ERROR: Cannot open file \"data.txt\"");
      return 1;
   }
   
   /* repeat ten times */
   for (j=0 ; j<10 ; j++) {

      /* start board (activate domino wave) */
      b->StartDomino();

      /* wait for trigger */
      printf("Waiting for trigger...");
      
      fflush(stdout);
      while (b->IsBusy());

      /* read all waveforms */
      b->TransferWaves(0, 8);

      /* read time (X) array of first channel in ns */
      b->GetTime(0, 0, b->GetTriggerCell(0), time_array[0]);

      /* decode waveform (Y) array of first channel in mV */
      b->GetWave(0, 0, wave_array[0]);

      /* read time (X) array of second channel in ns
       Note: On the evaluation board input #1 is connected to channel 0 and 1 of
       the DRS chip, input #2 is connected to channel 2 and 3 and so on. So to
       get the input #2 we have to read DRS channel #2, not #1. */
      b->GetTime(0, 2, b->GetTriggerCell(0), time_array[1]);

      /* decode waveform (Y) array of second channel in mV */
      b->GetWave(0, 2, wave_array[1]);

      /* Save waveform: X=time_array[i], Yn=wave_array[n][i] */
      fprintf(f, "Event #%d ----------------------\n  t1[ns]  u1[mV]  t2[ns] u2[mV]\n", j);
      for (i=0 ; i<1024 ; i++)
         fprintf(f, "%7.3f %7.1f %7.3f %7.1f\n", time_array[0][i], wave_array[0][i], time_array[1][i], wave_array[1][i]);

      /* print some progress indication */
      printf("\rEvent #%d read successfully\n", j);
   }

   fclose(f);
   
   /* delete DRS object -> close USB connection */
   delete drs;
}
ELOG V3.1.5-3fb85fa6