hallcurrent20 2.2.0
Loading...
Searching...
No Matches
hallcurrent20.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 HALLCURRENT20_H
29#define HALLCURRENT20_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_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define HALLCURRENT20_NUM_CONVERSIONS 200
75
80#define HALLCURRENT20_ADC_RESOLUTION 0x0FFF
81#define HALLCURRENT20_VREF_3V3 3.3
82#define HALLCURRENT20_VREF_5V 5.0
83
88#define HALLCURRENT20_TIMEOUT_MS 2000
89
95#define HALLCURRENT20_SET_DEV_ADDR 0x4D
96 // hallcurrent20_set
98
103
108
113#define HALLCURRENT20_MAP_MIKROBUS( cfg, mikrobus ) \
114 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
116 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
117 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
118 // hallcurrent20_map // hallcurrent20
121
132
137typedef struct
138{
139 digital_in_t fault;
140
141 analog_in_t adc;
142 i2c_master_t i2c;
143
145 float vref;
149
151
156typedef struct
157{
158 pin_name_t an;
159 pin_name_t scl;
160 pin_name_t sda;
161 pin_name_t fault;
162
163 analog_in_resolution_t resolution;
164 float vref;
165
166 uint32_t i2c_speed;
167 uint8_t i2c_address;
168
170
172
183
189
200
216
231
243err_t hallcurrent20_read_raw_adc ( hallcurrent20_t *ctx, uint16_t *raw_adc );
244
256err_t hallcurrent20_read_voltage ( hallcurrent20_t *ctx, float *voltage );
257
270err_t hallcurrent20_read_voltage_avg ( hallcurrent20_t *ctx, uint16_t num_conv, float *voltage_avg );
271
283err_t hallcurrent20_set_vref ( hallcurrent20_t *ctx, float vref );
284
294
306
319err_t hallcurrent20_calib_resolution ( hallcurrent20_t *ctx, float calib_current );
320
333err_t hallcurrent20_read_current ( hallcurrent20_t *ctx, float *current );
334
335#ifdef __cplusplus
336}
337#endif
338#endif // HALLCURRENT20_H
339 // hallcurrent20
341
342// ------------------------------------------------------------------------ END
err_t hallcurrent20_read_voltage_avg(hallcurrent20_t *ctx, uint16_t num_conv, float *voltage_avg)
Hall Current 20 read average voltage level function.
err_t hallcurrent20_calib_resolution(hallcurrent20_t *ctx, float calib_current)
Hall Current 20 calib resolution function.
err_t hallcurrent20_set_vref(hallcurrent20_t *ctx, float vref)
Hall Current 20 set vref function.
uint8_t hallcurrent20_get_fault_pin(hallcurrent20_t *ctx)
Hall Current 20 get fault pin function.
err_t hallcurrent20_read_voltage(hallcurrent20_t *ctx, float *voltage)
Hall Current 20 read voltage level function.
err_t hallcurrent20_read_raw_adc(hallcurrent20_t *ctx, uint16_t *raw_adc)
Hall Current 20 read raw ADC value function.
void hallcurrent20_cfg_setup(hallcurrent20_cfg_t *cfg)
Hall Current 20 configuration object setup function.
err_t hallcurrent20_calib_offset(hallcurrent20_t *ctx)
Hall Current 20 calib offset function.
err_t hallcurrent20_init(hallcurrent20_t *ctx, hallcurrent20_cfg_t *cfg)
Hall Current 20 initialization function.
err_t hallcurrent20_read_current(hallcurrent20_t *ctx, float *current)
Hall Current 20 read current function.
void hallcurrent20_drv_interface_sel(hallcurrent20_cfg_t *cfg, hallcurrent20_drv_t drv_sel)
Hall Current 20 driver interface setup function.
hallcurrent20_return_value_t
Hall Current 20 Click return value data.
Definition hallcurrent20.h:178
@ HALLCURRENT20_OK
Definition hallcurrent20.h:179
@ HALLCURRENT20_ERROR
Definition hallcurrent20.h:180
hallcurrent20_drv_t
Hall Current 20 Click driver selector.
Definition hallcurrent20.h:127
@ HALLCURRENT20_DRV_SEL_ADC
Definition hallcurrent20.h:128
@ HALLCURRENT20_DRV_SEL_I2C
Definition hallcurrent20.h:129
Hall Current 20 Click configuration object.
Definition hallcurrent20.h:157
analog_in_resolution_t resolution
Definition hallcurrent20.h:163
float vref
Definition hallcurrent20.h:164
uint32_t i2c_speed
Definition hallcurrent20.h:166
hallcurrent20_drv_t drv_sel
Definition hallcurrent20.h:169
pin_name_t scl
Definition hallcurrent20.h:159
pin_name_t sda
Definition hallcurrent20.h:160
pin_name_t an
Definition hallcurrent20.h:158
pin_name_t fault
Definition hallcurrent20.h:161
uint8_t i2c_address
Definition hallcurrent20.h:167
Hall Current 20 Click context object.
Definition hallcurrent20.h:138
float data_resolution
Definition hallcurrent20.h:147
float vref
Definition hallcurrent20.h:145
hallcurrent20_drv_t drv_sel
Definition hallcurrent20.h:148
i2c_master_t i2c
Definition hallcurrent20.h:142
digital_in_t fault
Definition hallcurrent20.h:139
uint8_t slave_address
Definition hallcurrent20.h:144
float zero_curr_offset
Definition hallcurrent20.h:146
analog_in_t adc
Definition hallcurrent20.h:141