DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
LTC2945Node.cpp
Go to the documentation of this file.
1
10
11// PDT headers
12#include "ers/ers.hpp"
13#include "timing/toolbox.hpp"
14
15#include <vector>
16// #include <fstream>
17// #include <sstream>
18
19namespace dunedaq {
20namespace timing {
21
22//-----------------------------------------------------------------------------
23LTC2945Node::LTC2945Node(const I2CMasterNode* i2c_master, uint8_t address, double sense_resistance) // NOLINT(build/unsigned)
24 : m_sense_resistance(sense_resistance)
25 , I2CSlave(i2c_master, address)
26{}
27//-----------------------------------------------------------------------------
28
29//-----------------------------------------------------------------------------
31//-----------------------------------------------------------------------------
32
33//-----------------------------------------------------------------------------
34/*
35uint8_t
36LTC2945Node::read_register(uint8_t reg_address) const
37{
38 // Reset bus before beginning
39 reset();
40
41 // Open the connection and send the slave address, bit 0 set to zero
42 send_i2c_command_and_write_data(kStartCmd, (m_i2c_device_address << 1) & 0xfe);
43
44 // Push the byte on the bus
45 send_i2c_command_and_write_data(0x0, reg_address);
46
47 // Open the connection & send the target i2c address. Bit 0 set to 1 (read)
48 send_i2c_command_and_write_data(kStartCmd, (m_i2c_device_address << 1) | 0x01);
49
50 uint number_of_bytes = 1;
51
52 std::vector<uint8_t> lArray; // NOLINT(build/unsigned)
53 for (unsigned ibyte = 0; ibyte < number_of_bytes; ibyte++) {
54
55 uint8_t cmd = ((ibyte == number_of_bytes - 1) ? (kStopCmd | kAckCmd) : 0x0); // NOLINT(build/unsigned)
56
57 // Push the cmd on the bus, retrieve the result and put it in the arrary
58 lArray.push_back(send_i2c_command_and_read_data(cmd));
59 }
60 return lArray[0];
61
62}
63*/
64//-----------------------------------------------------------------------------
65
66//-----------------------------------------------------------------------------
67double
69{
70 std::vector<uint8_t> v_in_bytes = this->read_i2cArray_atomic(0x1e, 0x2); // NOLINT(build/unsigned)
71 uint16_t v_in_raw = combine_adc_data(v_in_bytes[0], v_in_bytes[1]);
72 double v_in = v_in_raw*v_in_resolution;
73
74 TLOG_DEBUG(13) << "LTC2945 Vin data - "
75 << "raw bytes: 0x" << std::hex << (uint)v_in_bytes[0] << ", 0x" << (uint)v_in_bytes[1] // NOLINT(build/unsigned)
76 << ", combined word: 0x" << v_in_raw
77 << ", Vin [V]: " << v_in;
78 return v_in;
79}
80//-----------------------------------------------------------------------------
81
82//-----------------------------------------------------------------------------
83double
85{
86 std::vector<uint8_t> v_bytes = this->read_i2cArray_atomic(0x14, 0x2); // NOLINT(build/unsigned)
87 uint16_t v_raw = combine_adc_data(v_bytes[0], v_bytes[1]);
88 double v = v_raw*delta_sense_v_resolution;
89
90 TLOG_DEBUG(13) << "LTC2945 deltaSense V data - "
91 << "raw bytes: 0x" << std::hex << (uint)v_bytes[0] << ", 0x" << (uint)v_bytes[1] // NOLINT(build/unsigned)
92 << ", combined word: 0x" << v_raw
93 << ", detlaSense V [mV]: " << v*1000;
94 return v;
95}
96//-----------------------------------------------------------------------------
97
98//-----------------------------------------------------------------------------
99double
101{
102 std::vector<uint8_t> power_bytes = this->read_i2cArray_atomic(0x05, 0x3); // NOLINT(build/unsigned)
103 uint32_t power_raw = combine_power_data(power_bytes[0], power_bytes[1], power_bytes[2]);
104 double power = (power_raw * v_in_resolution * delta_sense_v_resolution) / m_sense_resistance;
105
106 TLOG_DEBUG(13) << "LTC2945 power data - "
107 << "raw bytes: 0x" << std::hex << (uint)power_bytes[0] << ", 0x" << (uint)power_bytes[1] << ", 0x" << (uint)power_bytes[2] // NOLINT(build/unsigned)
108 << ", combined word: 0x" << power_raw
109 << ", power [mW]: " << power*1000;
110 return power;
111}
112//-----------------------------------------------------------------------------
113
114//-----------------------------------------------------------------------------
115uint16_t
116LTC2945Node::combine_adc_data(uint8_t msb_byte, uint8_t lsb_byte)
117{
118 uint16_t adc = (uint16_t)msb_byte << 4;
119 adc = adc | (lsb_byte >> 4);
120 return adc;
121}
122//-----------------------------------------------------------------------------
123
124//-----------------------------------------------------------------------------
125uint32_t
126LTC2945Node::combine_power_data(uint8_t msb_byte_2, uint8_t msb_byte_1, uint8_t lsb_byte)
127{
128 uint32_t power = (uint32_t)msb_byte_2 << 16;
129 power = power | ((uint16_t)msb_byte_1 << 8);
130 power = power | lsb_byte;
131 return power;
132}
133//-----------------------------------------------------------------------------
134
135} // namespace timing
136} // namespace dunedaq
std::vector< uint8_t > read_i2cArray_atomic(uint32_t i2c_reg_address, uint32_t number_of_words) const
Definition I2CSlave.cpp:125
static constexpr float delta_sense_v_resolution
static uint32_t combine_power_data(uint8_t msb_byte_2, uint8_t msb_byte_1, uint8_t lsb_byte)
LTC2945Node(const I2CMasterNode *i2c_master, uint8_t i2c_device_address, double sense_resistance)
double read_power() const
Read power [W].
double read_v_in() const
Read V in [V].
static uint16_t combine_adc_data(uint8_t msb_byte, uint8_t lsb_byte)
static constexpr float v_in_resolution
double read_delta_sense_v() const
Read delta sense voltage [V].
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
The DUNE-DAQ namespace.
Definition DataStore.hpp:57
default char v[0]