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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define HALLCURRENT16_ADDR_IN_CH_SEL_1 0x00
71 #define HALLCURRENT16_ADDR_IN_CH_SEL_2 0x08
72 
77 #define HALLCURRENT16_RESOLUTION_12BIT 0x0FFFu
78 #define HALLCURRENT16_VREF_3V3 3.3f
79 #define HALLCURRENT16_VREF_5V 5.0f
80 
85 #define HALLCURRENT16_SENS_CALC_GAIN_0 26.4f
86 #define HALLCURRENT16_SENS_CALC_GAIN_1 33.0f
87 #define HALLCURRENT16_SENS_CALC_GAIN_2 39.6f
88 #define HALLCURRENT16_SENS_CALC_GAIN_3 19.8f
89 
94 #define HALLCURRENT16_ADC_NUM_OF_MEASURE 1000u
95 #define HALLCURRENT16_CONV_TO_MILI 1000.0f
96 
105 #define HALLCURRENT16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
106 #define HALLCURRENT16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
107  // hallcurrent16_set
109 
124 #define HALLCURRENT16_MAP_MIKROBUS( cfg, mikrobus ) \
125  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
126  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
127  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
128  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
129  cfg.ocf = MIKROBUS( mikrobus, MIKROBUS_INT )
130  // hallcurrent16_map // hallcurrent16
133 
138 typedef enum
139 {
144 
146 
151 typedef struct
152 {
153  // Input pins
154  digital_in_t ocf;
156  // Modules
157  spi_master_t spi;
159  pin_name_t chip_select;
161  float vref;
163  float sens;
166 
171 typedef struct
172 {
173  // Communication gpio pins
174  pin_name_t miso;
175  pin_name_t mosi;
176  pin_name_t sck;
177  pin_name_t cs;
179  // Additional gpio pins
180  pin_name_t ocf;
182  // static variable
183  uint32_t spi_speed;
184  spi_master_mode_t spi_mode;
185  spi_master_chip_select_polarity_t cs_polarity;
187  float vref;
191 
196 typedef enum
197 {
200 
202 
219 
234 
248 
262 void hallcurrent16_set_vref ( hallcurrent16_t *ctx, float vref );
263 
279 
293 err_t hallcurrent16_get_voltage ( hallcurrent16_t *ctx, float *voltage );
294 
308 err_t hallcurrent16_get_vout ( hallcurrent16_t *ctx, float *adc_vout );
309 
323 err_t hallcurrent16_get_vref ( hallcurrent16_t *ctx, float *adc_vref );
324 
338 err_t hallcurrent16_get_current ( hallcurrent16_t *ctx, float *current );
339 
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 #endif // HALLCURRENT16_H
357  // hallcurrent16
359 
360 // ------------------------------------------------------------------------ END
hallcurrent16_t::sens
float sens
Definition: hallcurrent16.h:163
hallcurrent16_t::vref
float vref
Definition: hallcurrent16.h:161
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:140
hallcurrent16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent16.h:185
hallcurrent16_cfg_t::sck
pin_name_t sck
Definition: hallcurrent16.h:176
hallcurrent16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent16.h:184
hallcurrent16_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent16.h:183
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:157
hallcurrent16_cfg_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:188
hallcurrent16_return_value_t
hallcurrent16_return_value_t
Hall Current 16 Click return value data.
Definition: hallcurrent16.h:197
HALLCURRENT16_ERROR
@ HALLCURRENT16_ERROR
Definition: hallcurrent16.h:199
hallcurrent16_cfg_t::ocf
pin_name_t ocf
Definition: hallcurrent16.h:180
hallcurrent16_cfg_t::vref
float vref
Definition: hallcurrent16.h:187
hallcurrent16_cfg_t
Hall Current 16 Click configuration object.
Definition: hallcurrent16.h:172
HALLCURRENT16_GAIN_3
@ HALLCURRENT16_GAIN_3
Definition: hallcurrent16.h:143
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:174
HALLCURRENT16_GAIN_2
@ HALLCURRENT16_GAIN_2
Definition: hallcurrent16.h:142
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:175
hallcurrent16_t::chip_select
pin_name_t chip_select
Definition: hallcurrent16.h:159
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:177
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:154
hallcurrent16_t::gain
hallcurrent16_gain_t gain
Definition: hallcurrent16.h:162
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:139
HALLCURRENT16_OK
@ HALLCURRENT16_OK
Definition: hallcurrent16.h:198
HALLCURRENT16_GAIN_1
@ HALLCURRENT16_GAIN_1
Definition: hallcurrent16.h:141
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:152