brushless3  2.0.0.0
brushless3.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 BRUSHLESS3_H
36 #define BRUSHLESS3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_pwm.h"
42 
43 
44 // -------------------------------------------------------------- PUBLIC MACROS
54 #define BRUSHLESS3_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
60 
66 #define BRUSHLESS3_OK 0
67 #define BRUSHLESS3_ERROR -1
68 
70 #define BRUSHLESS3_I2C_ADDRESS 0x52
71 #define BRUSHLESS3_MAX_SPEED 0x1FF
72 #define BRUSHLESS3_DEF_FREQ 25000
73 
78 #define BRUSHLESS3_SPEED_CTRL_1 0x00
79 #define BRUSHLESS3_SPEED_CTRL_2 0x01
80 #define BRUSHLESS3_DEV_CTRL 0x02
81 #define BRUSHLESS3_EE_CTRL 0x03
82 
88 #define BRUSHLESS3_STATUS 0x10
89 #define BRUSHLESS3_MOTOR_SPEED_1 0x11
90 #define BRUSHLESS3_MOTOR_SPEED_2 0x12
91 #define BRUSHLESS3_MOTOR_PERIOD_1 0x13
92 #define BRUSHLESS3_MOTOR_PERIOD_2 0x14
93 #define BRUSHLESS3_MOTOR_KT_1 0x15
94 #define BRUSHLESS3_MOTOR_KT_2 0x16
95 #define BRUSHLESS3_IPD_POSITION 0x19
96 #define BRUSHLESS3_SUPPLY_VOLTAGE 0x1A
97 #define BRUSHLESS3_SPEED_CMD 0x1B
98 #define BRUSHLESS3_SPD_CMD_BUFFER 0x1C
99 #define BRUSHLESS3_FAULT_CODE 0x1E
100 
106 #define BRUSHLESS3_MOTOR_PARAM_1 0x20
107 #define BRUSHLESS3_MOTOR_PARAM_2 0x21
108 #define BRUSHLESS3_MOTOR_PARAM_3 0x22
109 #define BRUSHLESS3_SYS_OPT_1 0x23
110 #define BRUSHLESS3_SYS_OPT_2 0x24
111 #define BRUSHLESS3_SYS_OPT_3 0x25
112 #define BRUSHLESS3_SYS_OPT_4 0x26
113 #define BRUSHLESS3_SYS_OPT_5 0x27
114 #define BRUSHLESS3_SYS_OPT_6 0x28
115 #define BRUSHLESS3_SYS_OPT_7 0x29
116 #define BRUSHLESS3_SYS_OPT_8 0x2A
117 #define BRUSHLESS3_SYS_OPT_9 0x2B
118 
124 #define BRUSHLESS3_PARAM_START_EE_CTRL 0x40
125 #define BRUSHLESS3_PARAM_STOP_EE_CTRL 0x50
126 #define BRUSHLESS3_PARAM_MOTOR_PARAM_1 0x39
127 #define BRUSHLESS3_PARAM_MOTOR_PARAM_2 0x1E
128 #define BRUSHLESS3_PARAM_MOTOR_PARAM_3 0x3A
129 #define BRUSHLESS3_PARAM_SYS_OPT_1 0x08
130 #define BRUSHLESS3_PARAM_SYS_OPT_2 0x50
131 #define BRUSHLESS3_PARAM_SYS_OPT_3 0xDA
132 #define BRUSHLESS3_PARAM_SYS_OPT_4 0xB8
133 #define BRUSHLESS3_PARAM_SYS_OPT_5 0x10
134 #define BRUSHLESS3_PARAM_SYS_OPT_6 0x27
135 #define BRUSHLESS3_PARAM_SYS_OPT_7 0x37
136 #define BRUSHLESS3_PARAM_SYS_OPT_8 0x04
137 #define BRUSHLESS3_PARAM_SYS_OPT_9 0x0C
138 #define BRUSHLESS3_PARAM_DEV_CTRL 0xB6
139  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
150 typedef struct
151 {
152  // Output pins
153  digital_out_t dir;
154 
155  // Input pins
156  digital_in_t int_pin;
157 
158  // Modules
159  i2c_master_t i2c;
160  pwm_t pwm;
161 
162  // ctx variable
163  uint32_t pwm_freq;
164  uint8_t slave_address;
165 
166 } brushless3_t;
167 
171 typedef struct
172 {
173  // Communication gpio pins
174  pin_name_t scl;
175  pin_name_t sda;
176  pin_name_t pwm;
177 
178  // Additional gpio pins
179  pin_name_t dir;
180  pin_name_t int_pin;
181 
182  // static variable
183  uint32_t dev_pwm_freq;
184  uint32_t i2c_speed;
185  uint8_t i2c_address;
186 
188  // End types group
190 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191 
197 #ifdef __cplusplus
198 extern "C"{
199 #endif
200 
210 
220 
232 
245 err_t brushless3_write_data ( brushless3_t *ctx, uint8_t reg_addr, uint8_t write_data );
246 
259 err_t brushless3_read_data ( brushless3_t *ctx, uint8_t reg_addr, uint8_t *read_data );
260 
274 
288 
302 
316 
330 
344 
358 
372 
386 
400 err_t brushless3_check_over_temp ( brushless3_t *ctx, uint8_t *over_temp );
401 
416 err_t brushless3_check_sleep_mode ( brushless3_t *ctx, uint8_t *sleep_mode );
417 
432 err_t brushless3_check_motor_lock ( brushless3_t *ctx, uint8_t *motor_lock );
433 
448 err_t brushless3_get_supply_voltage ( brushless3_t *ctx, float *voltage );
449 
464 err_t brushless3_get_speed_cmd ( brushless3_t *ctx, float *speed_cmd );
465 
489 err_t brushless3_check_fault_code ( brushless3_t *ctx, uint8_t *fault_code );
490 
505 err_t brushless3_get_speed ( brushless3_t *ctx, float *speed );
506 
520 err_t brushless3_set_speed ( brushless3_t *ctx, uint16_t motor_speed_hz );
521 
535 err_t brushless3_set_speed_pwm ( brushless3_t *ctx, uint16_t motor_speed_hz );
536 
551 err_t brushless3_get_period ( brushless3_t *ctx, float *period );
552 
566 
581 err_t brushless3_get_vel_const ( brushless3_t *ctx, float *velocity );
582 
592 
602 
613 
626 err_t brushless3_set_duty_cycle ( brushless3_t *ctx, float duty_cycle );
627 
639 
651 
652 #ifdef __cplusplus
653 }
654 #endif
655 #endif // _BRUSHLESS3_H_
656  // End public_function group
659 
660 // ------------------------------------------------------------------------- END
brushless3_set_an_mode
err_t brushless3_set_an_mode(brushless3_t *ctx)
Set Analog mode function.
brushless3_t::slave_address
uint8_t slave_address
Definition: brushless3.h:164
brushless3_pwm_start
err_t brushless3_pwm_start(brushless3_t *ctx)
Start PWM module.
brushless3_t::pwm
pwm_t pwm
Definition: brushless3.h:160
brushless3_cfg_t::i2c_address
uint8_t i2c_address
Definition: brushless3.h:185
brushless3_check_fault_code
err_t brushless3_check_fault_code(brushless3_t *ctx, uint8_t *fault_code)
Check fault code function.
brushless3_default_cfg
err_t brushless3_default_cfg(brushless3_t *ctx)
Click Default Configuration function.
brushless3_t::dir
digital_out_t dir
Definition: brushless3.h:153
brushless3_t::i2c
i2c_master_t i2c
Definition: brushless3.h:159
brushless3_get_speed
err_t brushless3_get_speed(brushless3_t *ctx, float *speed)
Get speed function.
brushless3_get_vel_const
err_t brushless3_get_vel_const(brushless3_t *ctx, float *velocity)
Get measured velocity constant function.
brushless3_forward_direction
void brushless3_forward_direction(brushless3_t *ctx)
Set the direction of rotation in the forward direction function.
brushless3_cfg_t::pwm
pin_name_t pwm
Definition: brushless3.h:176
brushless3_init
err_t brushless3_init(brushless3_t *ctx, brushless3_cfg_t *cfg)
Initialization function.
brushless3_get_supply_voltage
err_t brushless3_get_supply_voltage(brushless3_t *ctx, float *voltage)
Get the supply voltage function.
brushless3_set_speed_pwm
err_t brushless3_set_speed_pwm(brushless3_t *ctx, uint16_t motor_speed_hz)
Set speed PWM function.
brushless3_reverse_direction
void brushless3_reverse_direction(brushless3_t *ctx)
Set the direction of rotation in the reverse direction function.
brushless3_write_data
err_t brushless3_write_data(brushless3_t *ctx, uint8_t reg_addr, uint8_t write_data)
Write function.
brushless3_dis_config
err_t brushless3_dis_config(brushless3_t *ctx)
Disable the writing to the configuration registers function.
brushless3_pwm_stop
err_t brushless3_pwm_stop(brushless3_t *ctx)
Stop PWM module.
brushless3_set_default_param
err_t brushless3_set_default_param(brushless3_t *ctx)
Set default parameter function.
brushless3_copy_eeprom
err_t brushless3_copy_eeprom(brushless3_t *ctx)
Copy EEPROM data to register function.
brushless3_get_period
err_t brushless3_get_period(brushless3_t *ctx, float *period)
Get motor period function.
brushless3_cfg_t::scl
pin_name_t scl
Definition: brushless3.h:174
brushless3_read_data
err_t brushless3_read_data(brushless3_t *ctx, uint8_t reg_addr, uint8_t *read_data)
Read function.
brushless3_check_motor_lock
err_t brushless3_check_motor_lock(brushless3_t *ctx, uint8_t *motor_lock)
Check indicate that the motor is locked function.
brushless3_dis_sleep_mode
err_t brushless3_dis_sleep_mode(brushless3_t *ctx)
Disable entering into sleep or standby mode function.
brushless3_dis_write_eeprom
err_t brushless3_dis_write_eeprom(brushless3_t *ctx)
Disable the writing to the EEPROM registers function.
brushless3_t::int_pin
digital_in_t int_pin
Definition: brushless3.h:156
brushless3_set_speed
err_t brushless3_set_speed(brushless3_t *ctx, uint16_t motor_speed_hz)
Set speed function.
brushless3_get_speed_cmd
err_t brushless3_get_speed_cmd(brushless3_t *ctx, float *speed_cmd)
Get the speed command ( % ) based on analog or PWM or I2C function.
brushless3_check_sleep_mode
err_t brushless3_check_sleep_mode(brushless3_t *ctx, uint8_t *sleep_mode)
Check indicate that device went into sleep or standby mode function.
brushless3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless3.h:183
brushless3_cfg_setup
void brushless3_cfg_setup(brushless3_cfg_t *cfg)
Config Object Initialization function.
brushless3_set_duty_cycle
err_t brushless3_set_duty_cycle(brushless3_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless3_cfg_t::sda
pin_name_t sda
Definition: brushless3.h:175
brushless3_en_write_eeprom
err_t brushless3_en_write_eeprom(brushless3_t *ctx)
Enable the writing to the EEPROM registers function.
brushless3_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless3.h:180
brushless3_set_pwm_mode
err_t brushless3_set_pwm_mode(brushless3_t *ctx)
Set PWM mode function.
brushless3_en_prog_eeprom
err_t brushless3_en_prog_eeprom(brushless3_t *ctx)
Set prog key function.
brushless3_get_int_pin
uint8_t brushless3_get_int_pin(brushless3_t *ctx)
Get Interrupt pin state function.
brushless3_check_over_temp
err_t brushless3_check_over_temp(brushless3_t *ctx, uint8_t *over_temp)
Check indicate device temperature is over its limits function.
brushless3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: brushless3.h:184
brushless3_t
Click ctx object definition.
Definition: brushless3.h:151
brushless3_t::pwm_freq
uint32_t pwm_freq
Definition: brushless3.h:163
brushless3_en_config
err_t brushless3_en_config(brushless3_t *ctx)
Enable the writing to the configuration registers function.
brushless3_cfg_t
Click configuration structure definition.
Definition: brushless3.h:172
brushless3_cfg_t::dir
pin_name_t dir
Definition: brushless3.h:179