Skip to main content.

Read CAEN C414 TDC values

Read values are in nanoseconds, and out-of-range channels have a blinking warning.
The example assumes that a C414 (TDC unit by CAEN) is present on slot 14.

-- definiton of labels for inputs 1-4
inp1_label  = "channel 1: "
inp2_label  = "channel 2: "
inp3_label  = "channel 3: "
inp4_label  = "channel 4: "

-- In this example, C414 is in slot 14 (slots are numbered 1 to 24)
slot = 14

-- In this example, we use inputs 1,2,3,4
-- (inputs on C414 are numbered 0 to 7, on front panel from 1 to 8 !!)
inp1 = 0
inp2 = 1
inp3 = 2
inp4 = 3

-- In this example, C414 is set with 200 ns full-scale range
TDC_range = 200

-- miscellaneous parameters
mydelay = 500
ovr_msg = "OUT OF RANGE"

-- crate initialization and clear
CCCC()
CCCZ()

-- infinite loop to read TDC
while (1) do

  doevents();

  -- clear C414
  CSSA(9,slot,0,0)
  pause(mydelay);

  -- read input values
  q,inp1_value = CSSA(0,slot,inp1,0);
  q,inp2_value = CSSA(0,slot,inp2,0);
  q,inp3_value = CSSA(0,slot,inp3,0);
  q,inp4_value = CSSA(0,slot,inp4,0);

  -- convert read values to time (ns)
  inp1_time = (inp1_value/4095)*TDC_range
  inp2_time = (inp2_value/4095)*TDC_range
  inp3_time = (inp3_value/4095)*TDC_range
  inp4_time = (inp4_value/4095)*TDC_range

  -- assemble strings for proper display in HTML
  if inp1_time < TDC_range then
     str1 = format("%s<b>%d%s </b>",inp1_label,inp1_time," ns")
  else
     str1 = format("%s<b><blink> %s </blink></b>",inp1_label,ovr_msg)
  end

  if inp2_time < TDC_range then
     str2 = format("%s<b>%d%s </b>",inp2_label,inp2_time," ns")
  else
     str2 = format("%s<b><blink> %s </blink></b>",inp2_label,ovr_msg)
  end

  if inp3_time < TDC_range then
     str3 = format("%s<b>%d%s </b>",inp3_label,inp3_time," ns")
  else
     str3 = format("%s<b><blink> %s </blink></b>",inp3_label,ovr_msg)
  end

  if inp4_time < TDC_range then
     str4 = format("%s<b>%d%s </b>",inp4_label,inp4_time," ns")
  else
     str4 = format("%s<b><blink> %s </blink></b>",inp4_label,ovr_msg)
  end

  display = format ("%s<br>%s<br>%s<br>%s", str1,str2,str3,str4);
  web_setuser(display);

end