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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 #include "drv_analog_in.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define BRUSHLESS_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
55  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define BRUSHLESS_RETVAL uint8_t
65 
66 #define BRUSHLESS_OK 0x00
67 #define BRUSHLESS_INIT_ERROR 0xFF
68 
74 #define BRUSHLESS_DEF_FREQ 5000
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef uint16_t brushless_data_t;
88 
92 typedef struct
93 {
94  // Output pins
95 
96  digital_out_t dir;
97 
98  // Input pins
99 
100  digital_in_t int_pin;
101 
102  // Modules
103 
104  pwm_t pwm;
105  analog_in_t adc;
106 
107  // ctx variable
108 
109  uint32_t pwm_freq;
110 
111 } brushless_t;
112 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t pwm;
121  pin_name_t an_pin;
122 
123  // Additional gpio pins
124 
125  pin_name_t dir;
126  pin_name_t int_pin;
127 
128  // static variable
129 
130  uint32_t dev_pwm_freq;
131 
132  analog_in_resolution_t resolution;
133  float vref;
134 
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
168 
177 void brushless_set_duty_cycle ( brushless_t *ctx, float duty_cycle );
178 
186 void brushless_pwm_stop ( brushless_t *ctx );
187 
195 void brushless_pwm_start ( brushless_t *ctx );
196 
206 
215 
224 
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _BRUSHLESS_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------- END
brushless_cfg_t
Click configuration structure definition.
Definition: brushless.h:116
BRUSHLESS_RETVAL
#define BRUSHLESS_RETVAL
Definition: brushless.h:64
brushless_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless.h:126
brushless_t
Click ctx object definition.
Definition: brushless.h:92
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:104
brushless_cfg_t::vref
float vref
Definition: brushless.h:133
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:120
brushless_t::pwm_freq
uint32_t pwm_freq
Definition: brushless.h:109
brushless_cfg_t::an_pin
pin_name_t an_pin
Definition: brushless.h:121
brushless_cfg_t::dir
pin_name_t dir
Definition: brushless.h:125
brushless_t::int_pin
digital_in_t int_pin
Definition: brushless.h:100
brushless_t::adc
analog_in_t adc
Definition: brushless.h:105
brushless_cfg_t::resolution
analog_in_resolution_t resolution
Definition: brushless.h:132
brushless_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless.h:130
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:87
brushless_t::dir
digital_out_t dir
Definition: brushless.h:96
brushless_spin_clockwise
void brushless_spin_clockwise(brushless_t *ctx)
Spin motor clockwise function.