currentsens2  2.1.0.0
currentsens2.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 CURRENTSENS2_H
29 #define CURRENTSENS2_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_analog_in.h"
52 
73 #define CURRENTSENS2_CONV_FACTOR 12.5f
74 #define CURRENTSENS2_NUM_CONVERSIONS 10
75 #define CURRENTSENS2_NUM_OF_PASSES_1 1
76 #define CURRENTSENS2_NUM_OF_PASSES_2 2
77 #define CURRENTSENS2_NUM_OF_PASSES_3 3
78  // currentsens2_set
80 
95 #define CURRENTSENS2_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
97  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
98  // currentsens2_map // currentsens2
101 
106 typedef struct
107 {
108  digital_in_t int_pin;
110  analog_in_t adc;
112  float zero_val;
113  uint8_t no_of_turns;
116 
121 typedef struct
122 {
123  pin_name_t an;
124  pin_name_t int_pin;
126  analog_in_resolution_t resolution;
127  float vref;
130 
135 typedef enum
136 {
138  CURRENTSENS2_ERROR = -1
139 
141 
158 
173 
185 err_t currentsens2_read_an_pin_value ( currentsens2_t *ctx, uint16_t *data_out );
186 
200 err_t currentsens2_read_an_pin_vol ( currentsens2_t *ctx, float *data_out );
201 
212 
222 void currentsens2_set_prim_turn_no ( currentsens2_t *ctx, uint8_t turns );
223 
235 
247 err_t currentsens2_get_current ( currentsens2_t *ctx, float *current );
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 #endif // CURRENTSENS2_H
253  // currentsens2
255 
256 // ------------------------------------------------------------------------ END
currentsens2_cfg_t::vref
float vref
Definition: currentsens2.h:127
currentsens2_get_current
err_t currentsens2_get_current(currentsens2_t *ctx, float *current)
Current Sens 2 read current function.
currentsens2_t::adc
analog_in_t adc
Definition: currentsens2.h:110
currentsens2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: currentsens2.h:126
currentsens2_cfg_setup
void currentsens2_cfg_setup(currentsens2_cfg_t *cfg)
Current Sens 2 configuration object setup function.
currentsens2_cfg_t::an
pin_name_t an
Definition: currentsens2.h:123
currentsens2_t::int_pin
digital_in_t int_pin
Definition: currentsens2.h:108
currentsens2_get_int_pin
uint8_t currentsens2_get_int_pin(currentsens2_t *ctx)
Current Sens 2 get int pin state function.
currentsens2_t
Current Sens 2 Click context object.
Definition: currentsens2.h:107
CURRENTSENS2_OK
@ CURRENTSENS2_OK
Definition: currentsens2.h:137
currentsens2_set_prim_turn_no
void currentsens2_set_prim_turn_no(currentsens2_t *ctx, uint8_t turns)
Current Sens 2 set number of primary coil turns function.
CURRENTSENS2_ERROR
@ CURRENTSENS2_ERROR
Definition: currentsens2.h:138
currentsens2_return_value_t
currentsens2_return_value_t
Current Sens 2 Click return value data.
Definition: currentsens2.h:136
currentsens2_read_an_pin_value
err_t currentsens2_read_an_pin_value(currentsens2_t *ctx, uint16_t *data_out)
Current Sens 2 read AN pin value function.
currentsens2_init
err_t currentsens2_init(currentsens2_t *ctx, currentsens2_cfg_t *cfg)
Current Sens 2 initialization function.
currentsens2_cfg_t::int_pin
pin_name_t int_pin
Definition: currentsens2.h:124
currentsens2_cfg_t
Current Sens 2 Click configuration object.
Definition: currentsens2.h:122
currentsens2_tare
err_t currentsens2_tare(currentsens2_t *ctx)
Current Sens 2 tare function.
currentsens2_t::no_of_turns
uint8_t no_of_turns
Definition: currentsens2.h:113
currentsens2_t::zero_val
float zero_val
Definition: currentsens2.h:112
currentsens2_read_an_pin_vol
err_t currentsens2_read_an_pin_vol(currentsens2_t *ctx, float *data_out)
Current Sens 2 read AN pin voltage level function.