brushless22 2.0.0.0
brushless22.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 BRUSHLESS22_H
29#define BRUSHLESS22_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_pwm.h"
53
74#define BRUSHLESS22_DIGIPOT_MAX_VALUE 100000ul
75#define BRUSHLESS22_DIGIPOT_RESOLUTION 257
76#define BRUSHLESS22_ROUND_TO_NEAREST_INT 0.5
77#define BRUSHLESS22_SLEW_RATE_RES_MAX 47000
78#define BRUSHLESS22_SLEW_RATE_RES_DEFAULT 10000
79#define BRUSHLESS22_SLEW_RATE_RES_MIN 4700
80#define BRUSHLESS22_RPROG_3900 3900
81#define BRUSHLESS22_RPROG_24000 24000
82#define BRUSHLESS22_RPROG_ADDRESS 0x10
83
89#define BRUSHLESS22_ADDR_A2A1A0_000 0x28
90#define BRUSHLESS22_ADDR_A2A1A0_001 0x29
91#define BRUSHLESS22_ADDR_A2A1A0_010 0x2A
92#define BRUSHLESS22_ADDR_A2A1A0_011 0x2B
93#define BRUSHLESS22_ADDR_A2A1A0_100 0x2C
94#define BRUSHLESS22_ADDR_A2A1A0_101 0x2D
95#define BRUSHLESS22_ADDR_A2A1A0_110 0x2E
96#define BRUSHLESS22_ADDR_A2A1A0_111 0x2F
97
102#define BRUSHLESS22_DIR_FORWARD 0
103#define BRUSHLESS22_DIR_REVERSE 1
104
109#define BRUSHLESS22_DEF_FREQ 50000
110
111 // brushless22_cfg
112
127#define BRUSHLESS22_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
131 cfg.rt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
132 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
133 cfg.ss = MIKROBUS( mikrobus, MIKROBUS_CS ); \
134 cfg.fg = MIKROBUS( mikrobus, MIKROBUS_INT );
135
136 // brushless22_map
137 // brushless22
138
148typedef struct
149{
150 // Output pins
151 digital_out_t dir;
152 digital_out_t ss;
153 digital_out_t rt;
155 // Input pins
156 digital_in_t fg;
158 // Modules
159 i2c_master_t i2c;
160 pwm_t pwm;
162 // ctx variable
164 uint32_t pwm_freq;
167
172typedef struct
173{
174 // Communication gpio pins
175 pin_name_t scl;
176 pin_name_t sda;
177 pin_name_t pwm;
179 // Additional gpio pins
180 pin_name_t dir;
181 pin_name_t ss;
182 pin_name_t fg;
183 pin_name_t rt;
185 // Static variable
186 uint32_t i2c_speed;
187 uint8_t i2c_address;
188 uint32_t dev_pwm_freq;
191
202
219
235
250
264
277err_t brushless22_set_rprog ( brushless22_t *ctx, uint16_t res_ohm );
278
291err_t brushless22_set_duty_cycle ( brushless22_t *ctx, float duty_cycle );
292
305
318
328
338
349void brushless22_set_direction ( brushless22_t *ctx, uint8_t dir );
350
360
370
380
390
391#ifdef __cplusplus
392}
393#endif
394#endif // BRUSHLESS22_H
395
396 // brushless22
397
398// ------------------------------------------------------------------------ END
brushless22_return_value_t
Brushless 22 Click return value data.
Definition brushless22.h:197
@ BRUSHLESS22_OK
Definition brushless22.h:198
@ BRUSHLESS22_ERROR
Definition brushless22.h:199
err_t brushless22_pwm_start(brushless22_t *ctx)
Brushless 22 start PWM module.
uint8_t brushless22_get_fg_pin(brushless22_t *ctx)
Brushless 22 get fd pin function.
void brushless22_set_direction(brushless22_t *ctx, uint8_t dir)
Brushless 22 set direction function.
void brushless22_set_normal_regulation(brushless22_t *ctx)
Brushless 22 set normal regulation function.
err_t brushless22_set_duty_cycle(brushless22_t *ctx, float duty_cycle)
Brushless 22 sets PWM duty cycle.
err_t brushless22_pwm_stop(brushless22_t *ctx)
Brushless 22 stop PWM module.
err_t brushless22_init(brushless22_t *ctx, brushless22_cfg_t *cfg)
Brushless 22 initialization function.
err_t brushless22_default_cfg(brushless22_t *ctx)
Brushless 22 default configuration function.
void brushless22_set_low_load_regulation(brushless22_t *ctx)
Brushless 22 set low load regulation function.
void brushless22_cfg_setup(brushless22_cfg_t *cfg)
Brushless 22 configuration object setup function.
err_t brushless22_set_slew_rate_resistance(brushless22_t *ctx, uint16_t res_ohm)
Brushless 22 set slew rate resistance function.
void brushless22_set_soft_start(brushless22_t *ctx)
Brushless 22 set soft start function.
void brushless22_switch_direction(brushless22_t *ctx)
Brushless 22 switch direction function.
err_t brushless22_set_rprog(brushless22_t *ctx, uint16_t res_ohm)
Brushless 22 set rprog function.
void brushless22_set_strong_start(brushless22_t *ctx)
Brushless 22 set strong start function.
Brushless 22 Click configuration object.
Definition brushless22.h:173
pin_name_t fg
Definition brushless22.h:182
pin_name_t ss
Definition brushless22.h:181
uint32_t i2c_speed
Definition brushless22.h:186
pin_name_t rt
Definition brushless22.h:183
uint32_t dev_pwm_freq
Definition brushless22.h:188
pin_name_t dir
Definition brushless22.h:180
pin_name_t scl
Definition brushless22.h:175
pin_name_t pwm
Definition brushless22.h:177
pin_name_t sda
Definition brushless22.h:176
uint8_t i2c_address
Definition brushless22.h:187
Brushless 22 Click driver selector.
Definition brushless22.h:149
uint32_t pwm_freq
Definition brushless22.h:164
digital_out_t rt
Definition brushless22.h:153
i2c_master_t i2c
Definition brushless22.h:159
digital_out_t ss
Definition brushless22.h:152
uint8_t slave_address
Definition brushless22.h:163
digital_in_t fg
Definition brushless22.h:156
pwm_t pwm
Definition brushless22.h:160
digital_out_t dir
Definition brushless22.h:151