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 )
75#define BRUSHLESS4_RETVAL uint8_t
76
77#define BRUSHLESS4_OK 0x00
78#define BRUSHLESS4_INIT_ERROR 0xFF
85#define BRUSHLESS4_DEF_FREQ 20000
88 // End group macro
89// --------------------------------------------------------------- PUBLIC TYPES
98typedef 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
116 uint16_t slots_poles;
117
119
123typedef 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
139 // End types group
140// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141
147#ifdef __cplusplus
148extern "C"{
149#endif
150
160
169
178
187void brushless4_set_duty_cycle ( brushless4_t *ctx, float duty_cycle );
188
197
206
216void brushless4_motor_parameters ( brushless4_t *ctx , uint8_t poles, uint8_t slots );
217
229uint16_t brushless4_get_speed ( brushless4_t *ctx, uint16_t pulse_sample );
230
239void brushless4_pwm_pin ( brushless4_t *ctx, uint8_t state );
240
250
251#ifdef __cplusplus
252}
253#endif
254#endif // _BRUSHLESS4_H_
255
256 // End public_function group
258
259// ------------------------------------------------------------------------- END
#define BRUSHLESS4_RETVAL
Definition brushless4.h:75
void brushless4_pwm_start(brushless4_t *ctx)
Start PWM module.
BRUSHLESS4_RETVAL brushless4_init(brushless4_t *ctx, brushless4_cfg_t *cfg)
Initialization function.
void brushless4_motor_parameters(brushless4_t *ctx, uint8_t poles, uint8_t slots)
Setting the number of poles and number of slots.
uint16_t brushless4_get_speed(brushless4_t *ctx, uint16_t pulse_sample)
Calculation of speed.
void brushless4_set_duty_cycle(brushless4_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void brushless4_cfg_setup(brushless4_cfg_t *cfg)
Config Object Initialization function.
void brushless4_default_cfg(brushless4_t *ctx)
Click Default Configuration function.
void brushless4_pwm_pin(brushless4_t *ctx, uint8_t state)
Set the state of the PWM pin.
uint8_t brushless4_fg_get(brushless4_t *ctx)
The state of the interrupt pin.
void brushless4_pwm_stop(brushless4_t *ctx)
Stop PWM module.
Click configuration structure definition.
Definition brushless4.h:124
pin_name_t fg
Definition brushless4.h:131
uint32_t dev_pwm_freq
Definition brushless4.h:135
pin_name_t pwm
Definition brushless4.h:127
Click ctx object definition.
Definition brushless4.h:99
uint16_t slots_poles
Definition brushless4.h:116
uint32_t pwm_freq
Definition brushless4.h:112
uint8_t num_of_poles
Definition brushless4.h:114
uint8_t num_of_slots
Definition brushless4.h:115
digital_in_t fg
Definition brushless4.h:103
pwm_t pwm
Definition brushless4.h:107
uint16_t pwm_period
Definition brushless4.h:111