dcmotor5  2.0.0.0
dcmotor5.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef DCMOTOR5_H
29 #define DCMOTOR5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_pwm.h"
52 
73 #define DCMOTOR5_DEF_FREQ 20000
74  // dcmotor5_cfg
76 
91 #define DCMOTOR5_MAP_MIKROBUS( cfg, mikrobus ) \
92  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
93  cfg.snso = MIKROBUS( mikrobus, MIKROBUS_AN ); \
94  cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_RST ); \
95  cfg.fault = MIKROBUS( mikrobus, MIKROBUS_CS ); \
96  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT );
97  // dcmotor5_map // dcmotor5
100 
105 typedef struct
106 {
107  // Output pins
108  digital_out_t sleep;
109  digital_out_t in2;
111  // Input pins
112  digital_in_t snso;
113  digital_in_t fault;
115  // Modules
116  pwm_t pwm;
118  // ctx variable
119  uint32_t pwm_freq;
121 } dcmotor5_t;
122 
127 typedef struct
128 {
129  // Communication gpio pins
130  pin_name_t pwm;
132  // Additional gpio pins
133  pin_name_t snso;
134  pin_name_t sleep;
135  pin_name_t fault;
136  pin_name_t in2;
138  // Static variable
139  uint32_t dev_pwm_freq;
142 
147 typedef enum
148 {
150  DCMOTOR5_ERROR = -1
151 
153 
170 
182 
196 
205 void dcmotor5_set_duty_cycle ( dcmotor5_t *ctx, float duty_cycle );
206 
215 
224 
233 
243 
253 
263 
272 
280 void dcmotor5_stop ( dcmotor5_t *ctx );
281 
290 
300 
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 #endif // DCMOTOR5_H
306  // dcmotor5
308 
309 // ------------------------------------------------------------------------ END
dcmotor5_t::fault
digital_in_t fault
Definition: dcmotor5.h:113
dcmotor5_cfg_t::snso
pin_name_t snso
Definition: dcmotor5.h:133
DCMOTOR5_OK
@ DCMOTOR5_OK
Definition: dcmotor5.h:149
dcmotor5_standby
void dcmotor5_standby(dcmotor5_t *ctx)
DC Motor 5 Disable the engine function.
dcmotor5_cfg_t::sleep
pin_name_t sleep
Definition: dcmotor5.h:134
dcmotor5_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor5.h:119
dcmotor5_pwm_start
void dcmotor5_pwm_start(dcmotor5_t *ctx)
DC Motor 5 start PWM module.
dcmotor5_get_fault_conditions
uint8_t dcmotor5_get_fault_conditions(dcmotor5_t *ctx)
DC Motor 5 get fault conditions state function.
dcmotor5_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor5.h:139
dcmotor5_cfg_t::fault
pin_name_t fault
Definition: dcmotor5.h:135
dcmotor5_init
err_t dcmotor5_init(dcmotor5_t *ctx, dcmotor5_cfg_t *cfg)
DC Motor 5 initialization function.
dcmotor5_default_cfg
void dcmotor5_default_cfg(dcmotor5_t *ctx)
DC Motor 5 default configuration function.
dcmotor5_clockwise
void dcmotor5_clockwise(dcmotor5_t *ctx)
DC Motor 5 Set the direction of rotation in the clockwise direction function.
dcmotor5_set_duty_cycle
void dcmotor5_set_duty_cycle(dcmotor5_t *ctx, float duty_cycle)
DC Motor 5 sets PWM duty cycle.
dcmotor5_t::snso
digital_in_t snso
Definition: dcmotor5.h:112
dcmotor5_return_value_t
dcmotor5_return_value_t
DC Motor 5 Click return value data.
Definition: dcmotor5.h:148
dcmotor5_short_brake
void dcmotor5_short_brake(dcmotor5_t *ctx)
DC Motor 5 brake the engine function.
dcmotor5_t
DC Motor 5 Click context object.
Definition: dcmotor5.h:106
dcmotor5_t::sleep
digital_out_t sleep
Definition: dcmotor5.h:108
dcmotor5_stop
void dcmotor5_stop(dcmotor5_t *ctx)
DC Motor 5 stop the engine function.
dcmotor5_cfg_setup
void dcmotor5_cfg_setup(dcmotor5_cfg_t *cfg)
DC Motor 5 configuration object setup function.
dcmotor5_counter_clockwise
void dcmotor5_counter_clockwise(dcmotor5_t *ctx)
DC Motor 5 Set the direction of rotation in the counter clockwise direction function.
dcmotor5_cfg_t
DC Motor 5 Click configuration object.
Definition: dcmotor5.h:128
dcmotor5_pwm_stop
void dcmotor5_pwm_stop(dcmotor5_t *ctx)
DC Motor 5 stop PWM module.
dcmotor5_t::pwm
pwm_t pwm
Definition: dcmotor5.h:116
dcmotor5_enable
void dcmotor5_enable(dcmotor5_t *ctx)
DC Motor 5 start PWM module.
dcmotor5_t::in2
digital_out_t in2
Definition: dcmotor5.h:109
dcmotor5_get_sense_comparator
uint8_t dcmotor5_get_sense_comparator(dcmotor5_t *ctx)
DC Motor 5 get sense comparator.
dcmotor5_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor5.h:130
dcmotor5_cfg_t::in2
pin_name_t in2
Definition: dcmotor5.h:136
DCMOTOR5_ERROR
@ DCMOTOR5_ERROR
Definition: dcmotor5.h:150