brushless  2.0.0.0
brushless.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 BRUSHLESS_H
36 #define BRUSHLESS_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_pwm.h"
51 #include "drv_analog_in.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define BRUSHLESS_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
65  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define BRUSHLESS_RETVAL uint8_t
75 
76 #define BRUSHLESS_OK 0x00
77 #define BRUSHLESS_INIT_ERROR 0xFF
78 
84 #define BRUSHLESS_DEF_FREQ 5000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef uint16_t brushless_data_t;
98 
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t dir;
107 
108  // Input pins
109 
110  digital_in_t int_pin;
111 
112  // Modules
113 
114  pwm_t pwm;
115  analog_in_t adc;
116 
117  // ctx variable
118 
119  uint32_t pwm_freq;
120 
121 } brushless_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129 
130  pin_name_t pwm;
131  pin_name_t an_pin;
132 
133  // Additional gpio pins
134 
135  pin_name_t dir;
136  pin_name_t int_pin;
137 
138  // static variable
139 
140  uint32_t dev_pwm_freq;
141 
142  analog_in_resolution_t resolution;
143  float vref;
144 
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
187 void brushless_set_duty_cycle ( brushless_t *ctx, float duty_cycle );
188 
197 
206 
216 
225 
234 
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _BRUSHLESS_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
brushless_cfg_t
Click configuration structure definition.
Definition: brushless.h:127
BRUSHLESS_RETVAL
#define BRUSHLESS_RETVAL
Definition: brushless.h:74
brushless_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless.h:136
brushless_t
Click ctx object definition.
Definition: brushless.h:103
brushless_init
BRUSHLESS_RETVAL brushless_init(brushless_t *ctx, brushless_cfg_t *cfg)
Initialization function.
brushless_cfg_setup
void brushless_cfg_setup(brushless_cfg_t *cfg)
Config Object Initialization function.
brushless_t::pwm
pwm_t pwm
Definition: brushless.h:114
brushless_cfg_t::vref
float vref
Definition: brushless.h:143
brushless_read_rotation_speed_sensor_output
uint8_t brushless_read_rotation_speed_sensor_output(brushless_t *ctx)
Read rotation speed sensor output function.
brushless_generic_read
brushless_data_t brushless_generic_read(brushless_t *ctx)
Generic read function.
brushless_pwm_stop
void brushless_pwm_stop(brushless_t *ctx)
Stop PWM module.
brushless_pwm_start
void brushless_pwm_start(brushless_t *ctx)
Start PWM module.
brushless_cfg_t::pwm
pin_name_t pwm
Definition: brushless.h:130
brushless_t::pwm_freq
uint32_t pwm_freq
Definition: brushless.h:119
brushless_cfg_t::an_pin
pin_name_t an_pin
Definition: brushless.h:131
brushless_cfg_t::dir
pin_name_t dir
Definition: brushless.h:135
brushless_t::int_pin
digital_in_t int_pin
Definition: brushless.h:110
brushless_t::adc
analog_in_t adc
Definition: brushless.h:115
brushless_cfg_t::resolution
analog_in_resolution_t resolution
Definition: brushless.h:142
brushless_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless.h:140
brushless_set_duty_cycle
void brushless_set_duty_cycle(brushless_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless_spin_counter_clockwise
void brushless_spin_counter_clockwise(brushless_t *ctx)
Spin motor counter clockwise function.
brushless_data_t
uint16_t brushless_data_t
Analog data type.
Definition: brushless.h:97
brushless_t::dir
digital_out_t dir
Definition: brushless.h:106
brushless_spin_clockwise
void brushless_spin_clockwise(brushless_t *ctx)
Spin motor clockwise function.