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 
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 ISOADC_VEXT_MIN 4.5f
75 #define ISOADC_VEXT_5V 5.0f
76 #define ISOADC_VEXT_MAX 5.5f
77 #define ISOADC_ADC_RESOLUTION 65535
78 #define ISOADC_ADC_FSR 320
79 #define ISOADC_ADC_2FSR ( ISOADC_ADC_FSR * 2 )
80 #define ISOADC_ADC_NUM_AVERAGES 65535
81 #define ISOADC_VOLTAGE_NUM_AVERAGES 10
82 #define ISOADC_TIMEOUT_COUNT 1000
83 #define ISOADC_VOLTAGE_TO_CURRENT 0.1f
84 #define ISOADC_MILLI_TO_ONE 1000
85 
94 #define ISOADC_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
95 #define ISOADC_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
96  // isoadc_set
98 
113 #define ISOADC_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
115  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
116  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK );
117  // isoadc_map // isoadc
120 
125 typedef struct
126 {
127  // Modules
128  spi_master_t spi;
130  float vext;
132 } isoadc_t;
133 
138 typedef struct
139 {
140  // Communication gpio pins
141  pin_name_t miso;
142  pin_name_t mosi;
143  pin_name_t sck;
145  // static variable
146  uint32_t spi_speed;
147  spi_master_mode_t spi_mode;
149 } isoadc_cfg_t;
150 
155 typedef enum
156 {
158  ISOADC_ERROR = -1
159 
161 
178 
192 err_t isoadc_init ( isoadc_t *ctx, isoadc_cfg_t *cfg );
193 
205 err_t isoadc_read_raw_adc ( isoadc_t *ctx, uint16_t *data_out );
206 
216 void isoadc_set_vext ( isoadc_t *ctx, float vext );
217 
230 err_t isoadc_read_voltage ( isoadc_t *ctx, float *voltage );
231 
239 float isoadc_get_current ( float voltage );
240 
250 float isoadc_get_power ( isoadc_t *ctx, float voltage );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // ISOADC_H
256  // isoadc
258 
259 // ------------------------------------------------------------------------ END
spi_specifics.h
This file contains SPI specific macros, functions, etc.
isoadc_cfg_t::miso
pin_name_t miso
Definition: isoadc.h:141
isoadc_t
ISO ADC Click context object.
Definition: isoadc.h:126
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:158
isoadc_t::spi
spi_master_t spi
Definition: isoadc.h:128
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:147
isoadc_return_value_t
isoadc_return_value_t
ISO ADC Click return value data.
Definition: isoadc.h:156
isoadc_cfg_t::sck
pin_name_t sck
Definition: isoadc.h:143
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:130
isoadc_cfg_t
ISO ADC Click configuration object.
Definition: isoadc.h:139
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:146
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:142
ISOADC_OK
@ ISOADC_OK
Definition: isoadc.h:157