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 
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 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define BRUSHLESS4_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.fg = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define BRUSHLESS4_RETVAL uint8_t
76 
77 #define BRUSHLESS4_OK 0x00
78 #define BRUSHLESS4_INIT_ERROR 0xFF
79 
85 #define BRUSHLESS4_DEF_FREQ 20000
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100 
101  // Input pins
102 
103  digital_in_t fg;
104 
105  // Modules
106 
107  pwm_t pwm;
108 
109  // ctx variable
110 
111  uint16_t pwm_period;
112  uint32_t pwm_freq;
113 
114  uint8_t num_of_poles;
115  uint8_t num_of_slots;
116  uint16_t slots_poles;
117 
118 } brushless4_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t pwm;
128 
129  // Additional gpio pins
130 
131  pin_name_t fg;
132 
133  // static variable
134 
135  uint32_t dev_pwm_freq;
136 
138  // End types group
140 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141 
147 #ifdef __cplusplus
148 extern "C"{
149 #endif
150 
160 
169 
178 
187 void brushless4_set_duty_cycle ( brushless4_t *ctx, float duty_cycle );
188 
197 
206 
216 void brushless4_motor_parameters ( brushless4_t *ctx , uint8_t poles, uint8_t slots );
217 
229 uint16_t brushless4_get_speed ( brushless4_t *ctx, uint16_t pulse_sample );
230 
239 void brushless4_pwm_pin ( brushless4_t *ctx, uint8_t state );
240 
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 #endif // _BRUSHLESS4_H_
255  // End public_function group
258 
259 // ------------------------------------------------------------------------- END
brushless4_t
Click ctx object definition.
Definition: brushless4.h:99
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:127
brushless4_t::num_of_slots
uint8_t num_of_slots
Definition: brushless4.h:115
BRUSHLESS4_RETVAL
#define BRUSHLESS4_RETVAL
Definition: brushless4.h:75
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:114
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:112
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:131
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:103
brushless4_t::slots_poles
uint16_t slots_poles
Definition: brushless4.h:116
brushless4_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless4.h:135
brushless4_pwm_start
void brushless4_pwm_start(brushless4_t *ctx)
Start PWM module.
brushless4_t::pwm
pwm_t pwm
Definition: brushless4.h:107
brushless4_cfg_t
Click configuration structure definition.
Definition: brushless4.h:124
brushless4_t::pwm_period
uint16_t pwm_period
Definition: brushless4.h:111