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 
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  // 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  // dcmotor9_map // dcmotor9
117 
122 typedef 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 
142 typedef 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 
164 typedef enum
165 {
167  DCMOTOR9_ERROR = -1
168 
170 
187 
202 
217 
229 err_t dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
230 
242 
254 
263 
272 
282 
292 
302 
310 void dcmotor9_stop ( dcmotor9_t *ctx );
311 
323 err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
324 
336 err_t dcmotor9_read_an_voltage ( dcmotor9_t *ctx, float *data_out );
337 
338 #ifdef __cplusplus
339 }
340 #endif
341 #endif // DCMOTOR9_H
342  // dcmotor9
344 
345 // ------------------------------------------------------------------------ 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:129
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:145
dcmotor9_cfg_t::pw1
pin_name_t pw1
Definition: dcmotor9.h:150
dcmotor9_cfg_t::an
pin_name_t an
Definition: dcmotor9.h:148
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:166
dcmotor9_cfg_t::vref
float vref
Definition: dcmotor9.h:156
dcmotor9_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor9.h:134
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:165
dcmotor9_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor9.h:154
dcmotor9_t::shd
digital_out_t shd
Definition: dcmotor9.h:125
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:131
dcmotor9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: dcmotor9.h:155
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:123
dcmotor9_t::pw2
digital_out_t pw2
Definition: dcmotor9.h:126
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:143
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:151
dcmotor9_standby
void dcmotor9_standby(dcmotor9_t *ctx)
DC Motor 9 Disable the engine function.
DCMOTOR9_ERROR
@ DCMOTOR9_ERROR
Definition: dcmotor9.h:167
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:149