hallcurrent16 2.1.0.0
hallcurrent16.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
28#ifndef HALLCURRENT16_H
29#define HALLCURRENT16_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define HALLCURRENT16_ADDR_IN_CH_SEL_1 0x00
75#define HALLCURRENT16_ADDR_IN_CH_SEL_2 0x08
76
81#define HALLCURRENT16_RESOLUTION_12BIT 0x0FFFu
82#define HALLCURRENT16_VREF_3V3 3.3f
83#define HALLCURRENT16_VREF_5V 5.0f
84
89#define HALLCURRENT16_SENS_CALC_GAIN_0 26.4f
90#define HALLCURRENT16_SENS_CALC_GAIN_1 33.0f
91#define HALLCURRENT16_SENS_CALC_GAIN_2 39.6f
92#define HALLCURRENT16_SENS_CALC_GAIN_3 19.8f
93
98#define HALLCURRENT16_ADC_NUM_OF_MEASURE 1000u
99#define HALLCURRENT16_CONV_TO_MILI 1000.0f
100
109#define HALLCURRENT16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
110#define HALLCURRENT16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
111
112 // hallcurrent16_set
113
128#define HALLCURRENT16_MAP_MIKROBUS( cfg, mikrobus ) \
129 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
130 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
131 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
132 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
133 cfg.ocf = MIKROBUS( mikrobus, MIKROBUS_INT )
134
135 // hallcurrent16_map
136 // hallcurrent16
137
150
155typedef struct
156{
157 // Input pins
158 digital_in_t ocf;
160 // Modules
161 spi_master_t spi;
163 pin_name_t chip_select;
165 float vref;
167 float sens;
170
175typedef struct
176{
177 // Communication gpio pins
178 pin_name_t miso;
179 pin_name_t mosi;
180 pin_name_t sck;
181 pin_name_t cs;
183 // Additional gpio pins
184 pin_name_t ocf;
186 // static variable
187 uint32_t spi_speed;
188 spi_master_mode_t spi_mode;
189 spi_master_chip_select_polarity_t cs_polarity;
191 float vref;
195
206
223
238
252
266void hallcurrent16_set_vref ( hallcurrent16_t *ctx, float vref );
267
283
297err_t hallcurrent16_get_voltage ( hallcurrent16_t *ctx, float *voltage );
298
312err_t hallcurrent16_get_vout ( hallcurrent16_t *ctx, float *adc_vout );
313
327err_t hallcurrent16_get_vref ( hallcurrent16_t *ctx, float *adc_vref );
328
342err_t hallcurrent16_get_current ( hallcurrent16_t *ctx, float *current );
343
356
357#ifdef __cplusplus
358}
359#endif
360#endif // HALLCURRENT16_H
361
362 // hallcurrent16
363
364// ------------------------------------------------------------------------ END
uint8_t hallcurrent16_get_ovc_fault(hallcurrent16_t *ctx)
Hall Current 16 get overcurrent fault function.
err_t hallcurrent16_get_current(hallcurrent16_t *ctx, float *current)
Hall Current 16 get current function.
err_t hallcurrent16_get_vout(hallcurrent16_t *ctx, float *adc_vout)
Hall Current 16 get vout function.
err_t hallcurrent16_init(hallcurrent16_t *ctx, hallcurrent16_cfg_t *cfg)
Hall Current 16 initialization function.
void hallcurrent16_cfg_setup(hallcurrent16_cfg_t *cfg)
Hall Current 16 configuration object setup function.
err_t hallcurrent16_default_cfg(hallcurrent16_t *ctx)
Hall Current 16 default configuration function.
void hallcurrent16_set_vref(hallcurrent16_t *ctx, float vref)
Hall Current 16 set vref function.
err_t hallcurrent16_get_vref(hallcurrent16_t *ctx, float *adc_vref)
Hall Current 16 get vout function.
void hallcurrent16_set_sens(hallcurrent16_t *ctx)
Hall Current 16 set sens function.
err_t hallcurrent16_get_voltage(hallcurrent16_t *ctx, float *voltage)
Hall Current 16 get voltage function.
hallcurrent16_gain_t
Hall Current 16 Click gain value data.
Definition hallcurrent16.h:143
@ HALLCURRENT16_GAIN_3
Definition hallcurrent16.h:147
@ HALLCURRENT16_GAIN_2
Definition hallcurrent16.h:146
@ HALLCURRENT16_GAIN_0
Definition hallcurrent16.h:144
@ HALLCURRENT16_GAIN_1
Definition hallcurrent16.h:145
hallcurrent16_return_value_t
Hall Current 16 Click return value data.
Definition hallcurrent16.h:201
@ HALLCURRENT16_OK
Definition hallcurrent16.h:202
@ HALLCURRENT16_ERROR
Definition hallcurrent16.h:203
This file contains SPI specific macros, functions, etc.
Hall Current 16 Click configuration object.
Definition hallcurrent16.h:176
pin_name_t ocf
Definition hallcurrent16.h:184
hallcurrent16_gain_t gain
Definition hallcurrent16.h:192
float vref
Definition hallcurrent16.h:191
spi_master_chip_select_polarity_t cs_polarity
Definition hallcurrent16.h:189
pin_name_t sck
Definition hallcurrent16.h:180
spi_master_mode_t spi_mode
Definition hallcurrent16.h:188
pin_name_t mosi
Definition hallcurrent16.h:179
uint32_t spi_speed
Definition hallcurrent16.h:187
pin_name_t miso
Definition hallcurrent16.h:178
pin_name_t cs
Definition hallcurrent16.h:181
Hall Current 16 Click context object.
Definition hallcurrent16.h:156
hallcurrent16_gain_t gain
Definition hallcurrent16.h:166
spi_master_t spi
Definition hallcurrent16.h:161
digital_in_t ocf
Definition hallcurrent16.h:158
float vref
Definition hallcurrent16.h:165
float sens
Definition hallcurrent16.h:167
pin_name_t chip_select
Definition hallcurrent16.h:163