DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
timing
src
LTC2945Node.cpp
Go to the documentation of this file.
1
8
9
#include "
timing/LTC2945Node.hpp
"
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
19
namespace
dunedaq
{
20
namespace
timing
{
21
22
//-----------------------------------------------------------------------------
23
LTC2945Node::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
//-----------------------------------------------------------------------------
30
LTC2945Node::~LTC2945Node
() {}
31
//-----------------------------------------------------------------------------
32
33
//-----------------------------------------------------------------------------
34
/*
35
uint8_t
36
LTC2945Node::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
//-----------------------------------------------------------------------------
67
double
68
LTC2945Node::read_v_in
()
const
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
//-----------------------------------------------------------------------------
83
double
84
LTC2945Node::read_delta_sense_v
()
const
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
//-----------------------------------------------------------------------------
99
double
100
LTC2945Node::read_power
()
const
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
//-----------------------------------------------------------------------------
115
uint16_t
116
LTC2945Node::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
//-----------------------------------------------------------------------------
125
uint32_t
126
LTC2945Node::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
LTC2945Node.hpp
dunedaq::timing::I2CSlave::I2CMasterNode
friend class I2CMasterNode
Definition
I2CSlave.hpp:97
dunedaq::timing::I2CSlave::read_i2cArray_atomic
std::vector< uint8_t > read_i2cArray_atomic(uint32_t i2c_reg_address, uint32_t number_of_words) const
Definition
I2CSlave.cpp:125
dunedaq::timing::I2CSlave::I2CSlave
I2CSlave(const I2CMasterNode *i2c_master, uint8_t i2c_device_address)
Definition
I2CSlave.cpp:33
dunedaq::timing::LTC2945Node::delta_sense_v_resolution
static constexpr float delta_sense_v_resolution
Definition
LTC2945Node.hpp:57
dunedaq::timing::LTC2945Node::combine_power_data
static uint32_t combine_power_data(uint8_t msb_byte_2, uint8_t msb_byte_1, uint8_t lsb_byte)
Definition
LTC2945Node.cpp:126
dunedaq::timing::LTC2945Node::LTC2945Node
LTC2945Node(const I2CMasterNode *i2c_master, uint8_t i2c_device_address, double sense_resistance)
Definition
LTC2945Node.cpp:23
dunedaq::timing::LTC2945Node::read_power
double read_power() const
Read power [W].
Definition
LTC2945Node.cpp:100
dunedaq::timing::LTC2945Node::read_v_in
double read_v_in() const
Read V in [V].
Definition
LTC2945Node.cpp:68
dunedaq::timing::LTC2945Node::~LTC2945Node
virtual ~LTC2945Node()
Definition
LTC2945Node.cpp:30
dunedaq::timing::LTC2945Node::combine_adc_data
static uint16_t combine_adc_data(uint8_t msb_byte, uint8_t lsb_byte)
Definition
LTC2945Node.cpp:116
dunedaq::timing::LTC2945Node::m_sense_resistance
double m_sense_resistance
Definition
LTC2945Node.hpp:51
dunedaq::timing::LTC2945Node::v_in_resolution
static constexpr float v_in_resolution
Definition
LTC2945Node.hpp:56
dunedaq::timing::LTC2945Node::read_delta_sense_v
double read_delta_sense_v() const
Read delta sense voltage [V].
Definition
LTC2945Node.cpp:84
ers.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
dunedaq::timing
< Message parameters
Definition
BoreasDesign.hpp:29
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::v
default char v[0]
Definition
Serialization.hpp:266
dunedaq::address
Invalid address
Definition
CommonIssues.hpp:29
toolbox.hpp
Generated on
for DUNE-DAQ by
1.17.0