Loading...
Searching...
No Matches
ina3221_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
21
22#include <assert.h>
23#include "ina3221_defines.h"
24#include "ina3221.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
39static inline int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
40{
42
43 return reg_val / 8 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
44}
45
55static inline int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
56{
58
59 return s_uv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 8;
60}
61
71static inline int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
72{
74
75 return reg_val / 8 * INA3221_BUS_VOLTAGE_PRECISION_MV;
76}
77
87static inline int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
88{
91
92 return b_mv / INA3221_BUS_VOLTAGE_PRECISION_MV * 8;
93}
94
104static inline int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
105{
107
108 return sum_reg_val / 2 * INA3221_SHUNT_VOLTAGE_PRECISION_UV;
109}
110
120static inline int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
121{
123
124 return sum_suv / INA3221_SHUNT_VOLTAGE_PRECISION_UV * 2;
125}
126
127#ifdef __cplusplus
128}
129#endif
130
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:146
Device driver interface for Texas Instruments INA3221 three-channel, high-side current and bus voltag...
Internal definitions for Texas Instruments INA3221 three-channel, high-side current and bus voltage m...
#define INA3221_MAX_SHUNT_SUM_UV
Max.
#define INA3221_MAX_BUS_MV
Max.
#define INA3221_MAX_SHUNT_REG_VAL
0111 1111 1111 1000
#define INA3221_MIN_BUS_MV
Min.
#define INA3221_MAX_SHUNT_UV
Max.
#define INA3221_BUS_VOLTAGE_PRECISION_MV
Bus voltage measurement precision.
#define INA3221_MAX_SHUNT_SUM_REG_VAL
0111 1111 1111 1110
#define INA3221_MAX_BUS_REG_VAL
0111 1111 1111 1000
#define INA3221_SHUNT_VOLTAGE_PRECISION_UV
Shunt voltage measurement precision.
static int32_t reg_val_to_shunt_voltage_uv(int16_t reg_val)
Convert register value to shunt voltage in uV.
static int32_t sum_reg_val_to_shunt_voltage_uv(int16_t sum_reg_val)
Convert register value to shunt voltage sum value in mV.
static int16_t bus_voltage_mv_to_reg_val(int16_t b_mv)
Convert bus voltage in mV to register value.
static int16_t reg_val_to_bus_voltage_mv(int16_t reg_val)
Convert register value to bus voltage in mV.
static int16_t shunt_voltage_uv_to_reg_val(int32_t s_uv)
Convert shunt voltage in uV to register value.
static int16_t sum_shunt_voltage_uv_to_reg_val(int32_t sum_suv)
Convert shunt voltage sum value in uV to register value.