magneticrotary6  2.0.0.0
magneticrotary6.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 MAGNETICROTARY6_H
29 #define MAGNETICROTARY6_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 MAGNETICROTARY6_REG_NOP 0x0000u
75 #define MAGNETICROTARY6_REG_ERRFL 0x0001u
76 #define MAGNETICROTARY6_REG_PROG 0x0003u
77 #define MAGNETICROTARY6_REG_DIA 0x3FF5u
78 #define MAGNETICROTARY6_REG_AGC 0x3FF9u
79 #define MAGNETICROTARY6_REG_SIN_DATA 0x3FFAu
80 #define MAGNETICROTARY6_REG_COS_DATA 0x3FFBu
81 #define MAGNETICROTARY6_REG_VEL 0x3FFCu
82 #define MAGNETICROTARY6_REG_MAG 0x3FFDu
83 #define MAGNETICROTARY6_REG_ANGLEUNC 0x3FFEu
84 #define MAGNETICROTARY6_REG_ANGLECOM 0x3FFFu
85 #define MAGNETICROTARY6_REG_ECC_CHECKSUM 0x00D1u
86 
91 #define MAGNETICROTARY6_REG_DISABLE 0x0015u
92 #define MAGNETICROTARY6_REG_ZPOSM 0x0016u
93 #define MAGNETICROTARY6_REG_ZPOSL 0x0017u
94 #define MAGNETICROTARY6_REG_SETTINGS1 0x0018u
95 #define MAGNETICROTARY6_REG_SETTINGS2 0x0019u
96 #define MAGNETICROTARY6_REG_SETTINGS3 0x001Au
97 #define MAGNETICROTARY6_REG_ECC 0x001Bu
98  // magneticrotary6_reg
100 
115 #define MAGNETICROTARY6_ERRFL_CORDIC_OF 0x0400u
116 #define MAGNETICROTARY6_ERRFL_OFF_COMP_NOT_FIN 0x0200u
117 #define MAGNETICROTARY6_ERRFL_BRKHALL 0x0100u
118 #define MAGNETICROTARY6_ERRFL_WDTST 0x0080u
119 #define MAGNETICROTARY6_ERRFL_CRC_ERROR 0x0040u
120 #define MAGNETICROTARY6_ERRFL_CMD_ERROR 0x0020u
121 #define MAGNETICROTARY6_ERRFL_FRAMING_ERROR 0x0010u
122 #define MAGNETICROTARY6_ERRFL_P2RAM_ERROR 0x0008u
123 #define MAGNETICROTARY6_ERRFL_P2RAM_WARNING 0x0004u
124 #define MAGNETICROTARY6_ERRFL_MAGHALF 0x0002u
125 #define MAGNETICROTARY6_ERRFL_AGC_WARNING 0x0001u
126 
131 #define MAGNETICROTARY6_PROG_PROGVER 0x0040u
132 #define MAGNETICROTARY6_PROG_PROGOTP 0x0008u
133 #define MAGNETICROTARY6_PROG_OTPREF 0x0004u
134 #define MAGNETICROTARY6_PROG_PROGEN 0x0001u
135 
140 #define MAGNETICROTARY6_DIA_SPI_CNT 0x1800u
141 #define MAGNETICROTARY6_DIA_FUSA_ERROR 0x0400u
142 #define MAGNETICROTARY6_DIA_AGC_FIN 0x0200u
143 #define MAGNETICROTARY6_DIA_OFF_COMP_FIN 0x0100u
144 #define MAGNETICROTARY6_DIA_SINOFF_FIN 0x0080u
145 #define MAGNETICROTARY6_DIA_COSOFF_FIN 0x0040u
146 #define MAGNETICROTARY6_DIA_MAGHALF_FLAG 0x0020u
147 #define MAGNETICROTARY6_DIA_COMP_H 0x0010u
148 #define MAGNETICROTARY6_DIA_COMP_L 0x0008u
149 #define MAGNETICROTARY6_DIA_CORDIC_OF 0x0004u
150 #define MAGNETICROTARY6_DIA_LOOPSFIN 0x0002u
151 #define MAGNETICROTARY6_DIA_VDD_MODE_5V 0x0001u
152 #define MAGNETICROTARY6_DIA_VDD_MODE_3V 0x0000u
153 
158 #define MAGNETICROTARY6_DISABLE_FILTER_DISABLE 0x0040u
159 #define MAGNETICROTARY6_DISABLE_BRKHALL_SET 0x003Cu
160 #define MAGNETICROTARY6_DISABLE_ABI_OFF 0x0002u
161 #define MAGNETICROTARY6_DISABLE_UVW_OFF 0x0001u
162 
167 #define MAGNETICROTARY6_ZPOSL_DIA2_EN 0x0080u
168 #define MAGNETICROTARY6_ZPOSL_DIA1_EN 0x0040u
169 #define MAGNETICROTARY6_ZPOSL_LSB 0x003Fu
170 
175 #define MAGNETICROTARY6_SETTINGS1_DIA3_EN 0x0040u
176 #define MAGNETICROTARY6_SETTINGS1_K_MIN 0x0038u
177 #define MAGNETICROTARY6_SETTINGS1_K_MAX 0x0007u
178 
183 #define MAGNETICROTARY6_SETTINGS2_PWMON 0x0080u
184 #define MAGNETICROTARY6_SETTINGS2_DATA_SELECT 0x0040u
185 #define MAGNETICROTARY6_SETTINGS2_ABI_DEC 0x0020u
186 #define MAGNETICROTARY6_SETTINGS2_DAECDIS 0x0010u
187 #define MAGNETICROTARY6_SETTINGS2_UVW_ABI 0x0008u
188 #define MAGNETICROTARY6_SETTINGS2_DIR_CW 0x0000u
189 #define MAGNETICROTARY6_SETTINGS2_DIR_CCW 0x0004u
190 #define MAGNETICROTARY6_SETTINGS2_DIR_MASK 0x0004u
191 #define MAGNETICROTARY6_SETTINGS2_NOISESET 0x0002u
192 #define MAGNETICROTARY6_SETTINGS2_IWIDTH 0x0001u
193 
198 #define MAGNETICROTARY6_SETTINGS3_ABIRES_MASK 0x00E0u
199 #define MAGNETICROTARY6_SETTINGS3_HYS_MASK 0x0018u
200 #define MAGNETICROTARY6_SETTINGS3_UVWPP_1PP 0x0000u
201 #define MAGNETICROTARY6_SETTINGS3_UVWPP_2PP 0x0001u
202 #define MAGNETICROTARY6_SETTINGS3_UVWPP_3PP 0x0002u
203 #define MAGNETICROTARY6_SETTINGS3_UVWPP_4PP 0x0003u
204 #define MAGNETICROTARY6_SETTINGS3_UVWPP_5PP 0x0004u
205 #define MAGNETICROTARY6_SETTINGS3_UVWPP_6PP 0x0005u
206 #define MAGNETICROTARY6_SETTINGS3_UVWPP_7PP 0x0006u
207 #define MAGNETICROTARY6_SETTINGS3_UVWPP_MASK 0x0007u
208 
213 #define MAGNETICROTARY6_ECC_EN 0x0080u
214 #define MAGNETICROTARY6_ECC_CHSUM_MASK 0x007Fu
215 
220 #define MAGNETICROTARY6_DIE_BOTTOM 0
221 #define MAGNETICROTARY6_DIE_TOP 1
222 
227 #define MAGNETICROTARY6_DATA_RESOLUTION 0x3FFFu
228 #define MAGNETICROTARY6_FULL_CIRCLE 360u
229 
234 #define MAGNETICROTARY6_DIR_CW 0
235 #define MAGNETICROTARY6_DIR_CCW 1
236 
243 #define MAGNETICROTARY6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
244 #define MAGNETICROTARY6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
245  // magneticrotary6_set
247 
262 #define MAGNETICROTARY6_MAP_MIKROBUS( cfg, mikrobus ) \
263  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
264  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
265  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
266  cfg.cs_t = MIKROBUS( mikrobus, MIKROBUS_CS ); \
267  cfg.cs_b = MIKROBUS( mikrobus, MIKROBUS_PWM );
268  // magneticrotary6_map // magneticrotary6
271 
276 typedef struct
277 {
278  // Modules
279  spi_master_t spi;
281  pin_name_t cs_t;
282  pin_name_t cs_b;
285 
290 typedef struct
291 {
292  // Communication gpio pins
293  pin_name_t miso;
294  pin_name_t mosi;
295  pin_name_t sck;
296  pin_name_t cs_t;
297  pin_name_t cs_b;
299  // static variable
300  uint32_t spi_speed;
301  spi_master_mode_t spi_mode;
302  spi_master_chip_select_polarity_t cs_polarity;
305 
310 typedef enum
311 {
314 
316 
333 
348 
362 
377 err_t magneticrotary6_write_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t data_in );
378 
393 err_t magneticrotary6_read_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t *data_out );
394 
408 err_t magneticrotary6_get_angle ( magneticrotary6_t *ctx, uint8_t die_sel, float *angle );
409 
422 err_t magneticrotary6_set_direction ( magneticrotary6_t *ctx, uint8_t die_sel, uint8_t dir );
423 
424 #ifdef __cplusplus
425 }
426 #endif
427 #endif // MAGNETICROTARY6_H
428  // magneticrotary6
430 
431 // ------------------------------------------------------------------------ END
magneticrotary6_t::spi
spi_master_t spi
Definition: magneticrotary6.h:279
magneticrotary6_cfg_t::cs_b
pin_name_t cs_b
Definition: magneticrotary6.h:297
magneticrotary6_read_register
err_t magneticrotary6_read_register(magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 6 read register b function.
magneticrotary6_get_angle
err_t magneticrotary6_get_angle(magneticrotary6_t *ctx, uint8_t die_sel, float *angle)
Magnetic Rotary 6 get angle function.
magneticrotary6_t::cs_t
pin_name_t cs_t
Definition: magneticrotary6.h:281
magneticrotary6_cfg_setup
void magneticrotary6_cfg_setup(magneticrotary6_cfg_t *cfg)
Magnetic Rotary 6 configuration object setup function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary6_default_cfg
err_t magneticrotary6_default_cfg(magneticrotary6_t *ctx)
Magnetic Rotary 6 default configuration function.
magneticrotary6_cfg_t
Magnetic Rotary 6 Click configuration object.
Definition: magneticrotary6.h:291
magneticrotary6_init
err_t magneticrotary6_init(magneticrotary6_t *ctx, magneticrotary6_cfg_t *cfg)
Magnetic Rotary 6 initialization function.
magneticrotary6_t::cs_b
pin_name_t cs_b
Definition: magneticrotary6.h:282
magneticrotary6_cfg_t::cs_t
pin_name_t cs_t
Definition: magneticrotary6.h:296
magneticrotary6_return_value_t
magneticrotary6_return_value_t
Magnetic Rotary 6 Click return value data.
Definition: magneticrotary6.h:311
magneticrotary6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary6.h:301
magneticrotary6_t
Magnetic Rotary 6 Click context object.
Definition: magneticrotary6.h:277
magneticrotary6_cfg_t::miso
pin_name_t miso
Definition: magneticrotary6.h:293
magneticrotary6_write_register
err_t magneticrotary6_write_register(magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t data_in)
Magnetic Rotary 6 write register function.
MAGNETICROTARY6_OK
@ MAGNETICROTARY6_OK
Definition: magneticrotary6.h:312
magneticrotary6_set_direction
err_t magneticrotary6_set_direction(magneticrotary6_t *ctx, uint8_t die_sel, uint8_t dir)
Magnetic Rotary 6 set direction function.
magneticrotary6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary6.h:302
magneticrotary6_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary6.h:294
magneticrotary6_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary6.h:300
magneticrotary6_cfg_t::sck
pin_name_t sck
Definition: magneticrotary6.h:295
MAGNETICROTARY6_ERROR
@ MAGNETICROTARY6_ERROR
Definition: magneticrotary6.h:313