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 "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 DCMOTOR_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg. slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg. sl1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg. sl2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg. flt = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define DCMOTOR_RETVAL uint8_t
75 
76 #define DCMOTOR_OK 0x00
77 #define DCMOTOR_INIT_ERROR 0xFF
78 
84 #define DCMOTOR_DEF_FREQ 20000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99 
100  // Output pins
101 
102  digital_out_t slp;
103  digital_out_t sl1;
104  digital_out_t sl2;
105 
106  // Input pins
107 
108  digital_in_t flt;
109 
110  // Modules
111 
112  pwm_t pwm;
113 
114  // ctx variable
115 
116  uint16_t pwm_period;
117  uint32_t pwm_freq;
118 
119 } dcmotor_t;
120 
124 typedef struct
125 {
126  // Communication gpio pins
127 
128  pin_name_t pwm;
129 
130  // Additional gpio pins
131 
132  pin_name_t slp;
133  pin_name_t sl1;
134  pin_name_t sl2;
135  pin_name_t flt;
136 
137  // static variable
138 
139  uint32_t dev_pwm_freq;
140 
141 } dcmotor_cfg_t;
142  // End types group
144 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
164 
173 
183 void dcmotor_set_duty_cycle ( dcmotor_t *ctx, float duty_cycle );
184 
193 
202 
210  void dcmotor_enable ( dcmotor_t *ctx );
211 
220 
229 
238 
247 
256 
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // _DCMOTOR_H_
270  // End public_function group
273 
274 // ------------------------------------------------------------------------- END
dcmotor_right_direction_slow
void dcmotor_right_direction_slow(dcmotor_t *ctx)
Select right direction, slow decay function.
dcmotor_right_direction_fast
void dcmotor_right_direction_fast(dcmotor_t *ctx)
Select right direction, fast decay function.
dcmotor_left_direction_slow
void dcmotor_left_direction_slow(dcmotor_t *ctx)
Select left direction, slow decay function.
dcmotor_pwm_start
void dcmotor_pwm_start(dcmotor_t *ctx)
Start PWM module.
dcmotor_get_diagnostic
uint8_t dcmotor_get_diagnostic(dcmotor_t *ctx)
Get diagnostic function.
dcmotor_cfg_t
Click configuration structure definition.
Definition: dcmotor.h:125
dcmotor_pwm_stop
void dcmotor_pwm_stop(dcmotor_t *ctx)
Stop PWM module.
dcmotor_t::pwm_period
uint16_t pwm_period
Definition: dcmotor.h:116
dcmotor_enable
void dcmotor_enable(dcmotor_t *ctx)
Enable the motor function.
dcmotor_t::flt
digital_in_t flt
Definition: dcmotor.h:108
dcmotor_cfg_t::flt
pin_name_t flt
Definition: dcmotor.h:135
dcmotor_cfg_t::sl1
pin_name_t sl1
Definition: dcmotor.h:133
dcmotor_cfg_t::sl2
pin_name_t sl2
Definition: dcmotor.h:134
dcmotor_t::slp
digital_out_t slp
Definition: dcmotor.h:102
dcmotor_t::sl1
digital_out_t sl1
Definition: dcmotor.h:103
dcmotor_t::sl2
digital_out_t sl2
Definition: dcmotor.h:104
dcmotor_t::pwm
pwm_t pwm
Definition: dcmotor.h:112
dcmotor_t
Click ctx object definition.
Definition: dcmotor.h:98
dcmotor_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor.h:139
dcmotor_cfg_setup
void dcmotor_cfg_setup(dcmotor_cfg_t *cfg)
Config Object Initialization function.
dcmotor_cfg_t::slp
pin_name_t slp
Definition: dcmotor.h:132
dcmotor_left_direction_fast
void dcmotor_left_direction_fast(dcmotor_t *ctx)
Select left direction, fast decay function.
dcmotor_init
DCMOTOR_RETVAL dcmotor_init(dcmotor_t *ctx, dcmotor_cfg_t *cfg)
Initialization function.
dcmotor_sleep_mode
void dcmotor_sleep_mode(dcmotor_t *ctx)
Set sleep mode function.
dcmotor_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor.h:128
DCMOTOR_RETVAL
#define DCMOTOR_RETVAL
Definition: dcmotor.h:74
dcmotor_set_duty_cycle
void dcmotor_set_duty_cycle(dcmotor_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor.h:117