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 
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 DCMOTOR_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg. slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg. sl1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg. sl2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg. flt = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define DCMOTOR_RETVAL uint8_t
79 
80 #define DCMOTOR_OK 0x00
81 #define DCMOTOR_INIT_ERROR 0xFF
82 
88 #define DCMOTOR_DEF_FREQ 20000
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103 
104  // Output pins
105 
106  digital_out_t slp;
107  digital_out_t sl1;
108  digital_out_t sl2;
109 
110  // Input pins
111 
112  digital_in_t flt;
113 
114  // Modules
115 
116  pwm_t pwm;
117 
118  // ctx variable
119 
120  uint16_t pwm_period;
121  uint32_t pwm_freq;
122 
123 } dcmotor_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t pwm;
133 
134  // Additional gpio pins
135 
136  pin_name_t slp;
137  pin_name_t sl1;
138  pin_name_t sl2;
139  pin_name_t flt;
140 
141  // static variable
142 
143  uint32_t dev_pwm_freq;
144 
145 } dcmotor_cfg_t;
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
177 
187 void dcmotor_set_duty_cycle ( dcmotor_t *ctx, float duty_cycle );
188 
197 
206 
214  void dcmotor_enable ( dcmotor_t *ctx );
215 
224 
233 
242 
251 
260 
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 #endif // _DCMOTOR_H_
274  // End public_function group
277 
278 // ------------------------------------------------------------------------- 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:129
dcmotor_pwm_stop
void dcmotor_pwm_stop(dcmotor_t *ctx)
Stop PWM module.
dcmotor_t::pwm_period
uint16_t pwm_period
Definition: dcmotor.h:120
dcmotor_enable
void dcmotor_enable(dcmotor_t *ctx)
Enable the motor function.
dcmotor_t::flt
digital_in_t flt
Definition: dcmotor.h:112
dcmotor_cfg_t::flt
pin_name_t flt
Definition: dcmotor.h:139
dcmotor_cfg_t::sl1
pin_name_t sl1
Definition: dcmotor.h:137
dcmotor_cfg_t::sl2
pin_name_t sl2
Definition: dcmotor.h:138
dcmotor_t::slp
digital_out_t slp
Definition: dcmotor.h:106
dcmotor_t::sl1
digital_out_t sl1
Definition: dcmotor.h:107
dcmotor_t::sl2
digital_out_t sl2
Definition: dcmotor.h:108
dcmotor_t::pwm
pwm_t pwm
Definition: dcmotor.h:116
dcmotor_t
Click ctx object definition.
Definition: dcmotor.h:102
dcmotor_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor.h:143
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:136
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:132
DCMOTOR_RETVAL
#define DCMOTOR_RETVAL
Definition: dcmotor.h:78
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:121