isoadc  2.1.0.0
isoadc.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 ISOADC_H
29 #define ISOADC_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 ISOADC_VEXT_MIN 4.5f
71 #define ISOADC_VEXT_5V 5.0f
72 #define ISOADC_VEXT_MAX 5.5f
73 #define ISOADC_ADC_RESOLUTION 65535
74 #define ISOADC_ADC_FSR 320
75 #define ISOADC_ADC_2FSR ( ISOADC_ADC_FSR * 2 )
76 #define ISOADC_ADC_NUM_AVERAGES 65535
77 #define ISOADC_VOLTAGE_NUM_AVERAGES 10
78 #define ISOADC_TIMEOUT_COUNT 1000
79 #define ISOADC_VOLTAGE_TO_CURRENT 0.1f
80 #define ISOADC_MILLI_TO_ONE 1000
81 
90 #define ISOADC_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
91 #define ISOADC_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
92  // isoadc_set
94 
109 #define ISOADC_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
111  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
112  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK );
113  // isoadc_map // isoadc
116 
121 typedef struct
122 {
123  // Modules
124  spi_master_t spi;
126  float vext;
128 } isoadc_t;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
141  // static variable
142  uint32_t spi_speed;
143  spi_master_mode_t spi_mode;
145 } isoadc_cfg_t;
146 
151 typedef enum
152 {
154  ISOADC_ERROR = -1
155 
157 
174 
188 err_t isoadc_init ( isoadc_t *ctx, isoadc_cfg_t *cfg );
189 
201 err_t isoadc_read_raw_adc ( isoadc_t *ctx, uint16_t *data_out );
202 
212 void isoadc_set_vext ( isoadc_t *ctx, float vext );
213 
226 err_t isoadc_read_voltage ( isoadc_t *ctx, float *voltage );
227 
235 float isoadc_get_current ( float voltage );
236 
246 float isoadc_get_power ( isoadc_t *ctx, float voltage );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // ISOADC_H
252  // isoadc
254 
255 // ------------------------------------------------------------------------ END
spi_specifics.h
This file contains SPI specific macros, functions, etc.
isoadc_cfg_t::miso
pin_name_t miso
Definition: isoadc.h:137
isoadc_t
ISO ADC Click context object.
Definition: isoadc.h:122
isoadc_set_vext
void isoadc_set_vext(isoadc_t *ctx, float vext)
ISO ADC set vext function.
isoadc_get_current
float isoadc_get_current(float voltage)
ISO ADC get current function.
ISOADC_ERROR
@ ISOADC_ERROR
Definition: isoadc.h:154
isoadc_t::spi
spi_master_t spi
Definition: isoadc.h:124
isoadc_init
err_t isoadc_init(isoadc_t *ctx, isoadc_cfg_t *cfg)
ISO ADC initialization function.
isoadc_get_power
float isoadc_get_power(isoadc_t *ctx, float voltage)
ISO ADC get power function.
isoadc_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: isoadc.h:143
isoadc_return_value_t
isoadc_return_value_t
ISO ADC Click return value data.
Definition: isoadc.h:152
isoadc_cfg_t::sck
pin_name_t sck
Definition: isoadc.h:139
isoadc_read_voltage
err_t isoadc_read_voltage(isoadc_t *ctx, float *voltage)
ISO ADC read voltage function.
isoadc_t::vext
float vext
Definition: isoadc.h:126
isoadc_cfg_t
ISO ADC Click configuration object.
Definition: isoadc.h:135
isoadc_read_raw_adc
err_t isoadc_read_raw_adc(isoadc_t *ctx, uint16_t *data_out)
ISO ADC read raw ADC function.
isoadc_cfg_t::spi_speed
uint32_t spi_speed
Definition: isoadc.h:142
isoadc_cfg_setup
void isoadc_cfg_setup(isoadc_cfg_t *cfg)
ISO ADC configuration object setup function.
isoadc_cfg_t::mosi
pin_name_t mosi
Definition: isoadc.h:138
ISOADC_OK
@ ISOADC_OK
Definition: isoadc.h:153