brushless6  2.0.0.0
brushless6.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 BRUSHLESS6_H
36 #define BRUSHLESS6_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 BRUSHLESS6_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68 
69 
70  //cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
77 #define BRUSHLESS6_RETVAL uint8_t
78 
79 #define BRUSHLESS6_OK 0x00
80 #define BRUSHLESS6_INIT_ERROR 0xFF
81 
87 #define BRUSHLESS6_DEF_FREQ 500
88 
94 #define BRUSHLESS6_COEF 1.0 / ( ( 1000000.0 / BRUSHLESS6_DEF_FREQ ) / 0.3048 )
95 #define BRUSHLESS6_MIN_PWM_DC BRUSHLESS6_COEF * 2000.0
96 #define BRUSHLESS6_INIT_DC BRUSHLESS6_COEF * 4855.0
97 #define BRUSHLESS6_1MS_DC BRUSHLESS6_MIN_PWM_DC / 0.608
98 #define BRUSHLESS6_2MS_DC BRUSHLESS6_1MS_DC * 2.0
99 #define BRUSHLESS6_PERIOD BRUSHLESS6_1MS_DC / 10.0
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114 
115  // Modules
116 
117  pwm_t pwm;
118 
119  // ctx variable
120 
121  uint32_t pwm_freq;
122 
123 } brushless6_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t pwm;
133 
134  // static variable
135 
136  uint32_t dev_pwm_freq;
137 
139  // End types group
141 
142 
143  // End constants group
145 
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
166 
175 
176 
186 void brushless6_set_duty_cycle ( brushless6_t *ctx, float duty_cycle );
187 
196 
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 #endif // _BRUSHLESS6_H_
210  // End public_function group
213 
214 // ------------------------------------------------------------------------- END
BRUSHLESS6_RETVAL
#define BRUSHLESS6_RETVAL
Definition: brushless6.h:77
brushless6_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless6.h:136
brushless6_t::pwm_freq
uint32_t pwm_freq
Definition: brushless6.h:121
brushless6_init
BRUSHLESS6_RETVAL brushless6_init(brushless6_t *ctx, brushless6_cfg_t *cfg)
Initialization function.
brushless6_cfg_t::pwm
pin_name_t pwm
Definition: brushless6.h:132
brushless6_t::pwm
pwm_t pwm
Definition: brushless6.h:117
brushless6_set_duty_cycle
void brushless6_set_duty_cycle(brushless6_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless6_t
Click ctx object definition.
Definition: brushless6.h:113
brushless6_pwm_stop
void brushless6_pwm_stop(brushless6_t *ctx)
Stop PWM module.
brushless6_cfg_t
Click configuration structure definition.
Definition: brushless6.h:129
brushless6_pwm_start
void brushless6_pwm_start(brushless6_t *ctx)
Start PWM module.
brushless6_cfg_setup
void brushless6_cfg_setup(brushless6_cfg_t *cfg)
Config Object Initialization function.