cms-gem-daq-project / ctp7_modules

0 stars 13 forks source link

#100 : added 5 modules to read SCAADC sensors #120

Closed ram1123 closed 5 years ago

ram1123 commented 5 years ago

Added modules to read a specific SCA ADC or the similar type of SCA SCA sensors together, like temperature, voltage, etc.

Description

There are 31 SCA ADC sensors defined (here). As requested in issue #100, to create several function to read each ADC and all ADC, I added five different functions named readSCAADCSensor, readSCAADCTemperatureSensors, readSCAADCVoltageSensors, readSCAADCSignalStrengthSensors and readAllSCAADCSensors to read individual sensors, temperature sensors, voltage related sensors, signal strength sensors and all sensors, respectively.

Types of changes

Motivation and Context

How Has This Been Tested?

All added modules are tested using a macro named blaster.cxx.

#include <iostream>
#include <fstream>
#include <random>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <xhal/rpc/wiscrpcsvc.h>

using namespace wisc;

int main(int argc, char *argv[])
{
  RPCSvc rpc;
  try {
    rpc.connect(argv[1]);
  } catch (RPCSvc::ConnectionFailedException &e) {
    printf("Caught RPCErrorException: %s\n", e.message.c_str());
    return 1;
  } catch (RPCSvc::RPCException &e) {
    printf("Caught exception: %s\n", e.message.c_str());
    return 1;
  }

#define STANDARD_CATCH                                                  \
  catch (RPCSvc::NotConnectedException &e) {                            \
    printf("Caught NotConnectedException: %s\n", e.message.c_str());    \
    return 1;                                                           \
  } catch (RPCSvc::RPCErrorException &e) {                              \
    printf("Caught RPCErrorException: %s\n", e.message.c_str());        \
    return 1;                                                           \
  } catch (RPCSvc::RPCException &e) {                                   \
    printf("Caught exception: %s\n", e.message.c_str());                \
    return 1;                                                           \
  }

#define ASSERT(x) do {                                                  \
    if (!(x)) {                                                         \
      printf("Assertion Failed on line %u: %s\n", __LINE__, #x);        \
      return 1;                                                         \
    }                                                                   \
  } while (0)

  RPCMsg req, rsp;

  try {
    ASSERT(rpc.load_module("amc", "amc v1.0.1"));
  } STANDARD_CATCH;

  //req = RPCMsg("amc.readSCAADCSensor");
  req = RPCMsg("amc.readSCAADCTemperatureSensors");

  //errno = 0;
  //uint32_t sz = strtoul(argv[2], nullptr, 16);

  //if (errno != 0 /*|| *p != '\0'*/ || sz > INT_MAX) {
  //  errno = 0;
  //  sz = strtoul(argv[2], nullptr, 10);
  //  if (errno != 0 /*|| *p != '\0'*/ || sz > INT_MAX) {
  //    sz = 0;
  //  } else {
  //    // pass
  //  }
  //} else {
  //  // pass
  //}

  errno = 0;
  uint32_t ty = strtoul(argv[2], nullptr, 16);

  if (errno != 0 /*|| *p != '\0'*/ || ty > INT_MAX) {
    ty = 0;
  } else {
    // pass
  }

  //req.set_word("ch",  sz);
  req.set_word("ohMask",ty);

  try {
    std::cout << "calling amc.readSCAADCTemperatureSensors on " << std::string(argv[1]) << " with " << ty << "...";
    //std::cout << "calling amc.readSCAADCTemperatureSensors on " << std::string(argv[1]) << " with " << sz << " and " << ty << "...";
    rsp = rpc.call_method(req);
    std::cout << "done!" << std::endl;
    if (rsp.get_key_exists("error")) {
      std::cout << "RPC ERROR:" << rsp.get_string("error") << std::endl;
      return 0;
    }

  return 0;
}

then running its executable after setting the environment and monitoring the log.

Screenshots (if appropriate):

Checklist:

jsturdy commented 5 years ago

One other comment I missed from @bdorney regarding the PT100 sensors, the one we've labeled as SCA_PT100 should be GBT0_PT100, according to Yifan

ram1123 commented 5 years ago

One other comment I missed from @bdorney regarding the PT100 sensors, the one we've labeled as SCA_PT100 should be GBT0_PT100, according to Yifan

done.

jsturdy commented 5 years ago

@mexanick, any objections to merging this?

ram1123 commented 5 years ago

Output values from the sensors

Sensor ID Info ADC Count Measured decimal Value Expected value (link)
0x00 PT100 44 19 $^0C$ -
0x04 PT100 44 19 $^0C$ -
0x07 PT100 45 24.40 $^0C$ -
0x08 PT100 44 19 $^0C$ -
0x1F SCA internal temperature 2743 25 $^0C$ -
0x1B FPGA MGT Voltage 1025 1 V 1 V
0x1E FPGA MGT Voltage 1254 1.22 V 1.2 V
0x11 FPGA core voltage 1066 1.04 V 1.0 V
0x18 Power for GBTx and SCA 1524 1.5 V 1.5 V
0x0F FPGA I/O power 2620 2.6 V 2.5 V
0x15 Signal strength of VTRX1 14 13 mV -
0x13 Signal strength of VTRX1 14 13 mV -
0x12 Signal strength of VTRX1 12 12 mV -

How the conversions are made

ADC counts to voltage conversion

The output values are 12 bit ADC and the voltage value varies from 0 to 1 V. Thus, each bit corresponds to 1/2^{12} =~ 0.244 mV.

PT100 Sensors

SCA Internal temperature

upload_70214b9a453866df6201dd01a97f9573

The above V-T graph is taken from page 52 of GBT-SCA manual [2]

Conversion of ADC for Voltage sensors

upload_65554560d042b44d9ed7369b6cea3992


Reference

  1. https://www.intech.co.nz/products/temperature/typert/RTD-Pt100-Conversion.pdf

  2. https://espace.cern.ch/GBT-Project/GBT-SCA/Manuals/GBT-SCA-UserManual.pdf