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
32extern "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
97 // 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
118 // isoadc_map
119 // isoadc
120
125typedef struct
126{
127 // Modules
128 spi_master_t spi;
130 float vext;
132} isoadc_t;
133
138typedef 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;
150
155typedef enum
156{
158 ISOADC_ERROR = -1
159
161
178
192err_t isoadc_init ( isoadc_t *ctx, isoadc_cfg_t *cfg );
193
205err_t isoadc_read_raw_adc ( isoadc_t *ctx, uint16_t *data_out );
206
216void isoadc_set_vext ( isoadc_t *ctx, float vext );
217
230err_t isoadc_read_voltage ( isoadc_t *ctx, float *voltage );
231
239float isoadc_get_current ( float voltage );
240
250float isoadc_get_power ( isoadc_t *ctx, float voltage );
251
252#ifdef __cplusplus
253}
254#endif
255#endif // ISOADC_H
256
257 // isoadc
258
259// ------------------------------------------------------------------------ END
err_t isoadc_read_voltage(isoadc_t *ctx, float *voltage)
ISO ADC read voltage function.
float isoadc_get_power(isoadc_t *ctx, float voltage)
ISO ADC get power function.
void isoadc_cfg_setup(isoadc_cfg_t *cfg)
ISO ADC configuration object setup function.
err_t isoadc_init(isoadc_t *ctx, isoadc_cfg_t *cfg)
ISO ADC initialization function.
err_t isoadc_read_raw_adc(isoadc_t *ctx, uint16_t *data_out)
ISO ADC read raw ADC function.
void isoadc_set_vext(isoadc_t *ctx, float vext)
ISO ADC set vext function.
float isoadc_get_current(float voltage)
ISO ADC get current function.
isoadc_return_value_t
ISO ADC Click return value data.
Definition isoadc.h:156
@ ISOADC_ERROR
Definition isoadc.h:158
@ ISOADC_OK
Definition isoadc.h:157
This file contains SPI specific macros, functions, etc.
ISO ADC Click configuration object.
Definition isoadc.h:139
pin_name_t sck
Definition isoadc.h:143
spi_master_mode_t spi_mode
Definition isoadc.h:147
pin_name_t mosi
Definition isoadc.h:142
uint32_t spi_speed
Definition isoadc.h:146
pin_name_t miso
Definition isoadc.h:141
ISO ADC Click context object.
Definition isoadc.h:126
spi_master_t spi
Definition isoadc.h:128
float vext
Definition isoadc.h:130