angle4  2.0.0.0
angle4.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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef ANGLE4_H
35 #define ANGLE4_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ANGLE4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define ANGLE4_RETVAL uint8_t
64 
65 #define ANGLE4_OK 0x00
66 #define ANGLE4_INIT_ERROR 0xFF
67 
73 #define ANGLE4_REG_CUSTOMER_CFG_0 0x04
74 #define ANGLE4_REG_CUSTOMER_CFG_1 0x05
75 #define ANGLE4_REG_CUSTOMER_CFG_2 0x06
76 #define ANGLE4_REG_OPERATING_VOLTAGE 0x0A
77 #define ANGLE4_REG_UNLOCK_REGISTER 0x10
78 #define ANGLE4_REG_CUSTOMER_RESERVED_OTP 0x11
79 #define ANGLE4_REG_ST_ZERO_RESET_OTP 0x12
80 #define ANGLE4_REG_CUSTOMER_CONFIG_OTP 0x13
81 #define ANGLE4_REG_PROGRAM_OPERATING_VOLTAGE 0x14
82 #define ANGLE4_REG_CONFIG_OF_FULL_CALIBRATION_OTP 0x1B
83 
89 #define ANGLE4_CCFG0_SELECT_UVW_MODE 0x80
90 #define ANGLE4_CCFG0_SELECT_PWM_MODE 0x00
91 #define ANGLE4_CCFG0_PWM_PERIOD_8193us 0x60
92 #define ANGLE4_CCFG0_PWM_PERIOD_4097us 0x40
93 #define ANGLE4_CCFG0_PWM_PERIOD_2049us 0x20
94 #define ANGLE4_CCFG0_PWM_PERIOD_1025us 0x00
95 #define ANGLE4_CCFG0_ABI_360edeg 0x18
96 #define ANGLE4_CCFG0_ABI_270edeg 0x10
97 #define ANGLE4_CCFG0_ABI_180edeg 0x08
98 #define ANGLE4_CCFG0_ABI_90edeg 0x00
99 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_8 0x07
100 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_7 0x06
101 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_6 0x05
102 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_5 0x04
103 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_4 0x03
104 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_3 0x02
105 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_2 0x01
106 #define ANGLE4_CCFG0_UVW_POLE_PAIRS_1 0x00
107 
113 #define ANGLE4_CCFG1_ABI_CPR_4096 0x70
114 #define ANGLE4_CCFG1_ABI_CPR_2048 0x60
115 #define ANGLE4_CCFG1_ABI_CPR_1024 0x50
116 #define ANGLE4_CCFG1_ABI_CPR_512 0x40
117 #define ANGLE4_CCFG1_ABI_CPR_256 0x30
118 #define ANGLE4_CCFG1_ABI_CPR_128 0x20
119 #define ANGLE4_CCFG1_ABI_CPR_64 0x10
120 #define ANGLE4_CCFG1_ABI_CPR_32 0x00
121 #define ANGLE4_CCFG1_HYSTERESIS_1_4mdeg 0x09
122 #define ANGLE4_CCFG1_HYSTERESIS_0_7mdeg 0x08
123 #define ANGLE4_CCFG1_HYSTERESIS_0_35mdeg 0x07
124 #define ANGLE4_CCFG1_HYSTERESIS_0_17mdeg 0x06
125 #define ANGLE4_CCFG1_HYSTERESIS_0_08mdeg 0x05
126 #define ANGLE4_CCFG1_HYSTERESIS_0_04mdeg 0x04
127 #define ANGLE4_CCFG1_HYSTERESIS_0_02mdeg 0x03
128 #define ANGLE4_CCFG1_HYSTERESIS_0_01mdeg 0x02
129 #define ANGLE4_CCFG1_HYSTERESIS_0_005mdeg 0x01
130 #define ANGLE4_CCFG1_NO_HYSTERESIS 0x00
131 
137 #define ANGLE4_CCFG2_DIR_COUNTER_CLOCKWISE_ROTATION 0x80
138 #define ANGLE4_CCFG2_DIR_CLOCKWISE_ROTATION 0x00
139 #define ANGLE4_CCFG2_ZERO_LATENCY_MODE_ON 0x40
140 #define ANGLE4_CCFG2_ZERO_LATENCY_MODE_OFF 0x00
141 #define ANGLE4_CCFG2_ABS_RESOLUTION_10bit 0x30
142 #define ANGLE4_CCFG2_ABS_RESOLUTION_12bit 0x20
143 #define ANGLE4_CCFG2_ABS_RESOLUTION_14bit 0x10
144 #define ANGLE4_CCFG2_ABS_RESOLUTION_16bit 0x00
145 #define ANGLE4_CCFG2_SETTINGS_CPR_4096 0x06
146 #define ANGLE4_CCFG2_SETTINGS_CPR_2048 0x06
147 #define ANGLE4_CCFG2_SETTINGS_CPR_1024 0x04
148 #define ANGLE4_CCFG2_SETTINGS_CPR_512 0x04
149 #define ANGLE4_CCFG2_SETTINGS_CPR_256 0x03
150 #define ANGLE4_CCFG2_SETTINGS_CPR_128 0x02
151 #define ANGLE4_CCFG2_SETTINGS_CPR_64 0x02
152 #define ANGLE4_CCFG2_SETTINGS_CPR_32 0x02
153 #define ANGLE4_CCFG2_CPR_ABS_RESOLUTION 0x04
154 
160 #define ANGLE4_OPERATING_VOLTAGE_3300mV 0x00
161 #define ANGLE4_OPERATING_VOLTAGE_5000mV 0x02
162 
168 #define ANGLE4_DATA_RESOLUTION_14bit 0x10
169 #define ANGLE4_DATA_RESOLUTION_16bit 0x00
170 #define ANGLE4_DATA_RESOLUTION_12bit 0x30
171 #define ANGLE4_DATA_RESOLUTION_10bit 0x30
172  // End group macro
175 // --------------------------------------------------------------- PUBLIC TYPES
184 typedef struct
185 {
186  digital_out_t cs;
187 
188  // Modules
189 
190  spi_master_t spi;
191  pin_name_t chip_select;
192 
193  uint8_t resolution;
194  uint16_t new_angle;
195 
196 } angle4_t;
197 
201 typedef struct
202 {
203  // Communication gpio pins
204 
205  pin_name_t miso;
206  pin_name_t mosi;
207  pin_name_t sck;
208  pin_name_t cs;
209 
210  // static variable
211 
212  uint32_t spi_speed;
213  spi_master_mode_t spi_mode;
214  spi_master_chip_select_polarity_t cs_polarity;
215 
216  uint8_t cfg_resolution;
217  uint16_t cfg_new_angle;
218 
219 } angle4_cfg_t;
220  // End types group
222 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
223 
228 #ifdef __cplusplus
229 extern "C"{
230 #endif
231 
241 
251 
261 void angle4_default_cfg ( angle4_t *ctx, uint8_t dir, uint8_t data_resolution );
262 
274 void angle4_generic_transfer ( angle4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
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 
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::chip_select
pin_name_t chip_select
Definition: angle4.h:191
angle4_t::spi
spi_master_t spi
Definition: angle4.h:190
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:205
angle4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: angle4.h:213
angle4_cfg_t::sck
pin_name_t sck
Definition: angle4.h:207
angle4_t::cs
digital_out_t cs
Definition: angle4.h:186
angle4_t::resolution
uint8_t resolution
Definition: angle4.h:193
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:185
angle4_cfg_t
Click configuration structure definition.
Definition: angle4.h:202
angle4_cfg_t::cfg_resolution
uint8_t cfg_resolution
Definition: angle4.h:216
angle4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: angle4.h:214
angle4_cfg_t::cs
pin_name_t cs
Definition: angle4.h:208
angle4_cfg_t::cfg_new_angle
uint16_t cfg_new_angle
Definition: angle4.h:217
angle4_generic_transfer
void angle4_generic_transfer(angle4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
ANGLE4_RETVAL
#define ANGLE4_RETVAL
Definition: angle4.h:63
angle4_cfg_t::mosi
pin_name_t mosi
Definition: angle4.h:206
angle4_t::new_angle
uint16_t new_angle
Definition: angle4.h:194
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.
angle4_cfg_t::spi_speed
uint32_t spi_speed
Definition: angle4.h:212