dcmotor9  2.0.0.0
dcmotor9.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DCMOTOR9_H
36 #define DCMOTOR9_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_pwm.h"
40 #include "drv_analog_in.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DCMOTOR9_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
54  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.pw1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
56  cfg.pw2 = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define DCMOTOR9_DEF_FREQ 20000
64 #define DCMOTOR9_DEF_VREF 3.3
65 
71 #define DCMOTOR9_PWM_DUTY_PERCENT_0 0.0
72 #define DCMOTOR9_PWM_DUTY_PERCENT_10 0.1
73 #define DCMOTOR9_PWM_DUTY_PERCENT_20 0.2
74 #define DCMOTOR9_PWM_DUTY_PERCENT_30 0.3
75 #define DCMOTOR9_PWM_DUTY_PERCENT_40 0.4
76 #define DCMOTOR9_PWM_DUTY_PERCENT_50 0.5
77 #define DCMOTOR9_PWM_DUTY_PERCENT_60 0.6
78 #define DCMOTOR9_PWM_DUTY_PERCENT_70 0.7
79 #define DCMOTOR9_PWM_DUTY_PERCENT_80 0.8
80 #define DCMOTOR9_PWM_DUTY_PERCENT_90 0.9
81 #define DCMOTOR9_PWM_DUTY_PERCENT_100 1.0
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Digital output pins.
97 
98  digital_out_t shd;
99  digital_out_t pw2;
100 
101  // Modules.
102 
103  pwm_t pwm;
104  analog_in_t adc;
105 
106 } dcmotor9_t;
107 
111 typedef struct
112 {
113  // Gpio pins.
114 
115  pin_name_t an;
116  pin_name_t shd;
117  pin_name_t pw1;
118  pin_name_t pw2;
120  // Static variables.
121 
122  uint32_t pwm_freq;
123  analog_in_resolution_t resolution;
124  float vref;
127  // End type group
129 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 void dcmotor9_cfg_setup ( dcmotor9_cfg_t *cfg );
149 
163 err_t dcmotor9_init ( dcmotor9_t *ctx, dcmotor9_cfg_t *cfg );
164 
174 void dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
175 
183 void dcmotor9_pwm_stop ( dcmotor9_t *ctx );
184 
192 void dcmotor9_pwm_start ( dcmotor9_t *ctx );
193 
201 void dcmotor9_enable ( dcmotor9_t *ctx );
202 
210 void dcmotor9_standby ( dcmotor9_t *ctx );
211 
221 
230 void dcmotor9_clockwise ( dcmotor9_t *ctx );
231 
239 void dcmotor9_short_brake ( dcmotor9_t *ctx );
240 
248 void dcmotor9_stop ( dcmotor9_t *ctx );
249 
262 err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
263 
277 err_t dcmotor9_read_an_voltage ( dcmotor9_t *ctx, float *data_out );
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif // DCMOTOR9_H
283  // End public_function group
286 
287 // ------------------------------------------------------------------------- END
dcmotor9_t::pwm
pwm_t pwm
Definition: dcmotor9.h:103
dcmotor9_cfg_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor9.h:122
dcmotor9_cfg_t::pw1
pin_name_t pw1
Definition: dcmotor9.h:117
dcmotor9_pwm_stop
void dcmotor9_pwm_stop(dcmotor9_t *ctx)
Stop PWM module.
dcmotor9_cfg_t::an
pin_name_t an
Definition: dcmotor9.h:115
dcmotor9_clockwise
void dcmotor9_clockwise(dcmotor9_t *ctx)
Set the clockwise direction of rotation function.
dcmotor9_enable
void dcmotor9_enable(dcmotor9_t *ctx)
Enable the engine function.
dcmotor9_cfg_t::vref
float vref
Definition: dcmotor9.h:124
dcmotor9_t::shd
digital_out_t shd
Definition: dcmotor9.h:98
dcmotor9_set_duty_cycle
void dcmotor9_set_duty_cycle(dcmotor9_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor9_t::adc
analog_in_t adc
Definition: dcmotor9.h:104
dcmotor9_cfg_setup
void dcmotor9_cfg_setup(dcmotor9_cfg_t *cfg)
Configuration Object Init Setup function.
dcmotor9_counter_clockwise
void dcmotor9_counter_clockwise(dcmotor9_t *ctx)
Set the counter clockwise direction of rotation function.
dcmotor9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: dcmotor9.h:123
dcmotor9_init
err_t dcmotor9_init(dcmotor9_t *ctx, dcmotor9_cfg_t *cfg)
Initialization function.
dcmotor9_read_an_value
err_t dcmotor9_read_an_value(dcmotor9_t *ctx, uint16_t *data_out)
AN Value Read function.
dcmotor9_t
Click ctx object definition.
Definition: dcmotor9.h:94
dcmotor9_t::pw2
digital_out_t pw2
Definition: dcmotor9.h:99
dcmotor9_stop
void dcmotor9_stop(dcmotor9_t *ctx)
Stop the engine function.
dcmotor9_short_brake
void dcmotor9_short_brake(dcmotor9_t *ctx)
Brake the engine function.
dcmotor9_pwm_start
void dcmotor9_pwm_start(dcmotor9_t *ctx)
Start PWM module.
dcmotor9_read_an_voltage
err_t dcmotor9_read_an_voltage(dcmotor9_t *ctx, float *data_out)
AN Voltage Read function.
dcmotor9_cfg_t
Click configuration structure definition.
Definition: dcmotor9.h:111
dcmotor9_cfg_t::pw2
pin_name_t pw2
Definition: dcmotor9.h:118
dcmotor9_standby
void dcmotor9_standby(dcmotor9_t *ctx)
Disable the engine function.
dcmotor9_cfg_t::shd
pin_name_t shd
Definition: dcmotor9.h:116