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
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 DCMOTOR9_DEF_FREQ 20000
71 #define DCMOTOR9_DEF_VREF 3.3
72 
77 #define DCMOTOR9_PWM_DUTY_PERCENT_0 0.0
78 #define DCMOTOR9_PWM_DUTY_PERCENT_10 0.1
79 #define DCMOTOR9_PWM_DUTY_PERCENT_20 0.2
80 #define DCMOTOR9_PWM_DUTY_PERCENT_30 0.3
81 #define DCMOTOR9_PWM_DUTY_PERCENT_40 0.4
82 #define DCMOTOR9_PWM_DUTY_PERCENT_50 0.5
83 #define DCMOTOR9_PWM_DUTY_PERCENT_60 0.6
84 #define DCMOTOR9_PWM_DUTY_PERCENT_70 0.7
85 #define DCMOTOR9_PWM_DUTY_PERCENT_80 0.8
86 #define DCMOTOR9_PWM_DUTY_PERCENT_90 0.9
87 #define DCMOTOR9_PWM_DUTY_PERCENT_100 1.0
88  // dcmotor9_cfg
90 
105 #define DCMOTOR9_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
107  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_CS )
110  // dcmotor9_map // dcmotor9
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t shd;
122  digital_out_t pw2;
124  // Modules
125  pwm_t pwm;
127  analog_in_t adc;
129  // ctx variable
130  uint32_t pwm_freq;
132 } dcmotor9_t;
133 
138 typedef struct
139 {
140  // Communication gpio pins
141  pin_name_t pwm;
143  // Additional gpio pins
144  pin_name_t an;
145  pin_name_t shd;
146  pin_name_t pw1;
147  pin_name_t pw2;
149  // Static variable
150  uint32_t dev_pwm_freq;
151  analog_in_resolution_t resolution;
152  float vref;
155 
160 typedef enum
161 {
163  DCMOTOR9_ERROR = -1
164 
166 
183 
198 
213 
225 err_t dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
226 
238 
250 
259 
268 
278 
288 
298 
306 void dcmotor9_stop ( dcmotor9_t *ctx );
307 
319 err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
320 
332 err_t dcmotor9_read_an_voltage ( dcmotor9_t *ctx, float *data_out );
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 #endif // DCMOTOR9_H
338  // dcmotor9
340 
341 // ------------------------------------------------------------------------ END
dcmotor9_cfg_setup
void dcmotor9_cfg_setup(dcmotor9_cfg_t *cfg)
DC Motor 9 configuration object setup function.
dcmotor9_t::pwm
pwm_t pwm
Definition: dcmotor9.h:125
dcmotor9_stop
void dcmotor9_stop(dcmotor9_t *ctx)
DC Motor 9 Stop the engine function.
dcmotor9_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor9.h:141
dcmotor9_cfg_t::pw1
pin_name_t pw1
Definition: dcmotor9.h:146
dcmotor9_cfg_t::an
pin_name_t an
Definition: dcmotor9.h:144
dcmotor9_read_an_voltage
err_t dcmotor9_read_an_voltage(dcmotor9_t *ctx, float *data_out)
DC Motor 9 AN Voltage Read function.
dcmotor9_default_cfg
err_t dcmotor9_default_cfg(dcmotor9_t *ctx)
DC Motor 9 default configuration function.
DCMOTOR9_OK
@ DCMOTOR9_OK
Definition: dcmotor9.h:162
dcmotor9_cfg_t::vref
float vref
Definition: dcmotor9.h:152
dcmotor9_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor9.h:130
dcmotor9_short_brake
void dcmotor9_short_brake(dcmotor9_t *ctx)
DC Motor 9 Brake the engine function.
dcmotor9_set_duty_cycle
err_t dcmotor9_set_duty_cycle(dcmotor9_t *ctx, float duty_cycle)
DC Motor 9 sets PWM duty cycle.
dcmotor9_enable
void dcmotor9_enable(dcmotor9_t *ctx)
DC Motor 9 Enable the engine function.
dcmotor9_return_value_t
dcmotor9_return_value_t
DC Motor 9 Click return value data.
Definition: dcmotor9.h:161
dcmotor9_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor9.h:150
dcmotor9_t::shd
digital_out_t shd
Definition: dcmotor9.h:121
dcmotor9_pwm_stop
err_t dcmotor9_pwm_stop(dcmotor9_t *ctx)
DC Motor 9 stop PWM module.
dcmotor9_clockwise
void dcmotor9_clockwise(dcmotor9_t *ctx)
DC Motor 9 Set the clockwise direction of rotation function.
dcmotor9_t::adc
analog_in_t adc
Definition: dcmotor9.h:127
dcmotor9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: dcmotor9.h:151
dcmotor9_pwm_start
err_t dcmotor9_pwm_start(dcmotor9_t *ctx)
DC Motor 9 start PWM module.
dcmotor9_t
DC Motor 9 Click context object.
Definition: dcmotor9.h:119
dcmotor9_t::pw2
digital_out_t pw2
Definition: dcmotor9.h:122
dcmotor9_read_an_value
err_t dcmotor9_read_an_value(dcmotor9_t *ctx, uint16_t *data_out)
DC Motor 9 AN Value Read function.
dcmotor9_cfg_t
DC Motor 9 Click configuration object.
Definition: dcmotor9.h:139
dcmotor9_init
err_t dcmotor9_init(dcmotor9_t *ctx, dcmotor9_cfg_t *cfg)
DC Motor 9 initialization function.
dcmotor9_cfg_t::pw2
pin_name_t pw2
Definition: dcmotor9.h:147
dcmotor9_standby
void dcmotor9_standby(dcmotor9_t *ctx)
DC Motor 9 Disable the engine function.
DCMOTOR9_ERROR
@ DCMOTOR9_ERROR
Definition: dcmotor9.h:163
dcmotor9_counter_clockwise
void dcmotor9_counter_clockwise(dcmotor9_t *ctx)
DC Motor 9 Set the counter clockwise direction of rotation function.
dcmotor9_cfg_t::shd
pin_name_t shd
Definition: dcmotor9.h:145