dcmotor  2.0.0.0
dcmotor.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DCMOTOR_H
36 #define DCMOTOR_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 DCMOTOR_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg. slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55  cfg. sl1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg. sl2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg. flt = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define DCMOTOR_RETVAL uint8_t
65 
66 #define DCMOTOR_OK 0x00
67 #define DCMOTOR_INIT_ERROR 0xFF
68 
74 #define DCMOTOR_DEF_FREQ 20000
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89 
90  // Output pins
91 
92  digital_out_t slp;
93  digital_out_t sl1;
94  digital_out_t sl2;
95 
96  // Input pins
97 
98  digital_in_t flt;
99 
100  // Modules
101 
102  pwm_t pwm;
103 
104  // ctx variable
105 
106  uint16_t pwm_period;
107  hal_tim_frequency_t pwm_freq;
108 
109 } dcmotor_t;
110 
114 typedef struct
115 {
116  // Communication gpio pins
117 
118  pin_name_t pwm;
119 
120  // Additional gpio pins
121 
122  pin_name_t slp;
123  pin_name_t sl1;
124  pin_name_t sl2;
125  pin_name_t flt;
126 
127  // static variable
128 
129  hal_base_addr_t dev_pwm_base;
130  hal_tim_channel_t dev_pwm_channel;
131  hal_tim_output_polarity_t dev_pwm_polarity;
132  hal_tim_frequency_t dev_pwm_freq;
133 
134 } dcmotor_cfg_t;
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
156 void dcmotor_cfg_setup ( dcmotor_cfg_t *cfg );
157 
166 
176 void dcmotor_set_duty_cycle ( dcmotor_t *ctx, pwm_data_t duty_cycle );
177 
185 void dcmotor_pwm_stop ( dcmotor_t *ctx );
186 
194 void dcmotor_pwm_start ( dcmotor_t *ctx );
195 
203  void dcmotor_enable ( dcmotor_t *ctx );
204 
212  void dcmotor_sleep_mode ( dcmotor_t *ctx );
213 
222 
231 
240 
249 
257  uint8_t dcmotor_get_diagnostic ( dcmotor_t *ctx );
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif // _DCMOTOR_H_
263  // End public_function group
266 
267 // ------------------------------------------------------------------------- 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_cfg_t::dev_pwm_base
hal_base_addr_t dev_pwm_base
Definition: dcmotor.h:129
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::dev_pwm_channel
hal_tim_channel_t dev_pwm_channel
Definition: dcmotor.h:130
dcmotor_cfg_t
Click configuration structure definition.
Definition: dcmotor.h:114
dcmotor_pwm_stop
void dcmotor_pwm_stop(dcmotor_t *ctx)
Stop PWM module.
dcmotor_t::pwm_period
uint16_t pwm_period
Definition: dcmotor.h:106
dcmotor_enable
void dcmotor_enable(dcmotor_t *ctx)
Enable the motor function.
dcmotor_t::flt
digital_in_t flt
Definition: dcmotor.h:98
dcmotor_cfg_t::flt
pin_name_t flt
Definition: dcmotor.h:125
dcmotor_cfg_t::sl1
pin_name_t sl1
Definition: dcmotor.h:123
dcmotor_cfg_t::sl2
pin_name_t sl2
Definition: dcmotor.h:124
dcmotor_t::slp
digital_out_t slp
Definition: dcmotor.h:92
dcmotor_t::sl1
digital_out_t sl1
Definition: dcmotor.h:93
dcmotor_set_duty_cycle
void dcmotor_set_duty_cycle(dcmotor_t *ctx, pwm_data_t duty_cycle)
Generic sets PWM duty cycle.
dcmotor_cfg_t::dev_pwm_freq
hal_tim_frequency_t dev_pwm_freq
Definition: dcmotor.h:132
dcmotor_t::sl2
digital_out_t sl2
Definition: dcmotor.h:94
dcmotor_t::pwm_freq
hal_tim_frequency_t pwm_freq
Definition: dcmotor.h:107
dcmotor_t::pwm
pwm_t pwm
Definition: dcmotor.h:102
dcmotor_t
Click ctx object definition.
Definition: dcmotor.h:87
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:122
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:118
dcmotor_cfg_t::dev_pwm_polarity
hal_tim_output_polarity_t dev_pwm_polarity
Definition: dcmotor.h:131
DCMOTOR_RETVAL
#define DCMOTOR_RETVAL
Definition: dcmotor.h:64