brushless7 2.0.0.0
brushless7.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 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef BRUSHLESS7_H
36#define BRUSHLESS7_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_pwm.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define BRUSHLESS7_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.cmo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.sby = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
81#define BRUSHLESS7_RETVAL uint8_t
82
83#define BRUSHLESS7_OK 0x00
84#define BRUSHLESS7_INIT_ERROR 0xFF
91#define BRUSHLESS7_SLAVE_ADDR_ID2_LOW_ID1_LOW 0x29
92#define BRUSHLESS7_SLAVE_ADDR_ID2_LOW_ID1_HIGH 0x29
93#define BRUSHLESS7_SLAVE_ADDR_ID2_HIGH_ID1_LOW 0x2D
94#define BRUSHLESS7_SLAVE_ADDR_ID2_HIGH_ID1_HIGH 0x32
101#define BRUSHLESS7_REG_0 0
102#define BRUSHLESS7_REG_1 1
103#define BRUSHLESS7_REG_2 2
104#define BRUSHLESS7_REG_3 3
105#define BRUSHLESS7_REG_4 4
106#define BRUSHLESS7_REG_5 5
107#define BRUSHLESS7_REG_6 6
108#define BRUSHLESS7_REG_7 7
109#define BRUSHLESS7_REG_8 8
110#define BRUSHLESS7_REG_9 9
111#define BRUSHLESS7_REG_10 10
112#define BRUSHLESS7_REG_11 11
113#define BRUSHLESS7_REG_12 12
114#define BRUSHLESS7_REG_13 13
115#define BRUSHLESS7_REG_14 14
116#define BRUSHLESS7_REG_15 15
117#define BRUSHLESS7_REG_16 16
118#define BRUSHLESS7_REG_17 17
119#define BRUSHLESS7_REG_18 18
120#define BRUSHLESS7_REG_19 19
121#define BRUSHLESS7_REG_20 20
122#define BRUSHLESS7_REG_21 21
123#define BRUSHLESS7_REG_22 22
124#define BRUSHLESS7_REG_23 23
125#define BRUSHLESS7_REG_24 24
126#define BRUSHLESS7_REG_25 25
127#define BRUSHLESS7_REG_26 26
128#define BRUSHLESS7_REG_27 27
129#define BRUSHLESS7_REG_28 28
130#define BRUSHLESS7_REG_29 29
131#define BRUSHLESS7_REG_30 30
132#define BRUSHLESS7_REG_86 86
133#define BRUSHLESS7_REG_87 87
140#define BRUSHLESS7_DEV_ERROR 0xFF
141#define BRUSHLESS7_DEV_OK 0x00
148#define BRUSHLESS7_MAX_SPEED_4096 0x00
149#define BRUSHLESS7_MAX_SPEED_8192 0x02
150#define BRUSHLESS7_MAX_SPEED_16384 0x04
151#define BRUSHLESS7_MAX_SPEED_32768 0x06
158#define BRUSHLESS7_CTRL_TYPE_RPM 0xAA
159#define BRUSHLESS7_CTRL_TYPE_DUTY 0xBB
160#define BRUSHLESS7_CTRL_TYPE_STOP 0xCC
167#define BRUSHLESS7_DIR_CW 0xDD
168#define BRUSHLESS7_DIR_CCW 0xEE
175#define BRUSHLESS7_ZERO 0
182#define BRUSHLESS7_START_DUTY_MAX 49.8
183#define BRUSHLESS7_START_DUTY_AMP 512
190#define BRUSHLESS7_STOP_DUTY_MAX 49.6
191#define BRUSHLESS7_STOP_DUTY_AMP 256
192#define BRUSHLESS7_STOP_DUTY_MASK 0x80
199#define BRUSHLESS7_CHANGE_DUTY_MIN 0.4
200#define BRUSHLESS7_CHANGE_DUTY_MAX 99.6
201#define BRUSHLESS7_CHANGE_DUTY_AMP 256
208#define BRUSHLESS7_MAX_DUTY_MIN 50.2
209#define BRUSHLESS7_MAX_DUTY_MAX 100.0
210#define BRUSHLESS7_MAX_DUTY_AMP 512
211#define BRUSHLESS7_MAX_DUTY_DEC 257
218#define BRUSHLESS7_START_RPM_MAX 4095
219#define BRUSHLESS7_START_RPM_SHIFT 4
220#define BRUSHLESS7_START_RPM_MASK 0x0F
227#define BRUSHLESS7_MAX_SPEED_RMP_MASK 0xF9
234#define BRUSHLESS7_PRECENTAGE_DIV 100
241#define BRUSHLESS7_DEF_FREQ 5000
244 // End group macro
245// --------------------------------------------------------------- PUBLIC TYPES
254typedef struct
255{
256 // Output pins
257
258 digital_out_t dir;
259 digital_out_t sby;
260
261 // Input pins
262
263 digital_in_t cmo;
264 digital_in_t int_pin;
265
266 // Modules
267
268 pwm_t pwm;
269 i2c_master_t i2c;
270
271 // ctx variable
272
273 uint32_t pwm_freq;
275
277
281typedef struct
282{
283 // Communication gpio pins
284
285 pin_name_t scl;
286 pin_name_t sda;
287 pin_name_t pwm;
288
289 // Additional gpio pins
290
291 pin_name_t cmo;
292 pin_name_t dir;
293 pin_name_t sby;
294 pin_name_t int_pin;
295
296 // static variable
297
298 uint32_t dev_pwm_freq;
299 uint32_t i2c_speed;
300 uint8_t i2c_address;
301
303
304 // End types group
305// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
306
312#ifdef __cplusplus
313extern "C"{
314#endif
315
325
335
344
355void brushless7_generic_write ( brushless7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
356
367void brushless7_generic_read ( brushless7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
368
375void brushless7_set_sby_pin_state ( brushless7_t *ctx, uint8_t state );
376
383
392
403uint8_t brushless7_start_duty ( brushless7_t *ctx, float duty_ptc );
404
415uint8_t brushless7_stop_duty ( brushless7_t *ctx, float duty_ptc );
416
427uint8_t brushless7_change_duty ( brushless7_t *ctx, float duty_ptc );
428
439uint8_t brushless7_max_duty ( brushless7_t *ctx, float duty_ptc );
440
451uint8_t brushless7_start_rpm ( brushless7_t *ctx, uint16_t rpm_val );
452
461uint8_t brushless7_max_speed_rpm ( brushless7_t *ctx, uint8_t max_speed_rpm );
462
471uint8_t brushless7_rotating_direction ( brushless7_t *ctx, uint8_t direction_rot );
472
481uint8_t brushless7_control_mode_set ( brushless7_t *ctx, uint8_t ctrl_type );
482
492void brushless7_set_duty_cycle ( brushless7_t *ctx, float duty_cycle );
493
502
511
512#ifdef __cplusplus
513}
514#endif
515#endif // _BRUSHLESS7_H_
516
517 // End public_function group
519
520// ------------------------------------------------------------------------- END
#define BRUSHLESS7_RETVAL
Definition brushless7.h:81
void brushless7_cfg_setup(brushless7_cfg_t *cfg)
Config Object Initialization function.
uint8_t brushless7_start_duty(brushless7_t *ctx, float duty_ptc)
Function for setting start duty of device.
void brushless7_set_sby_pin_state(brushless7_t *ctx, uint8_t state)
Generic function for setting SBY pin state.
uint8_t brushless7_get_int_pin_state(brushless7_t *ctx)
Generic function for getting INT pin state.
void brushless7_pwm_start(brushless7_t *ctx)
Start PWM module.
uint8_t brushless7_start_rpm(brushless7_t *ctx, uint16_t rpm_val)
Function for setting start rpm parameter of device.
void brushless7_set_duty_cycle(brushless7_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
uint8_t brushless7_rotating_direction(brushless7_t *ctx, uint8_t direction_rot)
Function for setting rotation direction.
void brushless7_generic_read(brushless7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void brushless7_toggle_dir_pin_state(brushless7_t *ctx)
Generic function for toggling DIR pin state.
BRUSHLESS7_RETVAL brushless7_init(brushless7_t *ctx, brushless7_cfg_t *cfg)
Initialization function.
uint8_t brushless7_max_speed_rpm(brushless7_t *ctx, uint8_t max_speed_rpm)
Function for setting max rpm parameter of device.
uint8_t brushless7_control_mode_set(brushless7_t *ctx, uint8_t ctrl_type)
Function for setting type of device control.
uint8_t brushless7_max_duty(brushless7_t *ctx, float duty_ptc)
Function for setting max duty of device.
uint8_t brushless7_change_duty(brushless7_t *ctx, float duty_ptc)
Function for changeing duty of device.
uint8_t brushless7_stop_duty(brushless7_t *ctx, float duty_ptc)
Function for setting stop duty of device.
void brushless7_default_cfg(brushless7_t *ctx)
Click Default Configuration function.
void brushless7_generic_write(brushless7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void brushless7_pwm_stop(brushless7_t *ctx)
Stop PWM module.
Click configuration structure definition.
Definition brushless7.h:282
pin_name_t cmo
Definition brushless7.h:291
uint32_t i2c_speed
Definition brushless7.h:299
uint32_t dev_pwm_freq
Definition brushless7.h:298
pin_name_t dir
Definition brushless7.h:292
pin_name_t scl
Definition brushless7.h:285
pin_name_t int_pin
Definition brushless7.h:294
pin_name_t pwm
Definition brushless7.h:287
pin_name_t sda
Definition brushless7.h:286
pin_name_t sby
Definition brushless7.h:293
uint8_t i2c_address
Definition brushless7.h:300
Click ctx object definition.
Definition brushless7.h:255
uint32_t pwm_freq
Definition brushless7.h:273
digital_in_t cmo
Definition brushless7.h:263
digital_in_t int_pin
Definition brushless7.h:264
i2c_master_t i2c
Definition brushless7.h:269
digital_out_t sby
Definition brushless7.h:259
uint8_t slave_address
Definition brushless7.h:274
pwm_t pwm
Definition brushless7.h:268
digital_out_t dir
Definition brushless7.h:258