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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define MAGNETICROTARY6_REG_NOP 0x0000u
71 #define MAGNETICROTARY6_REG_ERRFL 0x0001u
72 #define MAGNETICROTARY6_REG_PROG 0x0003u
73 #define MAGNETICROTARY6_REG_DIA 0x3FF5u
74 #define MAGNETICROTARY6_REG_AGC 0x3FF9u
75 #define MAGNETICROTARY6_REG_SIN_DATA 0x3FFAu
76 #define MAGNETICROTARY6_REG_COS_DATA 0x3FFBu
77 #define MAGNETICROTARY6_REG_VEL 0x3FFCu
78 #define MAGNETICROTARY6_REG_MAG 0x3FFDu
79 #define MAGNETICROTARY6_REG_ANGLEUNC 0x3FFEu
80 #define MAGNETICROTARY6_REG_ANGLECOM 0x3FFFu
81 #define MAGNETICROTARY6_REG_ECC_CHECKSUM 0x00D1u
82 
87 #define MAGNETICROTARY6_REG_DISABLE 0x0015u
88 #define MAGNETICROTARY6_REG_ZPOSM 0x0016u
89 #define MAGNETICROTARY6_REG_ZPOSL 0x0017u
90 #define MAGNETICROTARY6_REG_SETTINGS1 0x0018u
91 #define MAGNETICROTARY6_REG_SETTINGS2 0x0019u
92 #define MAGNETICROTARY6_REG_SETTINGS3 0x001Au
93 #define MAGNETICROTARY6_REG_ECC 0x001Bu
94  // magneticrotary6_reg
96 
111 #define MAGNETICROTARY6_ERRFL_CORDIC_OF 0x0400u
112 #define MAGNETICROTARY6_ERRFL_OFF_COMP_NOT_FIN 0x0200u
113 #define MAGNETICROTARY6_ERRFL_BRKHALL 0x0100u
114 #define MAGNETICROTARY6_ERRFL_WDTST 0x0080u
115 #define MAGNETICROTARY6_ERRFL_CRC_ERROR 0x0040u
116 #define MAGNETICROTARY6_ERRFL_CMD_ERROR 0x0020u
117 #define MAGNETICROTARY6_ERRFL_FRAMING_ERROR 0x0010u
118 #define MAGNETICROTARY6_ERRFL_P2RAM_ERROR 0x0008u
119 #define MAGNETICROTARY6_ERRFL_P2RAM_WARNING 0x0004u
120 #define MAGNETICROTARY6_ERRFL_MAGHALF 0x0002u
121 #define MAGNETICROTARY6_ERRFL_AGC_WARNING 0x0001u
122 
127 #define MAGNETICROTARY6_PROG_PROGVER 0x0040u
128 #define MAGNETICROTARY6_PROG_PROGOTP 0x0008u
129 #define MAGNETICROTARY6_PROG_OTPREF 0x0004u
130 #define MAGNETICROTARY6_PROG_PROGEN 0x0001u
131 
136 #define MAGNETICROTARY6_DIA_SPI_CNT 0x1800u
137 #define MAGNETICROTARY6_DIA_FUSA_ERROR 0x0400u
138 #define MAGNETICROTARY6_DIA_AGC_FIN 0x0200u
139 #define MAGNETICROTARY6_DIA_OFF_COMP_FIN 0x0100u
140 #define MAGNETICROTARY6_DIA_SINOFF_FIN 0x0080u
141 #define MAGNETICROTARY6_DIA_COSOFF_FIN 0x0040u
142 #define MAGNETICROTARY6_DIA_MAGHALF_FLAG 0x0020u
143 #define MAGNETICROTARY6_DIA_COMP_H 0x0010u
144 #define MAGNETICROTARY6_DIA_COMP_L 0x0008u
145 #define MAGNETICROTARY6_DIA_CORDIC_OF 0x0004u
146 #define MAGNETICROTARY6_DIA_LOOPSFIN 0x0002u
147 #define MAGNETICROTARY6_DIA_VDD_MODE_5V 0x0001u
148 #define MAGNETICROTARY6_DIA_VDD_MODE_3V 0x0000u
149 
154 #define MAGNETICROTARY6_DISABLE_FILTER_DISABLE 0x0040u
155 #define MAGNETICROTARY6_DISABLE_BRKHALL_SET 0x003Cu
156 #define MAGNETICROTARY6_DISABLE_ABI_OFF 0x0002u
157 #define MAGNETICROTARY6_DISABLE_UVW_OFF 0x0001u
158 
163 #define MAGNETICROTARY6_ZPOSL_DIA2_EN 0x0080u
164 #define MAGNETICROTARY6_ZPOSL_DIA1_EN 0x0040u
165 #define MAGNETICROTARY6_ZPOSL_LSB 0x003Fu
166 
171 #define MAGNETICROTARY6_SETTINGS1_DIA3_EN 0x0040u
172 #define MAGNETICROTARY6_SETTINGS1_K_MIN 0x0038u
173 #define MAGNETICROTARY6_SETTINGS1_K_MAX 0x0007u
174 
179 #define MAGNETICROTARY6_SETTINGS2_PWMON 0x0080u
180 #define MAGNETICROTARY6_SETTINGS2_DATA_SELECT 0x0040u
181 #define MAGNETICROTARY6_SETTINGS2_ABI_DEC 0x0020u
182 #define MAGNETICROTARY6_SETTINGS2_DAECDIS 0x0010u
183 #define MAGNETICROTARY6_SETTINGS2_UVW_ABI 0x0008u
184 #define MAGNETICROTARY6_SETTINGS2_DIR_CW 0x0000u
185 #define MAGNETICROTARY6_SETTINGS2_DIR_CCW 0x0004u
186 #define MAGNETICROTARY6_SETTINGS2_DIR_MASK 0x0004u
187 #define MAGNETICROTARY6_SETTINGS2_NOISESET 0x0002u
188 #define MAGNETICROTARY6_SETTINGS2_IWIDTH 0x0001u
189 
194 #define MAGNETICROTARY6_SETTINGS3_ABIRES_MASK 0x00E0u
195 #define MAGNETICROTARY6_SETTINGS3_HYS_MASK 0x0018u
196 #define MAGNETICROTARY6_SETTINGS3_UVWPP_1PP 0x0000u
197 #define MAGNETICROTARY6_SETTINGS3_UVWPP_2PP 0x0001u
198 #define MAGNETICROTARY6_SETTINGS3_UVWPP_3PP 0x0002u
199 #define MAGNETICROTARY6_SETTINGS3_UVWPP_4PP 0x0003u
200 #define MAGNETICROTARY6_SETTINGS3_UVWPP_5PP 0x0004u
201 #define MAGNETICROTARY6_SETTINGS3_UVWPP_6PP 0x0005u
202 #define MAGNETICROTARY6_SETTINGS3_UVWPP_7PP 0x0006u
203 #define MAGNETICROTARY6_SETTINGS3_UVWPP_MASK 0x0007u
204 
209 #define MAGNETICROTARY6_ECC_EN 0x0080u
210 #define MAGNETICROTARY6_ECC_CHSUM_MASK 0x007Fu
211 
216 #define MAGNETICROTARY6_DIE_BOTTOM 0
217 #define MAGNETICROTARY6_DIE_TOP 1
218 
223 #define MAGNETICROTARY6_DATA_RESOLUTION 0x3FFFu
224 #define MAGNETICROTARY6_FULL_CIRCLE 360u
225 
230 #define MAGNETICROTARY6_DIR_CW 0
231 #define MAGNETICROTARY6_DIR_CCW 1
232 
239 #define MAGNETICROTARY6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
240 #define MAGNETICROTARY6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
241  // magneticrotary6_set
243 
258 #define MAGNETICROTARY6_MAP_MIKROBUS( cfg, mikrobus ) \
259  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
260  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
261  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
262  cfg.cs_t = MIKROBUS( mikrobus, MIKROBUS_CS ); \
263  cfg.cs_b = MIKROBUS( mikrobus, MIKROBUS_PWM );
264  // magneticrotary6_map // magneticrotary6
267 
272 typedef struct
273 {
274  // Modules
275  spi_master_t spi;
277  pin_name_t cs_t;
278  pin_name_t cs_b;
281 
286 typedef struct
287 {
288  // Communication gpio pins
289  pin_name_t miso;
290  pin_name_t mosi;
291  pin_name_t sck;
292  pin_name_t cs_t;
293  pin_name_t cs_b;
295  // static variable
296  uint32_t spi_speed;
297  spi_master_mode_t spi_mode;
298  spi_master_chip_select_polarity_t cs_polarity;
301 
306 typedef enum
307 {
310 
312 
329 
344 
358 
373 err_t magneticrotary6_write_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t data_in );
374 
389 err_t magneticrotary6_read_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t *data_out );
390 
404 err_t magneticrotary6_get_angle ( magneticrotary6_t *ctx, uint8_t die_sel, float *angle );
405 
418 err_t magneticrotary6_set_direction ( magneticrotary6_t *ctx, uint8_t die_sel, uint8_t dir );
419 
420 #ifdef __cplusplus
421 }
422 #endif
423 #endif // MAGNETICROTARY6_H
424  // magneticrotary6
426 
427 // ------------------------------------------------------------------------ END
magneticrotary6_t::spi
spi_master_t spi
Definition: magneticrotary6.h:275
magneticrotary6_cfg_t::cs_b
pin_name_t cs_b
Definition: magneticrotary6.h:293
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:277
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:287
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:278
magneticrotary6_cfg_t::cs_t
pin_name_t cs_t
Definition: magneticrotary6.h:292
magneticrotary6_return_value_t
magneticrotary6_return_value_t
Magnetic Rotary 6 Click return value data.
Definition: magneticrotary6.h:307
magneticrotary6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary6.h:297
magneticrotary6_t
Magnetic Rotary 6 Click context object.
Definition: magneticrotary6.h:273
magneticrotary6_cfg_t::miso
pin_name_t miso
Definition: magneticrotary6.h:289
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:308
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:298
magneticrotary6_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary6.h:290
magneticrotary6_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary6.h:296
magneticrotary6_cfg_t::sck
pin_name_t sck
Definition: magneticrotary6.h:291
MAGNETICROTARY6_ERROR
@ MAGNETICROTARY6_ERROR
Definition: magneticrotary6.h:309