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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_pwm.h"
55 #include "drv_analog_in.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define BRUSHLESS_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define BRUSHLESS_RETVAL uint8_t
79 
80 #define BRUSHLESS_OK 0x00
81 #define BRUSHLESS_INIT_ERROR 0xFF
82 
88 #define BRUSHLESS_DEF_FREQ 5000
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef uint16_t brushless_data_t;
102 
106 typedef struct
107 {
108  // Output pins
109 
110  digital_out_t dir;
111 
112  // Input pins
113 
114  digital_in_t int_pin;
115 
116  // Modules
117 
118  pwm_t pwm;
119  analog_in_t adc;
120 
121  // ctx variable
122 
123  uint32_t pwm_freq;
124 
125 } brushless_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133 
134  pin_name_t pwm;
135  pin_name_t an_pin;
136 
137  // Additional gpio pins
138 
139  pin_name_t dir;
140  pin_name_t int_pin;
141 
142  // static variable
143 
144  uint32_t dev_pwm_freq;
145 
146  analog_in_resolution_t resolution;
147  float vref;
148 
150  // End types group
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
182 
191 void brushless_set_duty_cycle ( brushless_t *ctx, float duty_cycle );
192 
201 
210 
220 
229 
238 
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // _BRUSHLESS_H_
252  // End public_function group
255 
256 // ------------------------------------------------------------------------- END
brushless_cfg_t
Click configuration structure definition.
Definition: brushless.h:131
BRUSHLESS_RETVAL
#define BRUSHLESS_RETVAL
Definition: brushless.h:78
brushless_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless.h:140
brushless_t
Click ctx object definition.
Definition: brushless.h:107
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:118
brushless_cfg_t::vref
float vref
Definition: brushless.h:147
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:134
brushless_t::pwm_freq
uint32_t pwm_freq
Definition: brushless.h:123
brushless_cfg_t::an_pin
pin_name_t an_pin
Definition: brushless.h:135
brushless_cfg_t::dir
pin_name_t dir
Definition: brushless.h:139
brushless_t::int_pin
digital_in_t int_pin
Definition: brushless.h:114
brushless_t::adc
analog_in_t adc
Definition: brushless.h:119
brushless_cfg_t::resolution
analog_in_resolution_t resolution
Definition: brushless.h:146
brushless_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless.h:144
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:101
brushless_t::dir
digital_out_t dir
Definition: brushless.h:110
brushless_spin_clockwise
void brushless_spin_clockwise(brushless_t *ctx)
Spin motor clockwise function.