angle4  2.0.0.0
angle4.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef ANGLE4_H
36 #define ANGLE4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define ANGLE4_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
59 
65 #define ANGLE4_RETVAL uint8_t
66 
67 #define ANGLE4_OK 0x00
68 #define ANGLE4_INIT_ERROR 0xFF
69 
75 #define ANGLE4_REG_CUSTOMER_CFG_0 0x04
76 #define ANGLE4_REG_CUSTOMER_CFG_1 0x05
77 #define ANGLE4_REG_CUSTOMER_CFG_2 0x06
78 #define ANGLE4_REG_OPERATING_VOLTAGE 0x0A
79 #define ANGLE4_REG_UNLOCK_REGISTER 0x10
80 #define ANGLE4_REG_CUSTOMER_RESERVED_OTP 0x11
81 #define ANGLE4_REG_ST_ZERO_RESET_OTP 0x12
82 #define ANGLE4_REG_CUSTOMER_CONFIG_OTP 0x13
83 #define ANGLE4_REG_PROGRAM_OPERATING_VOLTAGE 0x14
84 #define ANGLE4_REG_CONFIG_OF_FULL_CALIBRATION_OTP 0x1B
85 
91 #define ANGLE4_CCFG0_SELECT_UVW_MODE 0x80
92 #define ANGLE4_CCFG0_SELECT_PWM_MODE 0x00
93 #define ANGLE4_CCFG0_PWM_PERIOD_8193us 0x60
94 #define ANGLE4_CCFG0_PWM_PERIOD_4097us 0x40
95 #define ANGLE4_CCFG0_PWM_PERIOD_2049us 0x20
96 #define ANGLE4_CCFG0_PWM_PERIOD_1025us 0x00
97 #define ANGLE4_CCFG0_ABI_360edeg 0x18
98 #define ANGLE4_CCFG0_ABI_270edeg 0x10
99 #define ANGLE4_CCFG0_ABI_180edeg 0x08
100 #define ANGLE4_CCFG0_ABI_90edeg 0x00
101 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_8 0x07
102 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_7 0x06
103 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_6 0x05
104 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_5 0x04
105 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_4 0x03
106 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_3 0x02
107 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_2 0x01
108 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_1 0x00
109 
115 #define ANGLE4_CCFG1_ABI_CPR_4096 0x70
116 #define ANGLE4_CCFG1_ABI_CPR_2048 0x60
117 #define ANGLE4_CCFG1_ABI_CPR_1024 0x50
118 #define ANGLE4_CCFG1_ABI_CPR_512 0x40
119 #define ANGLE4_CCFG1_ABI_CPR_256 0x30
120 #define ANGLE4_CCFG1_ABI_CPR_128 0x20
121 #define ANGLE4_CCFG1_ABI_CPR_64 0x10
122 #define ANGLE4_CCFG1_ABI_CPR_32 0x00
123 #define ANGLE4_CCFG1_HYSTERESIS_1_4mdeg 0x09
124 #define ANGLE4_CCFG1_HYSTERESIS_0_7mdeg 0x08
125 #define ANGLE4_CCFG1_HYSTERESIS_0_35mdeg 0x07
126 #define ANGLE4_CCFG1_HYSTERESIS_0_17mdeg 0x06
127 #define ANGLE4_CCFG1_HYSTERESIS_0_08mdeg 0x05
128 #define ANGLE4_CCFG1_HYSTERESIS_0_04mdeg 0x04
129 #define ANGLE4_CCFG1_HYSTERESIS_0_02mdeg 0x03
130 #define ANGLE4_CCFG1_HYSTERESIS_0_01mdeg 0x02
131 #define ANGLE4_CCFG1_HYSTERESIS_0_005mdeg 0x01
132 #define ANGLE4_CCFG1_NO_HYSTERESIS 0x00
133 
139 #define ANGLE4_CCFG2_DIR_COUNTER_CLOCKWISE_ROTATION 0x80
140 #define ANGLE4_CCFG2_DIR_CLOCKWISE_ROTATION 0x00
141 #define ANGLE4_CCFG2_ZERO_LATENCY_MODE_ON 0x40
142 #define ANGLE4_CCFG2_ZERO_LATENCY_MODE_OFF 0x00
143 #define ANGLE4_CCFG2_ABS_RESOLUTION_10bit 0x30
144 #define ANGLE4_CCFG2_ABS_RESOLUTION_12bit 0x20
145 #define ANGLE4_CCFG2_ABS_RESOLUTION_14bit 0x10
146 #define ANGLE4_CCFG2_ABS_RESOLUTION_16bit 0x00
147 #define ANGLE4_CCFG2_SETTINGS_CPR_4096 0x06
148 #define ANGLE4_CCFG2_SETTINGS_CPR_2048 0x06
149 #define ANGLE4_CCFG2_SETTINGS_CPR_1024 0x04
150 #define ANGLE4_CCFG2_SETTINGS_CPR_512 0x04
151 #define ANGLE4_CCFG2_SETTINGS_CPR_256 0x03
152 #define ANGLE4_CCFG2_SETTINGS_CPR_128 0x02
153 #define ANGLE4_CCFG2_SETTINGS_CPR_64 0x02
154 #define ANGLE4_CCFG2_SETTINGS_CPR_32 0x02
155 #define ANGLE4_CCFG2_CPR_ABS_RESOLUTION 0x04
156 
162 #define ANGLE4_OPERATING_VOLTAGE_3300mV 0x00
163 #define ANGLE4_OPERATING_VOLTAGE_5000mV 0x02
164 
170 #define ANGLE4_DATA_RESOLUTION_14bit 0x10
171 #define ANGLE4_DATA_RESOLUTION_16bit 0x00
172 #define ANGLE4_DATA_RESOLUTION_12bit 0x30
173 #define ANGLE4_DATA_RESOLUTION_10bit 0x30
174 
180 #define NULL 0x00;
181  // End group macro
184 // --------------------------------------------------------------- PUBLIC TYPES
193 typedef struct
194 {
195  // Modules
196 
197  spi_master_t spi;
198  uint8_t resolution;
199  uint16_t new_angle;
200 
201 } angle4_t;
202 
206 typedef struct
207 {
208  // Communication gpio pins
209 
210  pin_name_t miso;
211  pin_name_t mosi;
212  pin_name_t sck;
213  pin_name_t cs;
214 
215  // static variable
216 
217  hal_spi_speed_t spi_speed;
218  hal_spi_mode_t spi_mode;
219  uint8_t cfg_resolution;
220  uint16_t cfg_new_angle;
221 
222 } angle4_cfg_t;
223  // End types group
225 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
226 
231 #ifdef __cplusplus
232 extern "C"{
233 #endif
234 
243 void angle4_cfg_setup ( angle4_cfg_t *cfg );
244 
253 
263 void angle4_default_cfg ( angle4_t *ctx, uint8_t dir, uint8_t data_resolution );
264 
273 void angle4_generic_transfer ( angle4_t *ctx, spi_master_transfer_data_t *block );
274 
284 void angle4_write_byte ( angle4_t *ctx, uint8_t addr, uint8_t w_data );
285 
295 uint8_t angle4_read_byte ( angle4_t *ctx, uint8_t addr );
296 
304 void angle4_start_mesuremenet ( angle4_t *ctx );
305 
325 uint8_t angle4_get_new_angle ( angle4_t *ctx, uint16_t *data_out );
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 #endif // _ANGLE4_H_
331  // End public_function group
334 
335 // ------------------------------------------------------------------------- END
angle4_t::spi
spi_master_t spi
Definition: angle4.h:197
angle4_read_byte
uint8_t angle4_read_byte(angle4_t *ctx, uint8_t addr)
One byte read function.
angle4_cfg_t::miso
pin_name_t miso
Definition: angle4.h:210
angle4_cfg_t::sck
pin_name_t sck
Definition: angle4.h:212
angle4_t::resolution
uint8_t resolution
Definition: angle4.h:198
angle4_default_cfg
void angle4_default_cfg(angle4_t *ctx, uint8_t dir, uint8_t data_resolution)
Click Default Configuration function.
angle4_t
Click ctx object definition.
Definition: angle4.h:193
angle4_cfg_t
Click configuration structure definition.
Definition: angle4.h:206
angle4_cfg_t::cfg_resolution
uint8_t cfg_resolution
Definition: angle4.h:219
angle4_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: angle4.h:218
angle4_cfg_t::cs
pin_name_t cs
Definition: angle4.h:213
angle4_cfg_t::cfg_new_angle
uint16_t cfg_new_angle
Definition: angle4.h:220
ANGLE4_RETVAL
#define ANGLE4_RETVAL
Definition: angle4.h:65
angle4_cfg_t::mosi
pin_name_t mosi
Definition: angle4.h:211
angle4_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: angle4.h:217
angle4_t::new_angle
uint16_t new_angle
Definition: angle4.h:199
angle4_generic_transfer
void angle4_generic_transfer(angle4_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
angle4_init
ANGLE4_RETVAL angle4_init(angle4_t *ctx, angle4_cfg_t *cfg)
Initialization function.
angle4_write_byte
void angle4_write_byte(angle4_t *ctx, uint8_t addr, uint8_t w_data)
One byte write function.
angle4_start_mesuremenet
void angle4_start_mesuremenet(angle4_t *ctx)
Start meaasurement function.
angle4_get_new_angle
uint8_t angle4_get_new_angle(angle4_t *ctx, uint16_t *data_out)
Functions for reading Angle.
angle4_cfg_setup
void angle4_cfg_setup(angle4_cfg_t *cfg)
Config Object Initialization function.