dcmotor3  2.0.0.0
dcmotor3.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 DCMOTOR3_H
36 #define DCMOTOR3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_pwm.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DCMOTOR3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS )
67 
73 #define DCMOTOR3_RETVAL uint8_t
74 
75 #define DCMOTOR3_OK 0x00
76 #define DCMOTOR3_INIT_ERROR 0xFF
77 
83 #define DCMOTOR3_DEF_FREQ 15000
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98 
99  // Output pins
100 
101  digital_out_t in1;
102  digital_out_t in2;
103  digital_out_t slp;
104 
105  // Modules
106 
107  pwm_t pwm;
108 
109  // ctx variable
110 
111  uint16_t pwm_period;
112  uint32_t pwm_freq;
113 
114 } dcmotor3_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t pwm;
124 
125  // Additional gpio pins
126 
127  pin_name_t in1;
128  pin_name_t in2;
129  pin_name_t slp;
130 
131  // static variable
132 
133  uint32_t dev_pwm_freq;
134 
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
167 
177 void dcmotor3_set_duty_cycle ( dcmotor3_t *ctx, float duty_cycle );
178 
187 
196 
205 
214 
224 
234 
243 
251 void dcmotor3_stop ( dcmotor3_t *ctx );
252 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // _DCMOTOR3_H_
258  // End public_function group
261 
262 // ------------------------------------------------------------------------- END
DCMOTOR3_RETVAL
#define DCMOTOR3_RETVAL
Definition: dcmotor3.h:73
dcmotor3_clockwise
void dcmotor3_clockwise(dcmotor3_t *ctx)
Set the direction of rotation in the clockwise direction function.
dcmotor3_set_duty_cycle
void dcmotor3_set_duty_cycle(dcmotor3_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor3_standby
void dcmotor3_standby(dcmotor3_t *ctx)
Disable the engine function.
dcmotor3_cfg_t::in1
pin_name_t in1
Definition: dcmotor3.h:127
dcmotor3_t::pwm
pwm_t pwm
Definition: dcmotor3.h:107
dcmotor3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor3.h:133
dcmotor3_pwm_start
void dcmotor3_pwm_start(dcmotor3_t *ctx)
Start PWM module.
dcmotor3_cfg_t::slp
pin_name_t slp
Definition: dcmotor3.h:129
dcmotor3_pwm_stop
void dcmotor3_pwm_stop(dcmotor3_t *ctx)
Stop PWM module.
dcmotor3_stop
void dcmotor3_stop(dcmotor3_t *ctx)
Stop the engine function.
dcmotor3_t::in2
digital_out_t in2
Definition: dcmotor3.h:102
dcmotor3_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor3.h:112
dcmotor3_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor3.h:123
dcmotor3_init
DCMOTOR3_RETVAL dcmotor3_init(dcmotor3_t *ctx, dcmotor3_cfg_t *cfg)
Initialization function.
dcmotor3_enable
void dcmotor3_enable(dcmotor3_t *ctx)
Enable the engine function.
dcmotor3_cfg_t::in2
pin_name_t in2
Definition: dcmotor3.h:128
dcmotor3_t
Click ctx object definition.
Definition: dcmotor3.h:97
dcmotor3_cfg_setup
void dcmotor3_cfg_setup(dcmotor3_cfg_t *cfg)
Config Object Initialization function.
dcmotor3_t::pwm_period
uint16_t pwm_period
Definition: dcmotor3.h:111
dcmotor3_counter_clockwise
void dcmotor3_counter_clockwise(dcmotor3_t *ctx)
Set the direction of rotation in the counter clockwise direction function.
dcmotor3_t::in1
digital_out_t in1
Definition: dcmotor3.h:101
dcmotor3_cfg_t
Click configuration structure definition.
Definition: dcmotor3.h:120
dcmotor3_short_brake
void dcmotor3_short_brake(dcmotor3_t *ctx)
Brake the engine function.
dcmotor3_t::slp
digital_out_t slp
Definition: dcmotor3.h:103