dcmotor 2.0.0.0
dcmotor.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 DCMOTOR_H
36#define DCMOTOR_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_pwm.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define DCMOTOR_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54 cfg. slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55 cfg. sl1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56 cfg. sl2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57 cfg. flt = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define DCMOTOR_RETVAL uint8_t
65
66#define DCMOTOR_OK 0x00
67#define DCMOTOR_INIT_ERROR 0xFF
74#define DCMOTOR_DEF_FREQ 20000 // End group macro
78// --------------------------------------------------------------- PUBLIC TYPES
87typedef struct
88{
89
90 // Output pins
91
92 digital_out_t slp;
93 digital_out_t sl1;
94 digital_out_t sl2;
95
96 // Input pins
97
98 digital_in_t flt;
99
100 // Modules
101
102 pwm_t pwm;
103
104 // ctx variable
105
106 uint16_t pwm_period;
107 uint32_t pwm_freq;
108
109} dcmotor_t;
110
114typedef struct
115{
116 // Communication gpio pins
117
118 pin_name_t pwm;
119
120 // Additional gpio pins
121
122 pin_name_t slp;
123 pin_name_t sl1;
124 pin_name_t sl2;
125 pin_name_t flt;
126
127 // static variable
128
129 uint32_t dev_pwm_freq;
130
132 // End types group
134// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135
141#ifdef __cplusplus
142extern "C"{
143#endif
144
154
163
173void dcmotor_set_duty_cycle ( dcmotor_t *ctx, float duty_cycle );
174
183
192
201
210
219
228
237
246
255
256#ifdef __cplusplus
257}
258#endif
259#endif // _DCMOTOR_H_
260 // End public_function group
263
264// ------------------------------------------------------------------------- END
#define DCMOTOR_RETVAL
Definition: dcmotor.h:64
void dcmotor_right_direction_fast(dcmotor_t *ctx)
Select right direction, fast decay function.
void dcmotor_left_direction_slow(dcmotor_t *ctx)
Select left direction, slow decay function.
void dcmotor_sleep_mode(dcmotor_t *ctx)
Set sleep mode function.
uint8_t dcmotor_get_diagnostic(dcmotor_t *ctx)
Get diagnostic function.
DCMOTOR_RETVAL dcmotor_init(dcmotor_t *ctx, dcmotor_cfg_t *cfg)
Initialization function.
void dcmotor_set_duty_cycle(dcmotor_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void dcmotor_right_direction_slow(dcmotor_t *ctx)
Select right direction, slow decay function.
void dcmotor_pwm_stop(dcmotor_t *ctx)
Stop PWM module.
void dcmotor_cfg_setup(dcmotor_cfg_t *cfg)
Config Object Initialization function.
void dcmotor_pwm_start(dcmotor_t *ctx)
Start PWM module.
void dcmotor_enable(dcmotor_t *ctx)
Enable the motor function.
void dcmotor_left_direction_fast(dcmotor_t *ctx)
Select left direction, fast decay function.
Click configuration structure definition.
Definition: dcmotor.h:115
pin_name_t sl2
Definition: dcmotor.h:124
pin_name_t slp
Definition: dcmotor.h:122
uint32_t dev_pwm_freq
Definition: dcmotor.h:129
pin_name_t flt
Definition: dcmotor.h:125
pin_name_t pwm
Definition: dcmotor.h:118
pin_name_t sl1
Definition: dcmotor.h:123
Click ctx object definition.
Definition: dcmotor.h:88
digital_out_t sl2
Definition: dcmotor.h:94
digital_in_t flt
Definition: dcmotor.h:98
digital_out_t slp
Definition: dcmotor.h:92
uint32_t pwm_freq
Definition: dcmotor.h:107
digital_out_t sl1
Definition: dcmotor.h:93
pwm_t pwm
Definition: dcmotor.h:102
uint16_t pwm_period
Definition: dcmotor.h:106