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_RETVAL uint8_t
67 
68 #define BRUSHLESS3_OK 0x00
69 #define BRUSHLESS3_INIT_ERROR 0xFF
70 
72 #define BRUSHLESS3_I2C_ADDRESS 0x52
73 #define BRUSHLESS3_MAX_SPEED 0x1FF
74 #define BRUSHLESS3_DEF_FREQ 25000
75 
80 #define BRUSHLESS3_SPEED_CTRL_1 0x00
81 #define BRUSHLESS3_SPEED_CTRL_2 0x01
82 #define BRUSHLESS3_DEV_CTRL 0x02
83 #define BRUSHLESS3_EE_CTRL 0x03
84 
90 #define BRUSHLESS3_STATUS 0x10
91 #define BRUSHLESS3_MOTOR_SPEED_1 0x11
92 #define BRUSHLESS3_MOTOR_SPEED_2 0x12
93 #define BRUSHLESS3_MOTOR_PERIOD_1 0x13
94 #define BRUSHLESS3_MOTOR_PERIOD_2 0x14
95 #define BRUSHLESS3_MOTOR_KT_1 0x15
96 #define BRUSHLESS3_MOTOR_KT_2 0x16
97 #define BRUSHLESS3_IPD_POSITION 0x19
98 #define BRUSHLESS3_SUPPLY_VOLTAGE 0x1A
99 #define BRUSHLESS3_SPEED_CMD 0x1B
100 #define BRUSHLESS3_SPD_CMD_BUFFER 0x1C
101 #define BRUSHLESS3_FAULT_CODE 0x1E
102 
108 #define BRUSHLESS3_MOTOR_PARAM_1 0x20
109 #define BRUSHLESS3_MOTOR_PARAM_2 0x21
110 #define BRUSHLESS3_MOTOR_PARAM_3 0x22
111 #define BRUSHLESS3_SYS_OPT_1 0x23
112 #define BRUSHLESS3_SYS_OPT_2 0x24
113 #define BRUSHLESS3_SYS_OPT_3 0x25
114 #define BRUSHLESS3_SYS_OPT_4 0x26
115 #define BRUSHLESS3_SYS_OPT_5 0x27
116 #define BRUSHLESS3_SYS_OPT_6 0x28
117 #define BRUSHLESS3_SYS_OPT_7 0x29
118 #define BRUSHLESS3_SYS_OPT_8 0x2A
119 #define BRUSHLESS3_SYS_OPT_9 0x2B
120 
126 #define BRUSHLESS3_PARAM_START_EE_CTRL 0x40
127 #define BRUSHLESS3_PARAM_STOP_EE_CTRL 0x50
128 #define BRUSHLESS3_PARAM_MOTOR_PARAM_1 0x39
129 #define BRUSHLESS3_PARAM_MOTOR_PARAM_2 0x1E
130 #define BRUSHLESS3_PARAM_MOTOR_PARAM_3 0x3A
131 #define BRUSHLESS3_PARAM_SYS_OPT_1 0x08
132 #define BRUSHLESS3_PARAM_SYS_OPT_2 0x50
133 #define BRUSHLESS3_PARAM_SYS_OPT_3 0xDA
134 #define BRUSHLESS3_PARAM_SYS_OPT_4 0xB8
135 #define BRUSHLESS3_PARAM_SYS_OPT_5 0x10
136 #define BRUSHLESS3_PARAM_SYS_OPT_6 0x27
137 #define BRUSHLESS3_PARAM_SYS_OPT_7 0x37
138 #define BRUSHLESS3_PARAM_SYS_OPT_8 0x04
139 #define BRUSHLESS3_PARAM_SYS_OPT_9 0x0C
140 #define BRUSHLESS3_PARAM_DEV_CTRL 0xB6
141  // End group macro
143 // --------------------------------------------------------------- PUBLIC TYPES
152 typedef struct
153 {
154  // Output pins
155 
156  digital_out_t dir;
157 
158  // Input pins
159 
160  digital_in_t int_pin;
161 
162  // Modules
163 
164  i2c_master_t i2c;
165  pwm_t pwm;
166 
167  // ctx variable
168 
169  uint32_t pwm_freq;
170  uint8_t slave_address;
171 
172 } brushless3_t;
173 
177 typedef struct
178 {
179  // Communication gpio pins
180 
181  pin_name_t scl;
182  pin_name_t sda;
183  pin_name_t pwm;
184 
185  // Additional gpio pins
186 
187  pin_name_t dir;
188  pin_name_t int_pin;
189 
190  // static variable
191 
192  uint32_t dev_pwm_freq;
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
195 
197  // End types group
199 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200 
206 #ifdef __cplusplus
207 extern "C"{
208 #endif
209 
219 
229 
238 
248 void brushless3_write_data ( brushless3_t *ctx, uint8_t reg_addr, uint8_t write_data );
249 
260 uint8_t brushless3_read_data ( brushless3_t *ctx, uint8_t reg_addr );
261 
272 
283 
294 
305 
316 
327 
338 
349 
360 
373 
386 
399 
412 
425 
447 
459 float brushless3_get_speed ( brushless3_t *ctx );
460 
471 void brushless3_set_speed ( brushless3_t *ctx, uint16_t motor_speed_hz );
472 
483 void brushless3_set_speedPWM ( brushless3_t *ctx, uint16_t motor_speed_hz );
484 
496 float brushless3_get_period ( brushless3_t *ctx );
497 
508 
521 
531 
541 
552 
562 void brushless3_set_duty_cycle ( brushless3_t *ctx, float duty_cycle );
563 
571 void brushless3_pwm_stop ( brushless3_t *ctx );
572 
580 void brushless3_pwm_start ( brushless3_t *ctx );
581 
582 #ifdef __cplusplus
583 }
584 #endif
585 #endif // _BRUSHLESS3_H_
586  // End public_function group
589 
590 // ------------------------------------------------------------------------- END
brushless3_t::slave_address
uint8_t slave_address
Definition: brushless3.h:170
brushless3_t::pwm
pwm_t pwm
Definition: brushless3.h:165
brushless3_cfg_t::i2c_address
uint8_t i2c_address
Definition: brushless3.h:194
brushless3_set_speedPWM
void brushless3_set_speedPWM(brushless3_t *ctx, uint16_t motor_speed_hz)
Set speed PWM function.
brushless3_check_motor_lock
uint8_t brushless3_check_motor_lock(brushless3_t *ctx)
Check indicate that the motor is locked function.
brushless3_get_speed
float brushless3_get_speed(brushless3_t *ctx)
Get speed function.
brushless3_disable_sleep_mode
void brushless3_disable_sleep_mode(brushless3_t *ctx)
Disable entering into sleep or standby mode function.
brushless3_t::dir
digital_out_t dir
Definition: brushless3.h:156
brushless3_t::i2c
i2c_master_t i2c
Definition: brushless3.h:164
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:183
brushless3_get_period
float brushless3_get_period(brushless3_t *ctx)
Get motor period function.
brushless3_copy_eeprom
void brushless3_copy_eeprom(brushless3_t *ctx)
Copy EEPROM data to register function.
brushless3_reverse_direction
void brushless3_reverse_direction(brushless3_t *ctx)
Set the direction of rotation in the reverse direction function.
brushless3_check_sleep_mode
uint8_t brushless3_check_sleep_mode(brushless3_t *ctx)
Check indicate that device went into sleep or standby mode function.
brushless3_get_velocity_constant
float brushless3_get_velocity_constant(brushless3_t *ctx)
Get measured velocity constant function.
brushless3_disable_write_eeprom
void brushless3_disable_write_eeprom(brushless3_t *ctx)
Disable the writing to the EEPROM registers function.
brushless3_get_interrupt_status
uint8_t brushless3_get_interrupt_status(brushless3_t *ctx)
Get Interrupt pin state function.
brushless3_write_data
void brushless3_write_data(brushless3_t *ctx, uint8_t reg_addr, uint8_t write_data)
Write function.
brushless3_cfg_t::scl
pin_name_t scl
Definition: brushless3.h:181
brushless3_pwm_start
void brushless3_pwm_start(brushless3_t *ctx)
Start PWM module.
brushless3_enable_write_eeprom
void brushless3_enable_write_eeprom(brushless3_t *ctx)
Enable the writing to the EEPROM registers function.
brushless3_read_data
uint8_t brushless3_read_data(brushless3_t *ctx, uint8_t reg_addr)
Read function.
brushless3_set_an_mode
void brushless3_set_an_mode(brushless3_t *ctx)
Set Analog mode function.
brushless3_get_supply_voltage_value
float brushless3_get_supply_voltage_value(brushless3_t *ctx)
Get the supply voltage function.
brushless3_pwm_stop
void brushless3_pwm_stop(brushless3_t *ctx)
Stop PWM module.
brushless3_default_cfg
void brushless3_default_cfg(brushless3_t *ctx)
Click Default Configuration function.
brushless3_t::int_pin
digital_in_t int_pin
Definition: brushless3.h:160
brushless3_get_speed_cmd
float brushless3_get_speed_cmd(brushless3_t *ctx)
Get the speed command ( % ) based on analog or PWM or I2C function.
brushless3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless3.h:192
brushless3_cfg_setup
void brushless3_cfg_setup(brushless3_cfg_t *cfg)
Config Object Initialization function.
brushless3_enable_programming_eeprom
void brushless3_enable_programming_eeprom(brushless3_t *ctx)
Set prog key function.
brushless3_cfg_t::sda
pin_name_t sda
Definition: brushless3.h:182
brushless3_disable_config
void brushless3_disable_config(brushless3_t *ctx)
Disable the writing to the configuration registers function.
brushless3_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless3.h:188
brushless3_set_speed
void brushless3_set_speed(brushless3_t *ctx, uint16_t motor_speed_hz)
Set speed function.
brushless3_enable_config
void brushless3_enable_config(brushless3_t *ctx)
Enable the writing to the configuration registers function.
brushless3_check_over_temp
uint8_t brushless3_check_over_temp(brushless3_t *ctx)
Check indicate device temperature is over its limits function.
brushless3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: brushless3.h:193
brushless3_init
BRUSHLESS3_RETVAL brushless3_init(brushless3_t *ctx, brushless3_cfg_t *cfg)
Initialization function.
brushless3_t
Click ctx object definition.
Definition: brushless3.h:152
brushless3_check_fault_code
uint8_t brushless3_check_fault_code(brushless3_t *ctx)
Check fault code function.
brushless3_t::pwm_freq
uint32_t pwm_freq
Definition: brushless3.h:169
brushless3_cfg_t
Click configuration structure definition.
Definition: brushless3.h:177
brushless3_set_duty_cycle
void brushless3_set_duty_cycle(brushless3_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless3_set_pwm_mode
void brushless3_set_pwm_mode(brushless3_t *ctx)
Set PWM mode function.
brushless3_set_default_param
void brushless3_set_default_param(brushless3_t *ctx)
Set default parameter function.
BRUSHLESS3_RETVAL
#define BRUSHLESS3_RETVAL
Definition: brushless3.h:66
brushless3_cfg_t::dir
pin_name_t dir
Definition: brushless3.h:187