angle7 2.0.0.0
angle7.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 ANGLE7_H
29#define ANGLE7_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_i2c_master.h"
52#include "drv_analog_in.h"
53
74#define ANGLE7_REG_ZMCO 0x00
75#define ANGLE7_REG_ZPOS_MSB 0x01
76#define ANGLE7_REG_ZPOS_LSB 0x02
77#define ANGLE7_REG_MPOS_MSB 0x03
78#define ANGLE7_REG_MPOS_LSB 0x04
79#define ANGLE7_REG_MANG_MSB 0x05
80#define ANGLE7_REG_MANG_LSB 0x06
81#define ANGLE7_REG_CONF_MSB 0x07
82#define ANGLE7_REG_CONF_LSB 0x08
83#define ANGLE7_REG_STATUS 0x0B
84#define ANGLE7_REG_RAW_ANGLE_MSB 0x0C
85#define ANGLE7_REG_RAW_ANGLE_LSB 0x0D
86#define ANGLE7_REG_ANGLE_MSB 0x0E
87#define ANGLE7_REG_ANGLE_LSB 0x0F
88#define ANGLE7_REG_AGC 0x1A
89#define ANGLE7_REG_MAGNITUDE_MSB 0x1B
90#define ANGLE7_REG_MAGNITUDE_LSB 0x1C
91#define ANGLE7_REG_BURN 0xFF
92
93 // angle7_reg
94
109#define ANGLE7_CONF_WATCHDOG_OFF 0x0000
110#define ANGLE7_CONF_WATCHDOG_ON 0x2000
111#define ANGLE7_CONF_WATCHDOG_BIT_MASK 0x2000
112#define ANGLE7_CONF_FTH_SLOW 0x0000
113#define ANGLE7_CONF_FTH_6LSB 0x0400
114#define ANGLE7_CONF_FTH_7LSB 0x0800
115#define ANGLE7_CONF_FTH_9LSB 0x0C00
116#define ANGLE7_CONF_FTH_18LSB 0x1000
117#define ANGLE7_CONF_FTH_21LSB 0x1400
118#define ANGLE7_CONF_FTH_24LSB 0x1800
119#define ANGLE7_CONF_FTH_10LSB 0x1C00
120#define ANGLE7_CONF_FTH_BIT_MASK 0x1C00
121#define ANGLE7_CONF_SF_16X 0x0000
122#define ANGLE7_CONF_SF_8X 0x0100
123#define ANGLE7_CONF_SF_4X 0x0200
124#define ANGLE7_CONF_SF_2X 0x0300
125#define ANGLE7_CONF_SF_BIT_MASK 0x0300
126#define ANGLE7_CONF_PWMF_115HZ 0x0000
127#define ANGLE7_CONF_PWMF_230HZ 0x0040
128#define ANGLE7_CONF_PWMF_460HZ 0x0080
129#define ANGLE7_CONF_PWMF_920HZ 0x00C0
130#define ANGLE7_CONF_PWMF_BIT_MASK 0x00C0
131#define ANGLE7_CONF_OUTS_ANALOG_FULL 0x0000
132#define ANGLE7_CONF_OUTS_ANALOG_REDUCED 0x0010
133#define ANGLE7_CONF_OUTS_PWM 0x0020
134#define ANGLE7_CONF_OUTS_BIT_MASK 0x0030
135#define ANGLE7_CONF_HYST_OFF 0x0000
136#define ANGLE7_CONF_HYST_1LSB 0x0004
137#define ANGLE7_CONF_HYST_2LSB 0x0008
138#define ANGLE7_CONF_HYST_3LSB 0x000C
139#define ANGLE7_CONF_HYST_BIT_MASK 0x000C
140#define ANGLE7_CONF_PM_NOM 0x0000
141#define ANGLE7_CONF_PM_LPM1 0x0001
142#define ANGLE7_CONF_PM_LPM2 0x0002
143#define ANGLE7_CONF_PM_LPM3 0x0003
144#define ANGLE7_CONF_PM_BIT_MASK 0x0003
145
150#define ANGLE7_STATUS_MAGNET_DETECTED 0x20
151#define ANGLE7_STATUS_MAGNET_TOO_WEAK 0x10
152#define ANGLE7_STATUS_MAGNET_TOO_STRONG 0x08
153
158#define ANGLE7_BURN_ANGLE 0x80
159#define ANGLE7_BURN_SETTING 0x40
160
165#define ANGLE7_RESOLUTION 0x0FFF
166#define ANGLE7_FULL_CIRCLE 360.0
167#define ANGLE7_ZERO_POSITION 0.0
168
174#define ANGLE7_DEVICE_ADDRESS 0x36
175
176 // angle7_set
177
192#define ANGLE7_MAP_MIKROBUS( cfg, mikrobus ) \
193 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
194 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
195 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
196 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
197 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
198
199 // angle7_map
200 // angle7
201
206typedef struct
207{
208 // Output pins
209 digital_out_t en;
211 // Input pins
212 digital_in_t int_pin;
214 // Modules
215 i2c_master_t i2c;
216 analog_in_t adc;
218 // I2C slave address
223
224} angle7_t;
225
230typedef struct
231{
232 pin_name_t scl;
233 pin_name_t sda;
235 pin_name_t en;
236 pin_name_t an;
237 pin_name_t int_pin;
239 uint32_t i2c_speed;
240 uint8_t i2c_address;
242 analog_in_resolution_t resolution;
243 float vref;
246
251typedef enum
252{
254 ANGLE7_ERROR = -1
255
257
274
288err_t angle7_init ( angle7_t *ctx, angle7_cfg_t *cfg );
289
303
318err_t angle7_generic_write ( angle7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
319
334err_t angle7_generic_read ( angle7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
335
349err_t angle7_write_two_bytes ( angle7_t *ctx, uint8_t reg, uint16_t data_in );
350
364err_t angle7_read_two_bytes ( angle7_t *ctx, uint8_t reg, uint16_t *data_out );
365
377err_t angle7_read_an_pin_value ( angle7_t *ctx, uint16_t *data_out );
378
392err_t angle7_read_an_pin_voltage ( angle7_t *ctx, float *data_out );
393
403
413
423
435err_t angle7_set_start_position ( angle7_t *ctx, float angle );
436
448err_t angle7_get_start_position ( angle7_t *ctx, float *angle );
449
461err_t angle7_set_stop_position ( angle7_t *ctx, float angle );
462
474err_t angle7_get_stop_position ( angle7_t *ctx, float *angle );
475
487err_t angle7_get_raw_angle ( angle7_t *ctx, float *angle );
488
500err_t angle7_get_angle ( angle7_t *ctx, float *angle );
501
513err_t angle7_get_status ( angle7_t *ctx, uint8_t *status );
514
526err_t angle7_get_agc ( angle7_t *ctx, uint8_t *agc );
527
539err_t angle7_get_magnitude ( angle7_t *ctx, uint16_t *magnitude );
540
541#ifdef __cplusplus
542}
543#endif
544#endif // ANGLE7_H
545
546 // angle7
547
548// ------------------------------------------------------------------------ END
angle7_return_value_t
Angle 7 Click return value data.
Definition angle7.h:252
@ ANGLE7_OK
Definition angle7.h:253
@ ANGLE7_ERROR
Definition angle7.h:254
void angle7_disable_device(angle7_t *ctx)
Angle 7 disable device function.
err_t angle7_init(angle7_t *ctx, angle7_cfg_t *cfg)
Angle 7 initialization function.
err_t angle7_get_start_position(angle7_t *ctx, float *angle)
Angle 7 get start position function.
err_t angle7_read_an_pin_value(angle7_t *ctx, uint16_t *data_out)
Angle 7 read AN pin value function.
err_t angle7_generic_read(angle7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Angle 7 I2C reading function.
err_t angle7_read_an_pin_voltage(angle7_t *ctx, float *data_out)
Angle 7 read AN pin voltage level function.
err_t angle7_default_cfg(angle7_t *ctx)
Angle 7 default configuration function.
err_t angle7_get_angle(angle7_t *ctx, float *angle)
Angle 7 get angle function.
err_t angle7_set_stop_position(angle7_t *ctx, float angle)
Angle 7 set stop position function.
err_t angle7_write_two_bytes(angle7_t *ctx, uint8_t reg, uint16_t data_in)
Angle 7 write two bytes function.
uint8_t angle7_get_int_pin(angle7_t *ctx)
Angle 7 get int pin function.
void angle7_cfg_setup(angle7_cfg_t *cfg)
Angle 7 configuration object setup function.
err_t angle7_get_status(angle7_t *ctx, uint8_t *status)
Angle 7 get status function.
err_t angle7_get_raw_angle(angle7_t *ctx, float *angle)
Angle 7 get raw angle function.
err_t angle7_generic_write(angle7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Angle 7 I2C writing function.
err_t angle7_get_agc(angle7_t *ctx, uint8_t *agc)
Angle 7 get agc function.
err_t angle7_set_start_position(angle7_t *ctx, float angle)
Angle 7 set start position function.
err_t angle7_get_stop_position(angle7_t *ctx, float *angle)
Angle 7 get stop position function.
err_t angle7_read_two_bytes(angle7_t *ctx, uint8_t reg, uint16_t *data_out)
Angle 7 read two bytes function.
void angle7_enable_device(angle7_t *ctx)
Angle 7 enable device function.
err_t angle7_get_magnitude(angle7_t *ctx, uint16_t *magnitude)
Angle 7 get magnitude function.
Angle 7 Click configuration object.
Definition angle7.h:231
analog_in_resolution_t resolution
Definition angle7.h:242
float vref
Definition angle7.h:243
uint32_t i2c_speed
Definition angle7.h:239
pin_name_t scl
Definition angle7.h:232
pin_name_t en
Definition angle7.h:235
pin_name_t int_pin
Definition angle7.h:237
pin_name_t sda
Definition angle7.h:233
pin_name_t an
Definition angle7.h:236
uint8_t i2c_address
Definition angle7.h:240
Angle 7 Click context object.
Definition angle7.h:207
float stop_position
Definition angle7.h:222
digital_in_t int_pin
Definition angle7.h:212
i2c_master_t i2c
Definition angle7.h:215
float start_position
Definition angle7.h:221
digital_out_t en
Definition angle7.h:209
uint8_t slave_address
Definition angle7.h:219
analog_in_t adc
Definition angle7.h:216