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
32extern "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
76 // 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
99 // dcmotor18_map
100 // dcmotor18
101
111typedef 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;
129
134typedef 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
162
179
194
209
221err_t dcmotor18_set_duty_cycle ( dcmotor18_t *ctx, float duty_cycle );
222
234
246
258err_t dcmotor18_read_an_pin_value ( dcmotor18_t *ctx, uint16_t *data_out );
259
274err_t dcmotor18_read_an_pin_voltage ( dcmotor18_t *ctx, float *data_out );
275
288err_t dcmotor18_read_an_pin_current ( dcmotor18_t *ctx, float *data_out );
289
298void dcmotor18_set_direction ( dcmotor18_t *ctx, uint8_t state );
299
308void dcmotor18_set_enable ( dcmotor18_t *ctx, uint8_t state );
309
318
330err_t dcmotor18_set_speed_percentage ( dcmotor18_t *ctx, float speed_percentage );
331
332#ifdef __cplusplus
333}
334#endif
335#endif // DCMOTOR18_H
336
337 // dcmotor18
338
339// ------------------------------------------------------------------------ END
dcmotor18_return_value_t
DC Motor 18 Click return value data.
Definition dcmotor18.h:157
@ DCMOTOR18_ERROR
Definition dcmotor18.h:159
@ DCMOTOR18_OK
Definition dcmotor18.h:158
err_t dcmotor18_set_speed_percentage(dcmotor18_t *ctx, float speed_percentage)
Set speed output percentage.
err_t dcmotor18_read_an_pin_voltage(dcmotor18_t *ctx, float *data_out)
DC Motor 18 read AN pin voltage level function.
void dcmotor18_set_direction(dcmotor18_t *ctx, uint8_t state)
Set diretion of motor rotation.
err_t dcmotor18_pwm_start(dcmotor18_t *ctx)
DC Motor 18 start PWM module.
err_t dcmotor18_read_an_pin_value(dcmotor18_t *ctx, uint16_t *data_out)
DC Motor 18 read AN pin value function.
err_t dcmotor18_default_cfg(dcmotor18_t *ctx)
DC Motor 18 default configuration function.
err_t dcmotor18_set_duty_cycle(dcmotor18_t *ctx, float duty_cycle)
Sets PWM duty cycle.
err_t dcmotor18_read_an_pin_current(dcmotor18_t *ctx, float *data_out)
Read AN pin current.
void dcmotor18_set_enable(dcmotor18_t *ctx, uint8_t state)
Set enable pin state.
void dcmotor18_cfg_setup(dcmotor18_cfg_t *cfg)
DC Motor 18 configuration object setup function.
uint8_t dcmotor18_get_interrupt(dcmotor18_t *ctx)
Get interrupt pin state.
err_t dcmotor18_init(dcmotor18_t *ctx, dcmotor18_cfg_t *cfg)
DC Motor 18 initialization function.
err_t dcmotor18_pwm_stop(dcmotor18_t *ctx)
DC Motor 18 stop PWM module.
DC Motor 18 Click configuration object.
Definition dcmotor18.h:135
analog_in_resolution_t resolution
Definition dcmotor18.h:147
float vref
Definition dcmotor18.h:148
pin_name_t pw2
Definition dcmotor18.h:141
uint32_t dev_pwm_freq
Definition dcmotor18.h:146
pin_name_t en
Definition dcmotor18.h:142
pin_name_t int_pin
Definition dcmotor18.h:143
pin_name_t pwm
Definition dcmotor18.h:137
pin_name_t an
Definition dcmotor18.h:138
DC Motor 18 Click driver selector.
Definition dcmotor18.h:112
uint32_t pwm_freq
Definition dcmotor18.h:125
digital_out_t pw2
Definition dcmotor18.h:114
digital_in_t int_pin
Definition dcmotor18.h:118
digital_out_t en
Definition dcmotor18.h:115
uint8_t direction
Definition dcmotor18.h:126
analog_in_t adc
Definition dcmotor18.h:122
pwm_t pwm
Definition dcmotor18.h:121