dcmotor4 2.0.0.0
dcmotor4.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 DCMOTOR4_H
36#define DCMOTOR4_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 DCMOTOR4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define DCMOTOR4_RETVAL uint8_t
78
79#define DCMOTOR4_OK 0x00
80#define DCMOTOR4_INIT_ERROR 0xFF
87#define DCMOTOR4_DEF_FREQ 10000
90 // End group macro
91// --------------------------------------------------------------- PUBLIC TYPES
100typedef struct
101{
102
103 // Output pins
104
105 digital_out_t dir;
106 digital_out_t en;
107
108 // Input pins
109
110 digital_in_t flt;
111
112 // Modules
113
114 pwm_t pwm;
115
116 // ctx variable
117
118 uint32_t pwm_freq;
119
120} dcmotor4_t;
121
125typedef struct
126{
127 // Communication gpio pins
128
129 pin_name_t pwm;
130
131 // Additional gpio pins
132
133 pin_name_t dir;
134 pin_name_t en;
135 pin_name_t flt;
136
137 // static variable
138
139 uint32_t dev_pwm_freq;
140
142
143 // End types group
144
145// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146
152#ifdef __cplusplus
153extern "C"{
154#endif
155
165
174
184void dcmotor4_set_duty_cycle ( dcmotor4_t *ctx, float duty_cycle );
185
194
203
212
221
230
239
248
249#ifdef __cplusplus
250}
251#endif
252#endif // _DCMOTOR4_H_
253
254 // End public_function group
256
257// ------------------------------------------------------------------------- END
#define DCMOTOR4_RETVAL
Definition dcmotor4.h:77
void dcmotor4_run_clockwise(dcmotor4_t *ctx)
Run clockwise.
void dcmotor4_pwm_stop(dcmotor4_t *ctx)
Stop PWM module.
void dcmotor4_disable_motor(dcmotor4_t *ctx)
Disable motor.
void dcmotor4_cfg_setup(dcmotor4_cfg_t *cfg)
Config Object Initialization function.
uint8_t dcmotor4_get_diagnostic(dcmotor4_t *ctx)
Get diagnostic.
void dcmotor4_run_counter_clockwise(dcmotor4_t *ctx)
Run counter clockwise.
void dcmotor4_set_duty_cycle(dcmotor4_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void dcmotor4_enable_motor(dcmotor4_t *ctx)
Enable motor.
DCMOTOR4_RETVAL dcmotor4_init(dcmotor4_t *ctx, dcmotor4_cfg_t *cfg)
Initialization function.
void dcmotor4_pwm_start(dcmotor4_t *ctx)
Start PWM module.
Click configuration structure definition.
Definition dcmotor4.h:126
uint32_t dev_pwm_freq
Definition dcmotor4.h:139
pin_name_t flt
Definition dcmotor4.h:135
pin_name_t dir
Definition dcmotor4.h:133
pin_name_t en
Definition dcmotor4.h:134
pin_name_t pwm
Definition dcmotor4.h:129
Click ctx object definition.
Definition dcmotor4.h:101
digital_in_t flt
Definition dcmotor4.h:110
uint32_t pwm_freq
Definition dcmotor4.h:118
digital_out_t en
Definition dcmotor4.h:106
pwm_t pwm
Definition dcmotor4.h:114
digital_out_t dir
Definition dcmotor4.h:105