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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DCMOTOR3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define DCMOTOR3_RETVAL uint8_t
64 
65 #define DCMOTOR3_OK 0x00
66 #define DCMOTOR3_INIT_ERROR 0xFF
67 
73 #define DCMOTOR3_DEF_FREQ 15000
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
86 typedef struct
87 {
88 
89  // Output pins
90 
91  digital_out_t in1;
92  digital_out_t in2;
93  digital_out_t slp;
94 
95  // Modules
96 
97  pwm_t pwm;
98 
99  // ctx variable
100 
101  uint16_t pwm_period;
102  uint32_t pwm_freq;
103 
104 } dcmotor3_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t pwm;
114 
115  // Additional gpio pins
116 
117  pin_name_t in1;
118  pin_name_t in2;
119  pin_name_t slp;
120 
121  // static variable
122 
123  uint32_t dev_pwm_freq;
124 
126  // End types group
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
157 
167 void dcmotor3_set_duty_cycle ( dcmotor3_t *ctx, float duty_cycle );
168 
177 
186 
195 
204 
214 
224 
233 
241 void dcmotor3_stop ( dcmotor3_t *ctx );
242 
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _DCMOTOR3_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
DCMOTOR3_RETVAL
#define DCMOTOR3_RETVAL
Definition: dcmotor3.h:63
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:117
dcmotor3_t::pwm
pwm_t pwm
Definition: dcmotor3.h:97
dcmotor3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor3.h:123
dcmotor3_pwm_start
void dcmotor3_pwm_start(dcmotor3_t *ctx)
Start PWM module.
dcmotor3_cfg_t::slp
pin_name_t slp
Definition: dcmotor3.h:119
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:92
dcmotor3_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor3.h:102
dcmotor3_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor3.h:113
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:118
dcmotor3_t
Click ctx object definition.
Definition: dcmotor3.h:87
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:101
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:91
dcmotor3_cfg_t
Click configuration structure definition.
Definition: dcmotor3.h:110
dcmotor3_short_brake
void dcmotor3_short_brake(dcmotor3_t *ctx)
Brake the engine function.
dcmotor3_t::slp
digital_out_t slp
Definition: dcmotor3.h:93