brushless11  2.1.0.0
brushless11.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 BRUSHLESS11_H
29 #define BRUSHLESS11_H
30 
31 #ifdef __cplusplus
32 extern "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_pwm.h"
52 
73 #define BRUSHLESS11_DEF_FREQ 5000
74 
79 #define BRUSHLESS11_PIN_STATE_HIGH 0x01
80 #define BRUSHLESS11_PIN_STATE_LOW 0x00
81 
86 #define BRUSHLESS11_BRAKE_ON 0x01
87 #define BRUSHLESS11_BRAKE_OFF 0x00
88  // brushless11_cfg
90 
105 #define BRUSHLESS11_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
107  cfg.fg1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108  cfg.brk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.fg2 = MIKROBUS( mikrobus, MIKROBUS_INT );
110  // brushless11_map // brushless11
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t brk;
123  // Input pins
124  digital_in_t fg1;
125  digital_in_t fg2;
127  // Modules
128  pwm_t pwm;
130  // ctx variable
131  uint32_t pwm_freq;
133 } brushless11_t;
134 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t pwm;
144  // Additional gpio pins
145  pin_name_t fg1;
146  pin_name_t brk;
147  pin_name_t fg2;
149  // Static variable
150  uint32_t dev_pwm_freq;
153 
158 typedef enum
159 {
161  BRUSHLESS11_ERROR = -1
162 
164 
181 
196 
210 
222 err_t brushless11_set_duty_cycle ( brushless11_t *ctx, float duty_cycle );
223 
235 
247 
257 void brushless11_set_brk_pin ( brushless11_t *ctx, uint8_t pin_state );
258 
269 
280 
290 void brushless11_set_brake ( brushless11_t *ctx, uint8_t brake_state );
291 
303 err_t brushless11_set_speed ( brushless11_t *ctx, uint8_t speed );
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 #endif // BRUSHLESS11_H
309  // brushless11
311 
312 // ------------------------------------------------------------------------ END
brushless11_get_fg2_pin
uint8_t brushless11_get_fg2_pin(brushless11_t *ctx)
Brushless 11 get FG2 pin state function.
brushless11_cfg_t
Brushless 11 Click configuration object.
Definition: brushless11.h:140
brushless11_cfg_t::brk
pin_name_t brk
Definition: brushless11.h:146
brushless11_t::pwm
pwm_t pwm
Definition: brushless11.h:128
brushless11_cfg_t::fg2
pin_name_t fg2
Definition: brushless11.h:147
brushless11_set_duty_cycle
err_t brushless11_set_duty_cycle(brushless11_t *ctx, float duty_cycle)
Brushless 11 sets PWM duty cycle.
brushless11_set_brk_pin
void brushless11_set_brk_pin(brushless11_t *ctx, uint8_t pin_state)
Brushless 11 set BRK pin state function.
brushless11_init
err_t brushless11_init(brushless11_t *ctx, brushless11_cfg_t *cfg)
Brushless 11 initialization function.
brushless11_pwm_start
err_t brushless11_pwm_start(brushless11_t *ctx)
Brushless 11 start PWM module.
brushless11_t::fg1
digital_in_t fg1
Definition: brushless11.h:124
brushless11_get_fg1_pin
uint8_t brushless11_get_fg1_pin(brushless11_t *ctx)
Brushless 11 get FG1 pin state function.
brushless11_cfg_t::pwm
pin_name_t pwm
Definition: brushless11.h:142
brushless11_cfg_setup
void brushless11_cfg_setup(brushless11_cfg_t *cfg)
Brushless 11 configuration object setup function.
brushless11_return_value_t
brushless11_return_value_t
Brushless 11 Click return value data.
Definition: brushless11.h:159
brushless11_pwm_stop
err_t brushless11_pwm_stop(brushless11_t *ctx)
Brushless 11 stop PWM module.
BRUSHLESS11_ERROR
@ BRUSHLESS11_ERROR
Definition: brushless11.h:161
brushless11_t::brk
digital_out_t brk
Definition: brushless11.h:121
brushless11_set_brake
void brushless11_set_brake(brushless11_t *ctx, uint8_t brake_state)
Brushless 11 set motor brake state function.
brushless11_default_cfg
err_t brushless11_default_cfg(brushless11_t *ctx)
Brushless 11 default configuration function.
brushless11_t::fg2
digital_in_t fg2
Definition: brushless11.h:125
BRUSHLESS11_OK
@ BRUSHLESS11_OK
Definition: brushless11.h:160
brushless11_t
Brushless 11 Click context object.
Definition: brushless11.h:119
brushless11_t::pwm_freq
uint32_t pwm_freq
Definition: brushless11.h:131
brushless11_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless11.h:150
brushless11_cfg_t::fg1
pin_name_t fg1
Definition: brushless11.h:145
brushless11_set_speed
err_t brushless11_set_speed(brushless11_t *ctx, uint8_t speed)
Brushless 11 set motor speed.