brushless4  2.0.0.0
brushless4.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 BRUSHLESS4_H
36 #define BRUSHLESS4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define BRUSHLESS4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.fg = MIKROBUS( mikrobus, MIKROBUS_INT )
55 
61 #define BRUSHLESS4_RETVAL uint8_t
62 
63 #define BRUSHLESS4_OK 0x00
64 #define BRUSHLESS4_INIT_ERROR 0xFF
65 
71 #define BRUSHLESS4_DEF_FREQ 20000
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef struct
85 {
86 
87  // Input pins
88 
89  digital_in_t fg;
90 
91  // Modules
92 
93  pwm_t pwm;
94 
95  // ctx variable
96 
97  uint16_t pwm_period;
98  uint32_t pwm_freq;
99 
100  uint8_t num_of_poles;
101  uint8_t num_of_slots;
102  uint16_t slots_poles;
103 
104 } brushless4_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t pwm;
114 
115  // Additional gpio pins
116 
117  pin_name_t fg;
118 
119  // static variable
120 
121  uint32_t dev_pwm_freq;
122 
124  // End types group
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
127 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
146 
155 
164 
173 void brushless4_set_duty_cycle ( brushless4_t *ctx, float duty_cycle );
174 
182 void brushless4_pwm_stop ( brushless4_t *ctx );
183 
191 void brushless4_pwm_start ( brushless4_t *ctx );
192 
202 void brushless4_motor_parameters ( brushless4_t *ctx , uint8_t poles, uint8_t slots );
203 
215 uint16_t brushless4_get_speed ( brushless4_t *ctx, uint16_t pulse_sample );
216 
225 void brushless4_pwm_pin ( brushless4_t *ctx, uint8_t state );
226 
235 uint8_t brushless4_fg_get ( brushless4_t *ctx );
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 #endif // _BRUSHLESS4_H_
241  // End public_function group
244 
245 // ------------------------------------------------------------------------- END
brushless4_t
Click ctx object definition.
Definition: brushless4.h:84
brushless4_default_cfg
void brushless4_default_cfg(brushless4_t *ctx)
Click Default Configuration function.
brushless4_cfg_t::pwm
pin_name_t pwm
Definition: brushless4.h:113
brushless4_t::num_of_slots
uint8_t num_of_slots
Definition: brushless4.h:101
BRUSHLESS4_RETVAL
#define BRUSHLESS4_RETVAL
Definition: brushless4.h:61
brushless4_fg_get
uint8_t brushless4_fg_get(brushless4_t *ctx)
The state of the interrupt pin.
brushless4_get_speed
uint16_t brushless4_get_speed(brushless4_t *ctx, uint16_t pulse_sample)
Calculation of speed.
brushless4_motor_parameters
void brushless4_motor_parameters(brushless4_t *ctx, uint8_t poles, uint8_t slots)
Setting the number of poles and number of slots.
brushless4_t::num_of_poles
uint8_t num_of_poles
Definition: brushless4.h:100
brushless4_cfg_setup
void brushless4_cfg_setup(brushless4_cfg_t *cfg)
Config Object Initialization function.
brushless4_t::pwm_freq
uint32_t pwm_freq
Definition: brushless4.h:98
brushless4_init
BRUSHLESS4_RETVAL brushless4_init(brushless4_t *ctx, brushless4_cfg_t *cfg)
Initialization function.
brushless4_set_duty_cycle
void brushless4_set_duty_cycle(brushless4_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless4_pwm_stop
void brushless4_pwm_stop(brushless4_t *ctx)
Stop PWM module.
brushless4_cfg_t::fg
pin_name_t fg
Definition: brushless4.h:117
brushless4_pwm_pin
void brushless4_pwm_pin(brushless4_t *ctx, uint8_t state)
Set the state of the PWM pin.
brushless4_t::fg
digital_in_t fg
Definition: brushless4.h:89
brushless4_t::slots_poles
uint16_t slots_poles
Definition: brushless4.h:102
brushless4_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless4.h:121
brushless4_pwm_start
void brushless4_pwm_start(brushless4_t *ctx)
Start PWM module.
brushless4_t::pwm
pwm_t pwm
Definition: brushless4.h:93
brushless4_cfg_t
Click configuration structure definition.
Definition: brushless4.h:109
brushless4_t::pwm_period
uint16_t pwm_period
Definition: brushless4.h:97