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
32 extern "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  // 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  // hallcurrent16_map // hallcurrent16
137 
142 typedef enum
143 {
148 
150 
155 typedef 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 
175 typedef 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 
200 typedef enum
201 {
204 
206 
223 
238 
252 
266 void hallcurrent16_set_vref ( hallcurrent16_t *ctx, float vref );
267 
283 
297 err_t hallcurrent16_get_voltage ( hallcurrent16_t *ctx, float *voltage );
298 
312 err_t hallcurrent16_get_vout ( hallcurrent16_t *ctx, float *adc_vout );
313 
327 err_t hallcurrent16_get_vref ( hallcurrent16_t *ctx, float *adc_vref );
328 
342 err_t hallcurrent16_get_current ( hallcurrent16_t *ctx, float *current );
343 
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 #endif // HALLCURRENT16_H
361  // hallcurrent16
363 
364 // ------------------------------------------------------------------------ END
hallcurrent16_t::sens
float sens
Definition: hallcurrent16.h:167
hallcurrent16_t::vref
float vref
Definition: hallcurrent16.h:165
hallcurrent16_default_cfg
err_t hallcurrent16_default_cfg(hallcurrent16_t *ctx)
Hall Current 16 default configuration function.
HALLCURRENT16_GAIN_0
@ HALLCURRENT16_GAIN_0
Definition: hallcurrent16.h:144
hallcurrent16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent16.h:189
hallcurrent16_cfg_t::sck
pin_name_t sck
Definition: hallcurrent16.h:180
hallcurrent16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent16.h:188
hallcurrent16_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent16.h:187
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hallcurrent16_get_voltage
err_t hallcurrent16_get_voltage(hallcurrent16_t *ctx, float *voltage)
Hall Current 16 get voltage function.
hallcurrent16_t::spi
spi_master_t spi
Definition: hallcurrent16.h:161
hallcurrent16_cfg_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:192
hallcurrent16_return_value_t
hallcurrent16_return_value_t
Hall Current 16 Click return value data.
Definition: hallcurrent16.h:201
HALLCURRENT16_ERROR
@ HALLCURRENT16_ERROR
Definition: hallcurrent16.h:203
hallcurrent16_cfg_t::ocf
pin_name_t ocf
Definition: hallcurrent16.h:184
hallcurrent16_cfg_t::vref
float vref
Definition: hallcurrent16.h:191
hallcurrent16_cfg_t
Hall Current 16 Click configuration object.
Definition: hallcurrent16.h:176
HALLCURRENT16_GAIN_3
@ HALLCURRENT16_GAIN_3
Definition: hallcurrent16.h:147
hallcurrent16_init
err_t hallcurrent16_init(hallcurrent16_t *ctx, hallcurrent16_cfg_t *cfg)
Hall Current 16 initialization function.
hallcurrent16_cfg_t::miso
pin_name_t miso
Definition: hallcurrent16.h:178
HALLCURRENT16_GAIN_2
@ HALLCURRENT16_GAIN_2
Definition: hallcurrent16.h:146
hallcurrent16_get_ovc_fault
uint8_t hallcurrent16_get_ovc_fault(hallcurrent16_t *ctx)
Hall Current 16 get overcurrent fault function.
hallcurrent16_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent16.h:179
hallcurrent16_t::chip_select
pin_name_t chip_select
Definition: hallcurrent16.h:163
hallcurrent16_get_current
err_t hallcurrent16_get_current(hallcurrent16_t *ctx, float *current)
Hall Current 16 get current function.
hallcurrent16_cfg_t::cs
pin_name_t cs
Definition: hallcurrent16.h:181
hallcurrent16_set_sens
void hallcurrent16_set_sens(hallcurrent16_t *ctx)
Hall Current 16 set sens function.
hallcurrent16_t::ocf
digital_in_t ocf
Definition: hallcurrent16.h:158
hallcurrent16_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:166
hallcurrent16_set_vref
void hallcurrent16_set_vref(hallcurrent16_t *ctx, float vref)
Hall Current 16 set vref function.
hallcurrent16_get_vout
err_t hallcurrent16_get_vout(hallcurrent16_t *ctx, float *adc_vout)
Hall Current 16 get vout function.
hallcurrent16_cfg_setup
void hallcurrent16_cfg_setup(hallcurrent16_cfg_t *cfg)
Hall Current 16 configuration object setup function.
hallcurrent16_gain_t
hallcurrent16_gain_t
Hall Current 16 Click gain value data.
Definition: hallcurrent16.h:143
HALLCURRENT16_OK
@ HALLCURRENT16_OK
Definition: hallcurrent16.h:202
HALLCURRENT16_GAIN_1
@ HALLCURRENT16_GAIN_1
Definition: hallcurrent16.h:145
hallcurrent16_get_vref
err_t hallcurrent16_get_vref(hallcurrent16_t *ctx, float *adc_vref)
Hall Current 16 get vout function.
hallcurrent16_t
Hall Current 16 Click context object.
Definition: hallcurrent16.h:156