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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_pwm.h"
38 #include "drv_analog_in.h"
39 
60 #define DCMOTOR9_DEF_FREQ 20000
61 #define DCMOTOR9_DEF_VREF 3.3
62 
67 #define DCMOTOR9_PWM_DUTY_PERCENT_0 0.0
68 #define DCMOTOR9_PWM_DUTY_PERCENT_10 0.1
69 #define DCMOTOR9_PWM_DUTY_PERCENT_20 0.2
70 #define DCMOTOR9_PWM_DUTY_PERCENT_30 0.3
71 #define DCMOTOR9_PWM_DUTY_PERCENT_40 0.4
72 #define DCMOTOR9_PWM_DUTY_PERCENT_50 0.5
73 #define DCMOTOR9_PWM_DUTY_PERCENT_60 0.6
74 #define DCMOTOR9_PWM_DUTY_PERCENT_70 0.7
75 #define DCMOTOR9_PWM_DUTY_PERCENT_80 0.8
76 #define DCMOTOR9_PWM_DUTY_PERCENT_90 0.9
77 #define DCMOTOR9_PWM_DUTY_PERCENT_100 1.0
78  // dcmotor9_cfg
80 
95 #define DCMOTOR9_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
97  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
98  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
99  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_CS )
100  // dcmotor9_map // dcmotor9
103 
108 typedef struct
109 {
110  // Output pins
111  digital_out_t shd;
112  digital_out_t pw2;
114  // Modules
115  pwm_t pwm;
117  analog_in_t adc;
119  // ctx variable
120  uint32_t pwm_freq;
122 } dcmotor9_t;
123 
128 typedef struct
129 {
130  // Communication gpio pins
131  pin_name_t pwm;
133  // Additional gpio pins
134  pin_name_t an;
135  pin_name_t shd;
136  pin_name_t pw1;
137  pin_name_t pw2;
139  // Static variable
140  uint32_t dev_pwm_freq;
141  analog_in_resolution_t resolution;
142  float vref;
145 
150 typedef enum
151 {
153  DCMOTOR9_ERROR = -1
154 
156 
173 
188 
203 
215 err_t dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
216 
228 
240 
249 
258 
268 
278 
288 
296 void dcmotor9_stop ( dcmotor9_t *ctx );
297 
309 err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
310 
322 err_t dcmotor9_read_an_voltage ( dcmotor9_t *ctx, float *data_out );
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 #endif // DCMOTOR9_H
328  // dcmotor9
330 
331 // ------------------------------------------------------------------------ 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:115
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:131
dcmotor9_cfg_t::pw1
pin_name_t pw1
Definition: dcmotor9.h:136
dcmotor9_cfg_t::an
pin_name_t an
Definition: dcmotor9.h:134
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:152
dcmotor9_cfg_t::vref
float vref
Definition: dcmotor9.h:142
dcmotor9_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor9.h:120
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:151
dcmotor9_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor9.h:140
dcmotor9_t::shd
digital_out_t shd
Definition: dcmotor9.h:111
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:117
dcmotor9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: dcmotor9.h:141
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:109
dcmotor9_t::pw2
digital_out_t pw2
Definition: dcmotor9.h:112
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:129
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:137
dcmotor9_standby
void dcmotor9_standby(dcmotor9_t *ctx)
DC Motor 9 Disable the engine function.
DCMOTOR9_ERROR
@ DCMOTOR9_ERROR
Definition: dcmotor9.h:153
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:135