amrangle2 2.1.0.0
amrangle2.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 AMRANGLE2_H
29#define AMRANGLE2_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#include "drv_analog_in.h"
54
75#define AMRANGLE2_REG_ADC_MODE_CONTROL 0x0000
76#define AMRANGLE2_REG_ADC_CONFIGURATION 0x8000
77#define AMRANGLE2_REG_UNIPOLAR 0x8800
78#define AMRANGLE2_REG_BIPOLAR 0x9000
79#define AMRANGLE2_REG_RANGE 0x9800
80#define AMRANGLE2_REG_CUSTOM_SCAN0 0xA000
81#define AMRANGLE2_REG_CUSTOM_SCAN1 0xA800
82#define AMRANGLE2_REG_SAMPLE_SET 0xB000
83
84 // amrangle2_reg
85
100#define AMRANGLE2_SCAN_UNCHANGED 0x0000
101#define AMRANGLE2_SCAN_MANUAL 0x0800
102#define AMRANGLE2_SCAN_REPEAT 0x1000
103#define AMRANGLE2_SCAN_STANDARD_INT 0x1800
104#define AMRANGLE2_SCAN_STANDARD_EXT 0x2000
105#define AMRANGLE2_SCAN_UPPER_INT 0x2800
106#define AMRANGLE2_SCAN_UPPER_EXT 0x3000
107#define AMRANGLE2_SCAN_CUSTOM_INT 0x3800
108#define AMRANGLE2_SCAN_CUSTOM_EXT 0x4000
109#define AMRANGLE2_SCAN_SAMPLE_SET 0x4800
110#define AMRANGLE2_CHSEL_AIN0 0x0000
111#define AMRANGLE2_CHSEL_AIN1 0x0080
112#define AMRANGLE2_CHSEL_AIN2 0x0100
113#define AMRANGLE2_CHSEL_AIN3 0x0180
114#define AMRANGLE2_RESET_FIFO 0x0020
115#define AMRANGLE2_RESET_ALL 0x0040
116#define AMRANGLE2_PM_NORMAL 0x0000
117#define AMRANGLE2_PM_AUTO_SHUTDOWN 0x0008
118#define AMRANGLE2_PM_AUTO_STANDBY 0x0010
119#define AMRANGLE2_CHAN_ID_ENABLE 0x0004
120#define AMRANGLE2_SWCNV_START 0x0002
121
126#define AMRANGLE2_REFSEL_EXT_DIFFERENTIAL 0x0400
127#define AMRANGLE2_AVGON 0x0200
128#define AMRANGLE2_NAVG_4 0x0000
129#define AMRANGLE2_NAVG_8 0x0080
130#define AMRANGLE2_NAVG_16 0x0100
131#define AMRANGLE2_NAVG_32 0x0180
132#define AMRANGLE2_NSCAN_4 0x0000
133#define AMRANGLE2_NSCAN_8 0x0020
134#define AMRANGLE2_NSCAN_12 0x0040
135#define AMRANGLE2_NSCAN_16 0x0060
136#define AMRANGLE2_SPM_NORMAL 0x0000
137#define AMRANGLE2_SPM_FULL_SHUTDOWN 0x0008
138#define AMRANGLE2_SPM_PARTIAL_SHUTDOWN 0x0010
139#define AMRANGLE2_ECHO_ON 0x0004
140
145#define AMRANGLE2_RANGE01_HALF_VREF 0x0000
146#define AMRANGLE2_RANGE01_FULL_VREF 0x0400
147#define AMRANGLE2_RANGE23_HALF_VREF 0x0000
148#define AMRANGLE2_RANGE23_FULL_VREF 0x0200
149
154#define AMRANGLE2_BCH01_UNIPOLAR 0x0000
155#define AMRANGLE2_BCH01_BIPOLAR_FULLY_DIFF 0x0400
156#define AMRANGLE2_BCH23_UNIPOLAR 0x0000
157#define AMRANGLE2_BCH23_BIPOLAR_FULLY_DIFF 0x0200
158
163#define AMRANGLE2_ADC_VREF 3.3
164#define AMRANGLE2_ADC_RESOLUTION 0x0FFF
165
170#define AMRANGLE2_RADIANS_TO_DEGREES 57.295779513
171#define AMRANGLE2_ANGLE_ZERO_OFFSET 90.0
172
177#define AMRANGLE2_TEMP_VDD 3.3
178#define AMRANGLE2_TEMP_TCAL 25.0
179#define AMRANGLE2_TEMP_TCO 0.003173
180#define AMRANGLE2_TEMP_NUM_CONVERSIONS 100
181
190#define AMRANGLE2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
191#define AMRANGLE2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
192
193 // amrangle2_set
194
209#define AMRANGLE2_MAP_MIKROBUS( cfg, mikrobus ) \
210 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
211 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
212 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
213 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
214 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
215 cfg.cst = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
216 cfg.eoc = MIKROBUS( mikrobus, MIKROBUS_INT )
217
218 // amrangle2_map
219 // amrangle2
220
225typedef struct
226{
227 // Output pins
228 digital_out_t cst;
230 // Input pins
231 digital_in_t eoc;
233 // Modules
234 spi_master_t spi;
235 analog_in_t adc;
237 pin_name_t chip_select;
238 float vcal;
241
246typedef struct
247{
248 // Communication gpio pins
249 pin_name_t miso;
250 pin_name_t mosi;
251 pin_name_t sck;
252 pin_name_t cs;
253 pin_name_t an;
255 // Additional gpio pins
256 pin_name_t cst;
257 pin_name_t eoc;
259 // static variable
260 uint32_t spi_speed;
261 spi_master_mode_t spi_mode;
262 spi_master_chip_select_polarity_t cs_polarity;
264 analog_in_resolution_t resolution;
265 float vref;
268
279
296
311
325
338err_t amrangle2_spi_transfer ( amrangle2_t *ctx, uint16_t data_in );
339
351err_t amrangle2_read_an_pin_value ( amrangle2_t *ctx, uint16_t *data_out );
352
366err_t amrangle2_read_an_pin_voltage ( amrangle2_t *ctx, float *data_out );
367
380
392err_t amrangle2_read_temperature ( amrangle2_t *ctx, float *temperature );
393
406err_t amrangle2_read_vsin_vcos ( amrangle2_t *ctx, float *vsin, float *vcos );
407
419err_t amrangle2_read_angle ( amrangle2_t *ctx, float *angle );
420
430void amrangle2_set_cst_pin ( amrangle2_t *ctx, uint8_t state );
431
441
451
452#ifdef __cplusplus
453}
454#endif
455#endif // AMRANGLE2_H
456
457 // amrangle2
458
459// ------------------------------------------------------------------------ END
amrangle2_return_value_t
AMR Angle 2 Click return value data.
Definition amrangle2.h:274
@ AMRANGLE2_OK
Definition amrangle2.h:275
@ AMRANGLE2_ERROR
Definition amrangle2.h:276
err_t amrangle2_init(amrangle2_t *ctx, amrangle2_cfg_t *cfg)
AMR Angle 2 initialization function.
void amrangle2_cfg_setup(amrangle2_cfg_t *cfg)
AMR Angle 2 configuration object setup function.
void amrangle2_set_cst_pin(amrangle2_t *ctx, uint8_t state)
AMR Angle 2 set cst pin function.
uint8_t amrangle2_get_eoc_pin(amrangle2_t *ctx)
AMR Angle 2 get eoc pin function.
err_t amrangle2_read_angle(amrangle2_t *ctx, float *angle)
AMR Angle 2 read angle function.
err_t amrangle2_default_cfg(amrangle2_t *ctx)
AMR Angle 2 default configuration function.
err_t amrangle2_read_vsin_vcos(amrangle2_t *ctx, float *vsin, float *vcos)
AMR Angle 2 read vsin vcos function.
void amrangle2_start_conversion(amrangle2_t *ctx)
AMR Angle 2 start conversion function.
err_t amrangle2_calibrate_temperature(amrangle2_t *ctx)
AMR Angle 2 calibrate temperature function.
err_t amrangle2_read_temperature(amrangle2_t *ctx, float *temperature)
AMR Angle 2 read temperature function.
err_t amrangle2_spi_transfer(amrangle2_t *ctx, uint16_t data_in)
AMR Angle 2 spi transfer function.
err_t amrangle2_read_an_pin_voltage(amrangle2_t *ctx, float *data_out)
AMR Angle 2 read AN pin voltage level function.
err_t amrangle2_read_an_pin_value(amrangle2_t *ctx, uint16_t *data_out)
AMR Angle 2 read AN pin value function.
This file contains SPI specific macros, functions, etc.
AMR Angle 2 Click configuration object.
Definition amrangle2.h:247
pin_name_t cst
Definition amrangle2.h:256
analog_in_resolution_t resolution
Definition amrangle2.h:264
float vref
Definition amrangle2.h:265
pin_name_t eoc
Definition amrangle2.h:257
spi_master_chip_select_polarity_t cs_polarity
Definition amrangle2.h:262
pin_name_t sck
Definition amrangle2.h:251
spi_master_mode_t spi_mode
Definition amrangle2.h:261
pin_name_t mosi
Definition amrangle2.h:250
uint32_t spi_speed
Definition amrangle2.h:260
pin_name_t miso
Definition amrangle2.h:249
pin_name_t an
Definition amrangle2.h:253
pin_name_t cs
Definition amrangle2.h:252
AMR Angle 2 Click context object.
Definition amrangle2.h:226
spi_master_t spi
Definition amrangle2.h:234
float vcal
Definition amrangle2.h:238
digital_out_t cst
Definition amrangle2.h:228
digital_in_t eoc
Definition amrangle2.h:231
pin_name_t chip_select
Definition amrangle2.h:237
analog_in_t adc
Definition amrangle2.h:235