brushless14 2.0.0.0
brushless14.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 BRUSHLESS14_H
29#define BRUSHLESS14_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 BRUSHLESS14_DAC_REG_CONFIG 0x01
75#define BRUSHLESS14_DAC_REG_STATUS_TRIGGER 0x02
76#define BRUSHLESS14_DAC_REG_BRDCAST 0x03
77#define BRUSHLESS14_DAC_REG_DAC_A_DATA 0x08
78#define BRUSHLESS14_DAC_REG_DAC_B_DATA 0x09
79#define BRUSHLESS14_DAC_REG_DAC_C_DATA 0x0A
80#define BRUSHLESS14_DAC_REG_DAC_D_DATA 0x0B
81#define BRUSHLESS14_DAC_REG_DAC_E_DATA 0x0C
82#define BRUSHLESS14_DAC_REG_DAC_F_DATA 0x0D
83#define BRUSHLESS14_DAC_REG_DAC_G_DATA 0x0E
84#define BRUSHLESS14_DAC_REG_DAC_H_DATA 0x0F
85
86#define BRUSHLESS14_PE_REG_INPUT_PORT 0x00
87#define BRUSHLESS14_PE_REG_OUTPUT_PORT 0x01
88#define BRUSHLESS14_PE_REG_POLARITY 0x02
89#define BRUSHLESS14_PE_REG_CONFIGURATION 0x03
90
91 // brushless14_reg
92
107#define BRUSHLESS14_DAC_ID 0x0500
108
114#define BRUSHLESS14_EXPANDER_SLAVE_ADDR 0x73
115#define BRUSHLESS14_DAC_SLAVE_ADDR 0x48
116
121#define BRUSHLESS14_DEF_FREQ 5000
122
123 // brushless14_set
124
139#define BRUSHLESS14_MAP_MIKROBUS( cfg, mikrobus ) \
140 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
142 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
143 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
144 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
145
146 // brushless14_map
147 // brushless14
148
153typedef struct
154{
155 // Output pins
156 digital_out_t dir;
158 // Input pins
159 digital_in_t int_pin;
161 // Modules
162 i2c_master_t i2c;
163 pwm_t pwm;
165 // I2C slave address
167 // ctx variable
168 uint32_t pwm_freq;
171
176typedef struct
177{
178 pin_name_t scl;
179 pin_name_t sda;
180 pin_name_t pwm;
182 pin_name_t dir;
183 pin_name_t int_pin;
185 uint32_t i2c_speed;
186 uint8_t i2c_address;
187 uint32_t dev_pwm_freq;
190
201
218
233
248
260err_t brushless14_set_duty_cycle ( brushless14_t *ctx, float duty_cycle );
261
273
285
298err_t brushless14_dac_write ( brushless14_t *ctx, uint8_t reg, uint16_t in_data );
299
312err_t brushless14_dac_read ( brushless14_t *ctx, uint8_t reg, uint16_t *out_data );
313
325err_t brushless14_set_adj0 ( brushless14_t *ctx, uint16_t m_voltage );
326
338err_t brushless14_set_adj1 ( brushless14_t *ctx, uint16_t m_voltage );
339
351err_t brushless14_set_adj2 ( brushless14_t *ctx, uint16_t m_voltage );
352
364err_t brushless14_set_adj3 ( brushless14_t *ctx, uint16_t m_voltage );
365
377err_t brushless14_set_fpwm ( brushless14_t *ctx, uint16_t m_voltage );
378
390err_t brushless14_set_la ( brushless14_t *ctx, uint16_t m_voltage );
391
404err_t brushless14_port_expander_write ( brushless14_t *ctx, uint8_t reg, uint8_t in_data );
405
418err_t brushless14_port_expander_read ( brushless14_t *ctx, uint8_t reg, uint8_t *out_data );
419
431err_t brushless14_set_slop ( brushless14_t *ctx, uint8_t state );
432
444err_t brushless14_set_rot ( brushless14_t *ctx, uint8_t state );
445
457err_t brushless14_set_fst ( brushless14_t *ctx, uint8_t state );
458
470err_t brushless14_set_sel_adj ( brushless14_t *ctx, uint8_t state );
471
483err_t brushless14_set_lap ( brushless14_t *ctx, uint8_t state );
484
496err_t brushless14_get_fg_out ( brushless14_t *ctx, uint8_t *state );
497
509err_t brushless14_get_ld_out ( brushless14_t *ctx, uint8_t *state );
510
519
528void brushless14_set_dir ( brushless14_t *ctx, uint8_t state );
529
530#ifdef __cplusplus
531}
532#endif
533#endif // BRUSHLESS14_H
534
535 // brushless14
536
537// ------------------------------------------------------------------------ END
brushless14_return_value_t
Brushless 14 Click return value data.
Definition brushless14.h:196
@ BRUSHLESS14_ERROR
Definition brushless14.h:198
@ BRUSHLESS14_OK
Definition brushless14.h:197
err_t brushless14_set_sel_adj(brushless14_t *ctx, uint8_t state)
Set PWM duty function setting.
err_t brushless14_set_adj0(brushless14_t *ctx, uint16_t m_voltage)
Set Adjusted input 0.
err_t brushless14_default_cfg(brushless14_t *ctx)
Brushless 14 default configuration function.
err_t brushless14_set_adj2(brushless14_t *ctx, uint16_t m_voltage)
Set Adjusted input 2.
err_t brushless14_port_expander_write(brushless14_t *ctx, uint8_t reg, uint8_t in_data)
Port expander write function.
err_t brushless14_pwm_start(brushless14_t *ctx)
Brushless 14 start PWM module.
err_t brushless14_set_adj1(brushless14_t *ctx, uint16_t m_voltage)
Set Adjusted input 1.
err_t brushless14_init(brushless14_t *ctx, brushless14_cfg_t *cfg)
Brushless 14 initialization function.
err_t brushless14_set_adj3(brushless14_t *ctx, uint16_t m_voltage)
Set Adjusted input 3.
err_t brushless14_set_fst(brushless14_t *ctx, uint8_t state)
Set forced commutation frequency select.
err_t brushless14_set_lap(brushless14_t *ctx, uint8_t state)
Set overlapping commutation select.
err_t brushless14_set_fpwm(brushless14_t *ctx, uint16_t m_voltage)
Set PWM frequency select input.
err_t brushless14_set_duty_cycle(brushless14_t *ctx, float duty_cycle)
Brushless 14 sets PWM duty cycle.
err_t brushless14_get_ld_out(brushless14_t *ctx, uint8_t *state)
Get lock detection signal.
err_t brushless14_dac_write(brushless14_t *ctx, uint8_t reg, uint16_t in_data)
DAC write function.
err_t brushless14_set_slop(brushless14_t *ctx, uint8_t state)
Set soft switching select.
err_t brushless14_dac_read(brushless14_t *ctx, uint8_t reg, uint16_t *out_data)
DAC reading function.
err_t brushless14_set_rot(brushless14_t *ctx, uint8_t state)
Set rotation speed of lead angle switching.
uint8_t brushless14_get_int(brushless14_t *ctx)
Get port expadner interrupt.
void brushless14_set_dir(brushless14_t *ctx, uint8_t state)
Set dirrection pin state.
err_t brushless14_port_expander_read(brushless14_t *ctx, uint8_t reg, uint8_t *out_data)
Port expander reading function.
err_t brushless14_get_fg_out(brushless14_t *ctx, uint8_t *state)
Get rotation speed.
err_t brushless14_set_la(brushless14_t *ctx, uint16_t m_voltage)
Set lead angle setting input.
void brushless14_cfg_setup(brushless14_cfg_t *cfg)
Brushless 14 configuration object setup function.
err_t brushless14_pwm_stop(brushless14_t *ctx)
Brushless 14 stop PWM module.
Brushless 14 Click configuration object.
Definition brushless14.h:177
uint32_t i2c_speed
Definition brushless14.h:185
uint32_t dev_pwm_freq
Definition brushless14.h:187
pin_name_t dir
Definition brushless14.h:182
pin_name_t scl
Definition brushless14.h:178
pin_name_t int_pin
Definition brushless14.h:183
pin_name_t pwm
Definition brushless14.h:180
pin_name_t sda
Definition brushless14.h:179
uint8_t i2c_address
Definition brushless14.h:186
Brushless 14 Click context object.
Definition brushless14.h:154
uint32_t pwm_freq
Definition brushless14.h:168
digital_in_t int_pin
Definition brushless14.h:159
i2c_master_t i2c
Definition brushless14.h:162
uint8_t slave_address
Definition brushless14.h:166
pwm_t pwm
Definition brushless14.h:163
digital_out_t dir
Definition brushless14.h:156