dcmotor18  2.0.0.0
dcmotor18.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 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 DCMOTOR18_H
29 #define DCMOTOR18_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_pwm.h"
48 #include "drv_analog_in.h"
49 
70 #define DCMOTOR18_DEF_FREQ 5000
71  // dcmotor18_cfg
73 
88 #define DCMOTOR18_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
90  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
91  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
92  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
93  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
94  // dcmotor18_map // dcmotor18
97 
107 typedef struct
108 {
109  // Output pins
110  digital_out_t pw2;
111  digital_out_t en;
113  // Input pins
114  digital_in_t int_pin;
116  // Modules
117  pwm_t pwm;
118  analog_in_t adc;
120  // ctx variable
121  uint32_t pwm_freq;
122  uint8_t direction;
124 } dcmotor18_t;
125 
130 typedef struct
131 {
132  // Communication gpio pins
133  pin_name_t pwm;
134  pin_name_t an;
136  // Additional gpio pins
137  pin_name_t pw2;
138  pin_name_t en;
139  pin_name_t int_pin;
141  // Static variable
142  uint32_t dev_pwm_freq;
143  analog_in_resolution_t resolution;
144  float vref;
147 
152 typedef enum
153 {
155  DCMOTOR18_ERROR = -1
156 
158 
175 
190 
205 
217 err_t dcmotor18_set_duty_cycle ( dcmotor18_t *ctx, float duty_cycle );
218 
230 
242 
254 err_t dcmotor18_read_an_pin_value ( dcmotor18_t *ctx, uint16_t *data_out );
255 
270 err_t dcmotor18_read_an_pin_voltage ( dcmotor18_t *ctx, float *data_out );
271 
284 err_t dcmotor18_read_an_pin_current ( dcmotor18_t *ctx, float *data_out );
285 
294 void dcmotor18_set_direction ( dcmotor18_t *ctx, uint8_t state );
295 
304 void dcmotor18_set_enable ( dcmotor18_t *ctx, uint8_t state );
305 
314 
326 err_t dcmotor18_set_speed_percentage ( dcmotor18_t *ctx, float speed_percentage );
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif // DCMOTOR18_H
332  // dcmotor18
334 
335 // ------------------------------------------------------------------------ END
dcmotor18_pwm_start
err_t dcmotor18_pwm_start(dcmotor18_t *ctx)
DC Motor 18 start PWM module.
dcmotor18_cfg_t
DC Motor 18 Click configuration object.
Definition: dcmotor18.h:131
dcmotor18_read_an_pin_value
err_t dcmotor18_read_an_pin_value(dcmotor18_t *ctx, uint16_t *data_out)
DC Motor 18 read AN pin value function.
dcmotor18_cfg_setup
void dcmotor18_cfg_setup(dcmotor18_cfg_t *cfg)
DC Motor 18 configuration object setup function.
dcmotor18_t
DC Motor 18 Click driver selector.
Definition: dcmotor18.h:108
dcmotor18_set_duty_cycle
err_t dcmotor18_set_duty_cycle(dcmotor18_t *ctx, float duty_cycle)
Sets PWM duty cycle.
dcmotor18_read_an_pin_current
err_t dcmotor18_read_an_pin_current(dcmotor18_t *ctx, float *data_out)
Read AN pin current.
dcmotor18_cfg_t::resolution
analog_in_resolution_t resolution
Definition: dcmotor18.h:143
dcmotor18_init
err_t dcmotor18_init(dcmotor18_t *ctx, dcmotor18_cfg_t *cfg)
DC Motor 18 initialization function.
DCMOTOR18_ERROR
@ DCMOTOR18_ERROR
Definition: dcmotor18.h:155
dcmotor18_t::pw2
digital_out_t pw2
Definition: dcmotor18.h:110
dcmotor18_cfg_t::an
pin_name_t an
Definition: dcmotor18.h:134
dcmotor18_t::adc
analog_in_t adc
Definition: dcmotor18.h:118
dcmotor18_cfg_t::en
pin_name_t en
Definition: dcmotor18.h:138
dcmotor18_set_enable
void dcmotor18_set_enable(dcmotor18_t *ctx, uint8_t state)
Set enable pin state.
dcmotor18_default_cfg
err_t dcmotor18_default_cfg(dcmotor18_t *ctx)
DC Motor 18 default configuration function.
dcmotor18_cfg_t::vref
float vref
Definition: dcmotor18.h:144
dcmotor18_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor18.h:133
dcmotor18_t::pwm
pwm_t pwm
Definition: dcmotor18.h:117
dcmotor18_t::direction
uint8_t direction
Definition: dcmotor18.h:122
dcmotor18_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor18.h:139
dcmotor18_t::int_pin
digital_in_t int_pin
Definition: dcmotor18.h:114
dcmotor18_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor18.h:142
dcmotor18_get_interrupt
uint8_t dcmotor18_get_interrupt(dcmotor18_t *ctx)
Get interrupt pin state.
dcmotor18_return_value_t
dcmotor18_return_value_t
DC Motor 18 Click return value data.
Definition: dcmotor18.h:153
dcmotor18_pwm_stop
err_t dcmotor18_pwm_stop(dcmotor18_t *ctx)
DC Motor 18 stop PWM module.
dcmotor18_set_direction
void dcmotor18_set_direction(dcmotor18_t *ctx, uint8_t state)
Set diretion of motor rotation.
dcmotor18_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor18.h:121
dcmotor18_set_speed_percentage
err_t dcmotor18_set_speed_percentage(dcmotor18_t *ctx, float speed_percentage)
Set speed output percentage.
dcmotor18_t::en
digital_out_t en
Definition: dcmotor18.h:111
dcmotor18_cfg_t::pw2
pin_name_t pw2
Definition: dcmotor18.h:137
DCMOTOR18_OK
@ DCMOTOR18_OK
Definition: dcmotor18.h:154
dcmotor18_read_an_pin_voltage
err_t dcmotor18_read_an_pin_voltage(dcmotor18_t *ctx, float *data_out)
DC Motor 18 read AN pin voltage level function.