buck24 2.2.0
Loading...
Searching...
No Matches
buck24.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef BUCK24_H
29#define BUCK24_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define BUCK24_REG_CONFIGURATION 0x00
74#define BUCK24_REG_SHUNT_VOLTAGE 0x01
75#define BUCK24_REG_BUS_VOLTAGE 0x02
76#define BUCK24_REG_POWER 0x03
77#define BUCK24_REG_CURRENT 0x04
78#define BUCK24_REG_CALIBRATION 0x05
79 // buck24_reg
81
86
91
96#define BUCK24_CONFIGURATION_RST 0x8000
97#define BUCK24_CONFIGURATION_BRNG_16V 0x0000
98#define BUCK24_CONFIGURATION_BRNG_32V 0x2000
99#define BUCK24_CONFIGURATION_BRNG_MASK 0x2000
100#define BUCK24_CONFIGURATION_PGA_DIV_1 0x0000
101#define BUCK24_CONFIGURATION_PGA_DIV_2 0x0800
102#define BUCK24_CONFIGURATION_PGA_DIV_4 0x1000
103#define BUCK24_CONFIGURATION_PGA_DIV_8 0x1800
104#define BUCK24_CONFIGURATION_PGA_MASK 0x1800
105#define BUCK24_CONFIGURATION_BADC_84_US 0x0000
106#define BUCK24_CONFIGURATION_BADC_148_US 0x0080
107#define BUCK24_CONFIGURATION_BADC_276_US 0x0100
108#define BUCK24_CONFIGURATION_BADC_532_US 0x0180
109#define BUCK24_CONFIGURATION_BADC_1_06_MS 0x0480
110#define BUCK24_CONFIGURATION_BADC_2_13_MS 0x0500
111#define BUCK24_CONFIGURATION_BADC_4_26_MS 0x0580
112#define BUCK24_CONFIGURATION_BADC_8_51_MS 0x0600
113#define BUCK24_CONFIGURATION_BADC_17_02_MS 0x0680
114#define BUCK24_CONFIGURATION_BADC_34_05_MS 0x0700
115#define BUCK24_CONFIGURATION_BADC_68_10_MS 0x0780
116#define BUCK24_CONFIGURATION_BADC_MASK 0x0780
117#define BUCK24_CONFIGURATION_SADC_84_US 0x0000
118#define BUCK24_CONFIGURATION_SADC_148_US 0x0008
119#define BUCK24_CONFIGURATION_SADC_276_US 0x0010
120#define BUCK24_CONFIGURATION_SADC_532_US 0x0018
121#define BUCK24_CONFIGURATION_SADC_1_06_MS 0x0048
122#define BUCK24_CONFIGURATION_SADC_2_13_MS 0x0050
123#define BUCK24_CONFIGURATION_SADC_4_26_MS 0x0058
124#define BUCK24_CONFIGURATION_SADC_8_51_MS 0x0060
125#define BUCK24_CONFIGURATION_SADC_17_02_MS 0x0068
126#define BUCK24_CONFIGURATION_SADC_34_05_MS 0x0070
127#define BUCK24_CONFIGURATION_SADC_68_10_MS 0x0078
128#define BUCK24_CONFIGURATION_SADC_MASK 0x0078
129#define BUCK24_CONFIGURATION_MODE_PDOWN 0x0000
130#define BUCK24_CONFIGURATION_MODE_SHT_V_TRG 0x0001
131#define BUCK24_CONFIGURATION_MODE_BUS_V_TRG 0x0002
132#define BUCK24_CONFIGURATION_MODE_SHT_BUS_V_TRG 0x0003
133#define BUCK24_CONFIGURATION_MODE_ADC_OFF 0x0004
134#define BUCK24_CONFIGURATION_MODE_SHT_V_CONT 0x0005
135#define BUCK24_CONFIGURATION_MODE_BUS_V_CONT 0x0006
136#define BUCK24_CONFIGURATION_MODE_SHT_BUS_V_CONT 0x0007
137#define BUCK24_CONFIGURATION_MODE_MASK 0x0007
138
143#define BUCK24_BUS_VOLTAGE_CNVR 0x0002
144#define BUCK24_BUS_VOLTAGE_OVF 0x0001
145
150#define BUCK24_SHUNT_LSB_MV 0.01f
151#define BUCK24_BUS_V_LSB_V 0.004f
152#define BUCK24_POWER_LSB_W 0.02f
153#define BUCK24_CURRENT_LSB_A 0.001f
154#define BUCK24_CALIBRATION_FOR_SHUNT_0_01_OHM 4096
155#define BUCK24_DEFAULT_NUM_CONV 20
156
162#define BUCK24_DEVICE_ADDRESS_0 0x40
163#define BUCK24_DEVICE_ADDRESS_1 0x41
164 // buck24_set
166
171
176
181typedef struct
182{
183 float shunt_mv;
184 float bus_v;
185 float current;
186 float power;
187
189
194#define BUCK24_MAP_MIKROBUS( cfg, mikrobus ) \
195 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
196 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
197 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
198 cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
199 // buck24_map // buck24
202
207typedef struct
208{
209 // Output pins
210 digital_out_t rst;
211
212 // Input pins
213 digital_in_t pg;
214
215 // Modules
216 i2c_master_t i2c;
217
218 // I2C slave address
220
221} buck24_t;
222
227typedef struct
228{
229 pin_name_t scl;
230 pin_name_t sda;
231
232 pin_name_t rst;
233 pin_name_t pg;
234
235 uint32_t i2c_speed;
236 uint8_t i2c_address;
237
239
244typedef enum
245{
248
250
256
267
281err_t buck24_init ( buck24_t *ctx, buck24_cfg_t *cfg );
282
296
306
316
326
338err_t buck24_write_reg ( buck24_t *ctx, uint8_t reg, uint16_t data_in );
339
351err_t buck24_read_reg ( buck24_t *ctx, uint8_t reg, uint16_t *data_out );
352
364err_t buck24_read_data ( buck24_t *ctx, buck24_data_t *data_out );
365
378err_t buck24_read_data_avg ( buck24_t *ctx, uint16_t num_conv, buck24_data_t *data_out );
379
380#ifdef __cplusplus
381}
382#endif
383#endif // BUCK24_H
384 // buck24
386
387// ------------------------------------------------------------------------ END
buck24_return_value_t
Buck 24 Click return value data.
Definition buck24.h:245
@ BUCK24_ERROR
Definition buck24.h:247
@ BUCK24_OK
Definition buck24.h:246
void buck24_cfg_setup(buck24_cfg_t *cfg)
Buck 24 configuration object setup function.
err_t buck24_read_data(buck24_t *ctx, buck24_data_t *data_out)
Buck 24 read measurement data function.
err_t buck24_init(buck24_t *ctx, buck24_cfg_t *cfg)
Buck 24 initialization function.
err_t buck24_read_reg(buck24_t *ctx, uint8_t reg, uint16_t *data_out)
Buck 24 read register function.
void buck24_disable_device(buck24_t *ctx)
Buck 24 disable device function.
uint8_t buck24_get_pg_pin(buck24_t *ctx)
Buck 24 get power-good pin function.
err_t buck24_default_cfg(buck24_t *ctx)
Buck 24 default configuration function.
err_t buck24_read_data_avg(buck24_t *ctx, uint16_t num_conv, buck24_data_t *data_out)
Buck 24 read averaged measurement data function.
void buck24_enable_device(buck24_t *ctx)
Buck 24 enable device function.
err_t buck24_write_reg(buck24_t *ctx, uint8_t reg, uint16_t data_in)
Buck 24 write register function.
Buck 24 Click configuration object.
Definition buck24.h:228
uint32_t i2c_speed
Definition buck24.h:235
pin_name_t scl
Definition buck24.h:229
pin_name_t sda
Definition buck24.h:230
pin_name_t pg
Definition buck24.h:233
pin_name_t rst
Definition buck24.h:232
uint8_t i2c_address
Definition buck24.h:236
Buck 24 Click data object.
Definition buck24.h:182
float shunt_mv
Definition buck24.h:183
float bus_v
Definition buck24.h:184
float power
Definition buck24.h:186
float current
Definition buck24.h:185
Buck 24 Click context object.
Definition buck24.h:208
i2c_master_t i2c
Definition buck24.h:216
digital_out_t rst
Definition buck24.h:210
uint8_t slave_address
Definition buck24.h:219
digital_in_t pg
Definition buck24.h:213