brushless18  2.1.0.0
brushless18.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BRUSHLESS18_H
29 #define BRUSHLESS18_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_pwm.h"
52 
73 #define BRUSHLESS18_DEF_FREQ 400
74 
79 #define BRUSHLESS18_DC_ZERO 0.0
80 #define BRUSHLESS18_DC_1MS ( BRUSHLESS18_DEF_FREQ / 1000.0 )
81 #define BRUSHLESS18_DC_MIN_THROTTLE ( BRUSHLESS18_DC_1MS * 1.064 )
82 #define BRUSHLESS18_DC_IDLE ( BRUSHLESS18_DC_1MS * 1.464 )
83 #define BRUSHLESS18_DC_MAX_THROTTLE ( BRUSHLESS18_DC_1MS * 1.864 )
84 #define BRUSHLESS18_DC_1_PCT ( ( BRUSHLESS18_DC_MAX_THROTTLE - BRUSHLESS18_DC_IDLE ) / 100.0 )
85 
90 #define BRUSHLESS18_SPEED_MIN 0
91 #define BRUSHLESS18_SPEED_MAX 100
92 #define BRUSHLESS18_DIRECTION_CW 0
93 #define BRUSHLESS18_DIRECTION_CCW 1
94  // brushless18_cfg
96 
111 #define BRUSHLESS18_MAP_MIKROBUS( cfg, mikrobus ) \
112  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
113  // brushless18_map // brushless18
116 
121 typedef struct
122 {
123  // Modules
124  pwm_t pwm;
126  // ctx variable
127  uint32_t pwm_freq;
129 } brushless18_t;
130 
135 typedef struct
136 {
137  // Communication gpio pins
138  pin_name_t pwm;
140  // Static variable
141  uint32_t dev_pwm_freq;
144 
149 typedef enum
150 {
152  BRUSHLESS18_ERROR = -1
153 
155 
172 
187 
199 err_t brushless18_set_duty_cycle ( brushless18_t *ctx, float duty_cycle );
200 
212 
224 
236 
250 err_t brushless18_drive_motor ( brushless18_t *ctx, uint8_t direction, uint8_t speed );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // BRUSHLESS18_H
256  // brushless18
258 
259 // ------------------------------------------------------------------------ END
brushless18_cfg_t
Brushless 18 Click configuration object.
Definition: brushless18.h:136
brushless18_t::pwm_freq
uint32_t pwm_freq
Definition: brushless18.h:127
brushless18_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless18.h:141
brushless18_cfg_t::pwm
pin_name_t pwm
Definition: brushless18.h:138
BRUSHLESS18_OK
@ BRUSHLESS18_OK
Definition: brushless18.h:151
brushless18_t::pwm
pwm_t pwm
Definition: brushless18.h:124
brushless18_pwm_start
err_t brushless18_pwm_start(brushless18_t *ctx)
Brushless 18 start PWM module.
brushless18_drive_motor
err_t brushless18_drive_motor(brushless18_t *ctx, uint8_t direction, uint8_t speed)
Brushless 18 drive motor module.
brushless18_pwm_stop
err_t brushless18_pwm_stop(brushless18_t *ctx)
Brushless 18 stop PWM module.
brushless18_throttle_calib
err_t brushless18_throttle_calib(brushless18_t *ctx)
Brushless 18 throttle calib module.
brushless18_cfg_setup
void brushless18_cfg_setup(brushless18_cfg_t *cfg)
Brushless 18 configuration object setup function.
brushless18_t
Brushless 18 Click context object.
Definition: brushless18.h:122
brushless18_init
err_t brushless18_init(brushless18_t *ctx, brushless18_cfg_t *cfg)
Brushless 18 initialization function.
brushless18_return_value_t
brushless18_return_value_t
Brushless 18 Click return value data.
Definition: brushless18.h:150
brushless18_set_duty_cycle
err_t brushless18_set_duty_cycle(brushless18_t *ctx, float duty_cycle)
Brushless 18 sets PWM duty cycle.
BRUSHLESS18_ERROR
@ BRUSHLESS18_ERROR
Definition: brushless18.h:152