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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_pwm.h"
38 #include "drv_analog_in.h"
39 
60 #define DCMOTOR18_DEF_FREQ 5000
61  // dcmotor18_cfg
63 
78 #define DCMOTOR18_MAP_MIKROBUS( cfg, mikrobus ) \
79  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
80  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
81  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
82  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
83  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
84  // dcmotor18_map // dcmotor18
87 
97 typedef struct
98 {
99  // Output pins
100  digital_out_t pw2;
101  digital_out_t en;
103  // Input pins
104  digital_in_t int_pin;
106  // Modules
107  pwm_t pwm;
108  analog_in_t adc;
110  // ctx variable
111  uint32_t pwm_freq;
112  uint8_t direction;
114 } dcmotor18_t;
115 
120 typedef struct
121 {
122  // Communication gpio pins
123  pin_name_t pwm;
124  pin_name_t an;
126  // Additional gpio pins
127  pin_name_t pw2;
128  pin_name_t en;
129  pin_name_t int_pin;
131  // Static variable
132  uint32_t dev_pwm_freq;
133  analog_in_resolution_t resolution;
134  float vref;
137 
142 typedef enum
143 {
145  DCMOTOR18_ERROR = -1
146 
148 
165 
180 
195 
207 err_t dcmotor18_set_duty_cycle ( dcmotor18_t *ctx, float duty_cycle );
208 
220 
232 
244 err_t dcmotor18_read_an_pin_value ( dcmotor18_t *ctx, uint16_t *data_out );
245 
260 err_t dcmotor18_read_an_pin_voltage ( dcmotor18_t *ctx, float *data_out );
261 
274 err_t dcmotor18_read_an_pin_current ( dcmotor18_t *ctx, float *data_out );
275 
284 void dcmotor18_set_direction ( dcmotor18_t *ctx, uint8_t state );
285 
294 void dcmotor18_set_enable ( dcmotor18_t *ctx, uint8_t state );
295 
304 
316 err_t dcmotor18_set_speed_percentage ( dcmotor18_t *ctx, float speed_percentage );
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // DCMOTOR18_H
322  // dcmotor18
324 
325 // ------------------------------------------------------------------------ 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:121
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:98
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:133
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:145
dcmotor18_t::pw2
digital_out_t pw2
Definition: dcmotor18.h:100
dcmotor18_cfg_t::an
pin_name_t an
Definition: dcmotor18.h:124
dcmotor18_t::adc
analog_in_t adc
Definition: dcmotor18.h:108
dcmotor18_cfg_t::en
pin_name_t en
Definition: dcmotor18.h:128
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:134
dcmotor18_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor18.h:123
dcmotor18_t::pwm
pwm_t pwm
Definition: dcmotor18.h:107
dcmotor18_t::direction
uint8_t direction
Definition: dcmotor18.h:112
dcmotor18_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor18.h:129
dcmotor18_t::int_pin
digital_in_t int_pin
Definition: dcmotor18.h:104
dcmotor18_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor18.h:132
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:143
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:111
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:101
dcmotor18_cfg_t::pw2
pin_name_t pw2
Definition: dcmotor18.h:127
DCMOTOR18_OK
@ DCMOTOR18_OK
Definition: dcmotor18.h:144
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.