voltmeter 2.0.0.0
voltmeter.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef VOLTMETER_H
36#define VOLTMETER_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define VOLTMETER_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
80#define VOLTMETER_OK 0
81#define VOLTMETER_ERROR -1
88#define VOLTMETER_DATA_RESOLUTION 0x0FFF
89#define VOLTMETER_VREF_ISOLATED_GND 17.05f
90#define VOLTMETER_VREF_SHARED_GND 8.525f
91#define VOLTMETER_NUM_ADC_CONVERSIONS 100
92#define VOLTMETER_DATA_OFFSET 15
93#define VOLTMETER_GND_ISO 1
94#define VOLTMETER_GND_SHARED 0
97 // End group macro
98// --------------------------------------------------------------- PUBLIC TYPES
107typedef struct
108{
109 // Input pins
110 digital_in_t an;
111
112 // Modules
113 spi_master_t spi;
114 pin_name_t chip_select;
115
117
121typedef struct
122{
123 // Communication gpio pins
124 pin_name_t miso;
125 pin_name_t mosi;
126 pin_name_t sck;
127 pin_name_t cs;
128
129 // Additional gpio pins
130 pin_name_t an;
131
132 // static variable
133 uint32_t spi_speed;
134 spi_master_mode_t spi_mode;
135 spi_master_chip_select_polarity_t cs_polarity;
136
138
139 // End types group
140// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141
146#ifdef __cplusplus
147extern "C"{
148#endif
149
159
168
177
187float voltmeter_calculate_voltage ( voltmeter_t *ctx, int16_t raw_adc, uint8_t iso_gnd );
188
189#ifdef __cplusplus
190}
191#endif
192#endif // _VOLTMETER_H_
193
194 // End public_function group
196
197// ------------------------------------------------------------------------- END
int16_t voltmeter_read_raw_data(voltmeter_t *ctx)
Read raw ADC value function.
err_t voltmeter_init(voltmeter_t *ctx, voltmeter_cfg_t *cfg)
Initialization function.
float voltmeter_calculate_voltage(voltmeter_t *ctx, int16_t raw_adc, uint8_t iso_gnd)
Voltage calculation function.
void voltmeter_cfg_setup(voltmeter_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition voltmeter.h:122
spi_master_chip_select_polarity_t cs_polarity
Definition voltmeter.h:135
pin_name_t sck
Definition voltmeter.h:126
spi_master_mode_t spi_mode
Definition voltmeter.h:134
pin_name_t mosi
Definition voltmeter.h:125
uint32_t spi_speed
Definition voltmeter.h:133
pin_name_t miso
Definition voltmeter.h:124
pin_name_t an
Definition voltmeter.h:130
pin_name_t cs
Definition voltmeter.h:127
Click ctx object definition.
Definition voltmeter.h:108
spi_master_t spi
Definition voltmeter.h:113
digital_in_t an
Definition voltmeter.h:110
pin_name_t chip_select
Definition voltmeter.h:114