dcmotor5  2.0.0.0
dcmotor5.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 DCMOTOR5_H
36 #define DCMOTOR5_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 DCMOTOR5_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.snso = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55  cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.fault = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define DCMOTOR5_RETVAL uint8_t
65 
66 #define DCMOTOR5_OK 0x00
67 #define DCMOTOR5_INIT_ERROR 0xFF
68 
74 #define DCMOTOR5_DEF_FREQ 20000
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t sleep;
92  digital_out_t in2;
93 
94  // Input pins
95 
96  digital_in_t snso;
97  digital_in_t fault;
98 
99  // Modules
100 
101  pwm_t pwm;
102 
103  // ctx variable
104 
105  uint32_t pwm_freq;
106 } dcmotor5_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t pwm;
116 
117  // Additional gpio pins
118 
119  pin_name_t snso;
120  pin_name_t sleep;
121  pin_name_t fault;
122  pin_name_t in2;
123 
124  // static variable
125 
126  uint32_t dev_pwm_freq;
127 
129  // End types group
131 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132 
138 #ifdef __cplusplus
139 extern "C"{
140 #endif
141 
151 
160 
170 void dcmotor5_set_duty_cycle ( dcmotor5_t *ctx, float duty_cycle );
171 
180 
189 
198 
207 
217 
227 
236 
244 void dcmotor5_stop ( dcmotor5_t *ctx );
245 
260 
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // _DCMOTOR5_H_
280  // End public_function group
283 
284 // ------------------------------------------------------------------------- END
dcmotor5_t::fault
digital_in_t fault
Definition: dcmotor5.h:97
dcmotor5_cfg_t::snso
pin_name_t snso
Definition: dcmotor5.h:119
DCMOTOR5_RETVAL
#define DCMOTOR5_RETVAL
Definition: dcmotor5.h:64
dcmotor5_cfg_t::sleep
pin_name_t sleep
Definition: dcmotor5.h:120
dcmotor5_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor5.h:105
dcmotor5_short_brake
void dcmotor5_short_brake(dcmotor5_t *ctx)
Brake the engine function.
dcmotor5_standby
void dcmotor5_standby(dcmotor5_t *ctx)
Disable the engine function.
dcmotor5_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor5.h:126
dcmotor5_cfg_t::fault
pin_name_t fault
Definition: dcmotor5.h:121
dcmotor5_init
DCMOTOR5_RETVAL dcmotor5_init(dcmotor5_t *ctx, dcmotor5_cfg_t *cfg)
Initialization function.
dcmotor5_pwm_start
void dcmotor5_pwm_start(dcmotor5_t *ctx)
Start PWM module.
dcmotor5_get_fault_conditions
uint8_t dcmotor5_get_fault_conditions(dcmotor5_t *ctx)
Get fault conditions state function.
dcmotor5_t::snso
digital_in_t snso
Definition: dcmotor5.h:96
dcmotor5_enable
void dcmotor5_enable(dcmotor5_t *ctx)
Enable the engine function.
dcmotor5_t
Click ctx object definition.
Definition: dcmotor5.h:88
dcmotor5_t::sleep
digital_out_t sleep
Definition: dcmotor5.h:91
dcmotor5_clockwise
void dcmotor5_clockwise(dcmotor5_t *ctx)
Set the direction of rotation in the clockwise direction function.
dcmotor5_stop
void dcmotor5_stop(dcmotor5_t *ctx)
Stop the engine function.
dcmotor5_set_duty_cycle
void dcmotor5_set_duty_cycle(dcmotor5_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor5_get_sense_comparator
uint8_t dcmotor5_get_sense_comparator(dcmotor5_t *ctx)
Get sense comparator state function.
dcmotor5_cfg_t
Click configuration structure definition.
Definition: dcmotor5.h:112
dcmotor5_t::pwm
pwm_t pwm
Definition: dcmotor5.h:101
dcmotor5_t::in2
digital_out_t in2
Definition: dcmotor5.h:92
dcmotor5_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor5.h:115
dcmotor5_pwm_stop
void dcmotor5_pwm_stop(dcmotor5_t *ctx)
Stop PWM module.
dcmotor5_cfg_t::in2
pin_name_t in2
Definition: dcmotor5.h:122
dcmotor5_counter_clockwise
void dcmotor5_counter_clockwise(dcmotor5_t *ctx)
Set the direction of rotation in the counter clockwise direction function.
dcmotor5_cfg_setup
void dcmotor5_cfg_setup(dcmotor5_cfg_t *cfg)
Config Object Initialization function.