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 
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 DCMOTOR3_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS )
71 
77 #define DCMOTOR3_RETVAL uint8_t
78 
79 #define DCMOTOR3_OK 0x00
80 #define DCMOTOR3_INIT_ERROR 0xFF
81 
87 #define DCMOTOR3_DEF_FREQ 15000
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
100 typedef struct
101 {
102 
103  // Output pins
104 
105  digital_out_t in1;
106  digital_out_t in2;
107  digital_out_t slp;
108 
109  // Modules
110 
111  pwm_t pwm;
112 
113  // ctx variable
114 
115  uint16_t pwm_period;
116  uint32_t pwm_freq;
117 
118 } dcmotor3_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t pwm;
128 
129  // Additional gpio pins
130 
131  pin_name_t in1;
132  pin_name_t in2;
133  pin_name_t slp;
134 
135  // static variable
136 
137  uint32_t dev_pwm_freq;
138 
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
162 
171 
181 void dcmotor3_set_duty_cycle ( dcmotor3_t *ctx, float duty_cycle );
182 
191 
200 
209 
218 
228 
238 
247 
255 void dcmotor3_stop ( dcmotor3_t *ctx );
256 
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 #endif // _DCMOTOR3_H_
262  // End public_function group
265 
266 // ------------------------------------------------------------------------- END
DCMOTOR3_RETVAL
#define DCMOTOR3_RETVAL
Definition: dcmotor3.h:77
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:131
dcmotor3_t::pwm
pwm_t pwm
Definition: dcmotor3.h:111
dcmotor3_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor3.h:137
dcmotor3_pwm_start
void dcmotor3_pwm_start(dcmotor3_t *ctx)
Start PWM module.
dcmotor3_cfg_t::slp
pin_name_t slp
Definition: dcmotor3.h:133
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:106
dcmotor3_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor3.h:116
dcmotor3_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor3.h:127
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:132
dcmotor3_t
Click ctx object definition.
Definition: dcmotor3.h:101
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:115
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:105
dcmotor3_cfg_t
Click configuration structure definition.
Definition: dcmotor3.h:124
dcmotor3_short_brake
void dcmotor3_short_brake(dcmotor3_t *ctx)
Brake the engine function.
dcmotor3_t::slp
digital_out_t slp
Definition: dcmotor3.h:107