dcmotor9 2.0.0.0
dcmotor9.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 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 DCMOTOR9_H
29#define DCMOTOR9_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 DCMOTOR9_DEF_FREQ 20000
75#define DCMOTOR9_DEF_VREF 3.3
76
81#define DCMOTOR9_PWM_DUTY_PERCENT_0 0.0
82#define DCMOTOR9_PWM_DUTY_PERCENT_10 0.1
83#define DCMOTOR9_PWM_DUTY_PERCENT_20 0.2
84#define DCMOTOR9_PWM_DUTY_PERCENT_30 0.3
85#define DCMOTOR9_PWM_DUTY_PERCENT_40 0.4
86#define DCMOTOR9_PWM_DUTY_PERCENT_50 0.5
87#define DCMOTOR9_PWM_DUTY_PERCENT_60 0.6
88#define DCMOTOR9_PWM_DUTY_PERCENT_70 0.7
89#define DCMOTOR9_PWM_DUTY_PERCENT_80 0.8
90#define DCMOTOR9_PWM_DUTY_PERCENT_90 0.9
91#define DCMOTOR9_PWM_DUTY_PERCENT_100 1.0
92
93 // dcmotor9_cfg
94
109#define DCMOTOR9_MAP_MIKROBUS( cfg, mikrobus ) \
110 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
111 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
112 cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
113 cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_CS )
114
115 // dcmotor9_map
116 // dcmotor9
117
122typedef struct
123{
124 // Output pins
125 digital_out_t shd;
126 digital_out_t pw2;
128 // Modules
129 pwm_t pwm;
131 analog_in_t adc;
133 // ctx variable
134 uint32_t pwm_freq;
136} dcmotor9_t;
137
142typedef struct
143{
144 // Communication gpio pins
145 pin_name_t pwm;
147 // Additional gpio pins
148 pin_name_t an;
149 pin_name_t shd;
150 pin_name_t pw1;
151 pin_name_t pw2;
153 // Static variable
154 uint32_t dev_pwm_freq;
155 analog_in_resolution_t resolution;
156 float vref;
159
164typedef enum
165{
167 DCMOTOR9_ERROR = -1
168
170
187
202
217
229err_t dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
230
242
254
263
272
282
292
302
311
323err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
324
336err_t dcmotor9_read_an_voltage ( dcmotor9_t *ctx, float *data_out );
337
338#ifdef __cplusplus
339}
340#endif
341#endif // DCMOTOR9_H
342
343 // dcmotor9
344
345// ------------------------------------------------------------------------ END
dcmotor9_return_value_t
DC Motor 9 Click return value data.
Definition dcmotor9.h:165
@ DCMOTOR9_OK
Definition dcmotor9.h:166
@ DCMOTOR9_ERROR
Definition dcmotor9.h:167
void dcmotor9_counter_clockwise(dcmotor9_t *ctx)
DC Motor 9 Set the counter clockwise direction of rotation function.
void dcmotor9_clockwise(dcmotor9_t *ctx)
DC Motor 9 Set the clockwise direction of rotation function.
err_t dcmotor9_pwm_start(dcmotor9_t *ctx)
DC Motor 9 start PWM module.
err_t dcmotor9_read_an_voltage(dcmotor9_t *ctx, float *data_out)
DC Motor 9 AN Voltage Read function.
err_t dcmotor9_default_cfg(dcmotor9_t *ctx)
DC Motor 9 default configuration function.
void dcmotor9_enable(dcmotor9_t *ctx)
DC Motor 9 Enable the engine function.
err_t dcmotor9_set_duty_cycle(dcmotor9_t *ctx, float duty_cycle)
DC Motor 9 sets PWM duty cycle.
err_t dcmotor9_read_an_value(dcmotor9_t *ctx, uint16_t *data_out)
DC Motor 9 AN Value Read function.
err_t dcmotor9_init(dcmotor9_t *ctx, dcmotor9_cfg_t *cfg)
DC Motor 9 initialization function.
void dcmotor9_short_brake(dcmotor9_t *ctx)
DC Motor 9 Brake the engine function.
void dcmotor9_standby(dcmotor9_t *ctx)
DC Motor 9 Disable the engine function.
void dcmotor9_cfg_setup(dcmotor9_cfg_t *cfg)
DC Motor 9 configuration object setup function.
err_t dcmotor9_pwm_stop(dcmotor9_t *ctx)
DC Motor 9 stop PWM module.
void dcmotor9_stop(dcmotor9_t *ctx)
DC Motor 9 Stop the engine function.
DC Motor 9 Click configuration object.
Definition dcmotor9.h:143
analog_in_resolution_t resolution
Definition dcmotor9.h:155
float vref
Definition dcmotor9.h:156
pin_name_t pw2
Definition dcmotor9.h:151
uint32_t dev_pwm_freq
Definition dcmotor9.h:154
pin_name_t shd
Definition dcmotor9.h:149
pin_name_t pwm
Definition dcmotor9.h:145
pin_name_t pw1
Definition dcmotor9.h:150
pin_name_t an
Definition dcmotor9.h:148
DC Motor 9 Click context object.
Definition dcmotor9.h:123
uint32_t pwm_freq
Definition dcmotor9.h:134
digital_out_t pw2
Definition dcmotor9.h:126
analog_in_t adc
Definition dcmotor9.h:131
pwm_t pwm
Definition dcmotor9.h:129
digital_out_t shd
Definition dcmotor9.h:125