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 )
64#define BRUSHLESS_RETVAL uint8_t
65
66#define BRUSHLESS_OK 0x00
67#define BRUSHLESS_INIT_ERROR 0xFF
74#define BRUSHLESS_DEF_FREQ 5000 // End group macro
78// --------------------------------------------------------------- PUBLIC TYPES
87typedef uint16_t brushless_data_t;
88
92typedef 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
112
116typedef 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
146extern "C"{
147#endif
148
158
168
177void brushless_set_duty_cycle ( brushless_t *ctx, float duty_cycle );
178
187
196
206
215
224
233
234#ifdef __cplusplus
235}
236#endif
237#endif // _BRUSHLESS_H_
238 // End public_function group
241
242// ------------------------------------------------------------------------- END
#define BRUSHLESS_RETVAL
Definition: brushless.h:64
brushless_data_t brushless_generic_read(brushless_t *ctx)
Generic read function.
void brushless_pwm_stop(brushless_t *ctx)
Stop PWM module.
uint8_t brushless_read_rotation_speed_sensor_output(brushless_t *ctx)
Read rotation speed sensor output function.
void brushless_spin_clockwise(brushless_t *ctx)
Spin motor clockwise function.
void brushless_pwm_start(brushless_t *ctx)
Start PWM module.
void brushless_spin_counter_clockwise(brushless_t *ctx)
Spin motor counter clockwise function.
BRUSHLESS_RETVAL brushless_init(brushless_t *ctx, brushless_cfg_t *cfg)
Initialization function.
void brushless_cfg_setup(brushless_cfg_t *cfg)
Config Object Initialization function.
void brushless_set_duty_cycle(brushless_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
uint16_t brushless_data_t
Analog data type.
Definition: brushless.h:87
Click configuration structure definition.
Definition: brushless.h:117
analog_in_resolution_t resolution
Definition: brushless.h:132
float vref
Definition: brushless.h:133
pin_name_t an_pin
Definition: brushless.h:121
uint32_t dev_pwm_freq
Definition: brushless.h:130
pin_name_t dir
Definition: brushless.h:125
pin_name_t int_pin
Definition: brushless.h:126
pin_name_t pwm
Definition: brushless.h:120
Click ctx object definition.
Definition: brushless.h:93
uint32_t pwm_freq
Definition: brushless.h:109
digital_in_t int_pin
Definition: brushless.h:100
analog_in_t adc
Definition: brushless.h:105
pwm_t pwm
Definition: brushless.h:104
digital_out_t dir
Definition: brushless.h:96