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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define HALLCURRENT16_ADDR_IN_CH_SEL_1 0x00
61 #define HALLCURRENT16_ADDR_IN_CH_SEL_2 0x08
62 
67 #define HALLCURRENT16_RESOLUTION_12BIT 0x0FFFu
68 #define HALLCURRENT16_VREF_3V3 3.3f
69 #define HALLCURRENT16_VREF_5V 5.0f
70 
75 #define HALLCURRENT16_SENS_CALC_GAIN_0 26.4f
76 #define HALLCURRENT16_SENS_CALC_GAIN_1 33.0f
77 #define HALLCURRENT16_SENS_CALC_GAIN_2 39.6f
78 #define HALLCURRENT16_SENS_CALC_GAIN_3 19.8f
79 
84 #define HALLCURRENT16_ADC_NUM_OF_MEASURE 1000u
85 #define HALLCURRENT16_CONV_TO_MILI 1000.0f
86 
95 #define HALLCURRENT16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
96 #define HALLCURRENT16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
97  // hallcurrent16_set
99 
114 #define HALLCURRENT16_MAP_MIKROBUS( cfg, mikrobus ) \
115  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
116  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
117  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
118  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
119  cfg.ocf = MIKROBUS( mikrobus, MIKROBUS_INT )
120  // hallcurrent16_map // hallcurrent16
123 
128 typedef enum
129 {
134 
136 
141 typedef struct
142 {
143  // Input pins
144  digital_in_t ocf;
146  // Modules
147  spi_master_t spi;
149  pin_name_t chip_select;
151  float vref;
153  float sens;
156 
161 typedef struct
162 {
163  // Communication gpio pins
164  pin_name_t miso;
165  pin_name_t mosi;
166  pin_name_t sck;
167  pin_name_t cs;
169  // Additional gpio pins
170  pin_name_t ocf;
172  // static variable
173  uint32_t spi_speed;
174  spi_master_mode_t spi_mode;
175  spi_master_chip_select_polarity_t cs_polarity;
177  float vref;
181 
186 typedef enum
187 {
190 
192 
209 
224 
238 
252 void hallcurrent16_set_vref ( hallcurrent16_t *ctx, float vref );
253 
269 
283 err_t hallcurrent16_get_voltage ( hallcurrent16_t *ctx, float *voltage );
284 
298 err_t hallcurrent16_get_vout ( hallcurrent16_t *ctx, float *adc_vout );
299 
313 err_t hallcurrent16_get_vref ( hallcurrent16_t *ctx, float *adc_vref );
314 
328 err_t hallcurrent16_get_current ( hallcurrent16_t *ctx, float *current );
329 
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 #endif // HALLCURRENT16_H
347  // hallcurrent16
349 
350 // ------------------------------------------------------------------------ END
hallcurrent16_t::sens
float sens
Definition: hallcurrent16.h:153
hallcurrent16_t::vref
float vref
Definition: hallcurrent16.h:151
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:130
hallcurrent16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent16.h:175
hallcurrent16_cfg_t::sck
pin_name_t sck
Definition: hallcurrent16.h:166
hallcurrent16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent16.h:174
hallcurrent16_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent16.h:173
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:147
hallcurrent16_cfg_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:178
hallcurrent16_return_value_t
hallcurrent16_return_value_t
Hall Current 16 Click return value data.
Definition: hallcurrent16.h:187
HALLCURRENT16_ERROR
@ HALLCURRENT16_ERROR
Definition: hallcurrent16.h:189
hallcurrent16_cfg_t::ocf
pin_name_t ocf
Definition: hallcurrent16.h:170
hallcurrent16_cfg_t::vref
float vref
Definition: hallcurrent16.h:177
hallcurrent16_cfg_t
Hall Current 16 Click configuration object.
Definition: hallcurrent16.h:162
HALLCURRENT16_GAIN_3
@ HALLCURRENT16_GAIN_3
Definition: hallcurrent16.h:133
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:164
HALLCURRENT16_GAIN_2
@ HALLCURRENT16_GAIN_2
Definition: hallcurrent16.h:132
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:165
hallcurrent16_t::chip_select
pin_name_t chip_select
Definition: hallcurrent16.h:149
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:167
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:144
hallcurrent16_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:152
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:129
HALLCURRENT16_OK
@ HALLCURRENT16_OK
Definition: hallcurrent16.h:188
HALLCURRENT16_GAIN_1
@ HALLCURRENT16_GAIN_1
Definition: hallcurrent16.h:131
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:142