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 
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 #include "drv_analog_in.h"
53 
74 #define DCMOTOR18_DEF_FREQ 5000
75  // dcmotor18_cfg
77 
92 #define DCMOTOR18_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
94  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
95  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
96  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
97  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
98  // dcmotor18_map // dcmotor18
101 
111 typedef struct
112 {
113  // Output pins
114  digital_out_t pw2;
115  digital_out_t en;
117  // Input pins
118  digital_in_t int_pin;
120  // Modules
121  pwm_t pwm;
122  analog_in_t adc;
124  // ctx variable
125  uint32_t pwm_freq;
126  uint8_t direction;
128 } dcmotor18_t;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t pwm;
138  pin_name_t an;
140  // Additional gpio pins
141  pin_name_t pw2;
142  pin_name_t en;
143  pin_name_t int_pin;
145  // Static variable
146  uint32_t dev_pwm_freq;
147  analog_in_resolution_t resolution;
148  float vref;
151 
156 typedef enum
157 {
159  DCMOTOR18_ERROR = -1
160 
162 
179 
194 
209 
221 err_t dcmotor18_set_duty_cycle ( dcmotor18_t *ctx, float duty_cycle );
222 
234 
246 
258 err_t dcmotor18_read_an_pin_value ( dcmotor18_t *ctx, uint16_t *data_out );
259 
274 err_t dcmotor18_read_an_pin_voltage ( dcmotor18_t *ctx, float *data_out );
275 
288 err_t dcmotor18_read_an_pin_current ( dcmotor18_t *ctx, float *data_out );
289 
298 void dcmotor18_set_direction ( dcmotor18_t *ctx, uint8_t state );
299 
308 void dcmotor18_set_enable ( dcmotor18_t *ctx, uint8_t state );
309 
318 
330 err_t dcmotor18_set_speed_percentage ( dcmotor18_t *ctx, float speed_percentage );
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 #endif // DCMOTOR18_H
336  // dcmotor18
338 
339 // ------------------------------------------------------------------------ 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:135
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:112
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:147
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:159
dcmotor18_t::pw2
digital_out_t pw2
Definition: dcmotor18.h:114
dcmotor18_cfg_t::an
pin_name_t an
Definition: dcmotor18.h:138
dcmotor18_t::adc
analog_in_t adc
Definition: dcmotor18.h:122
dcmotor18_cfg_t::en
pin_name_t en
Definition: dcmotor18.h:142
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:148
dcmotor18_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor18.h:137
dcmotor18_t::pwm
pwm_t pwm
Definition: dcmotor18.h:121
dcmotor18_t::direction
uint8_t direction
Definition: dcmotor18.h:126
dcmotor18_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor18.h:143
dcmotor18_t::int_pin
digital_in_t int_pin
Definition: dcmotor18.h:118
dcmotor18_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor18.h:146
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:157
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:125
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:115
dcmotor18_cfg_t::pw2
pin_name_t pw2
Definition: dcmotor18.h:141
DCMOTOR18_OK
@ DCMOTOR18_OK
Definition: dcmotor18.h:158
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.