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 )
63#define DCMOTOR9_DEF_FREQ 20000
64#define DCMOTOR9_DEF_VREF 3.3
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 // End group macro
85// --------------------------------------------------------------- PUBLIC TYPES
94typedef 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
111typedef 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
136extern "C"{
137#endif
138
149
164
174void dcmotor9_set_duty_cycle ( dcmotor9_t *ctx, float duty_cycle );
175
184
193
202
211
221
231
240
249
262err_t dcmotor9_read_an_value ( dcmotor9_t *ctx, uint16_t *data_out );
263
277err_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
void dcmotor9_counter_clockwise(dcmotor9_t *ctx)
Set the counter clockwise direction of rotation function.
void dcmotor9_clockwise(dcmotor9_t *ctx)
Set the clockwise direction of rotation function.
err_t dcmotor9_read_an_voltage(dcmotor9_t *ctx, float *data_out)
AN Voltage Read function.
void dcmotor9_enable(dcmotor9_t *ctx)
Enable the engine function.
void dcmotor9_set_duty_cycle(dcmotor9_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
err_t dcmotor9_read_an_value(dcmotor9_t *ctx, uint16_t *data_out)
AN Value Read function.
err_t dcmotor9_init(dcmotor9_t *ctx, dcmotor9_cfg_t *cfg)
Initialization function.
void dcmotor9_short_brake(dcmotor9_t *ctx)
Brake the engine function.
void dcmotor9_standby(dcmotor9_t *ctx)
Disable the engine function.
void dcmotor9_cfg_setup(dcmotor9_cfg_t *cfg)
Configuration Object Init Setup function.
void dcmotor9_pwm_stop(dcmotor9_t *ctx)
Stop PWM module.
void dcmotor9_pwm_start(dcmotor9_t *ctx)
Start PWM module.
void dcmotor9_stop(dcmotor9_t *ctx)
Stop the engine function.
Click configuration structure definition.
Definition: dcmotor9.h:112
analog_in_resolution_t resolution
Definition: dcmotor9.h:123
float vref
Definition: dcmotor9.h:124
pin_name_t pw2
Definition: dcmotor9.h:118
uint32_t pwm_freq
Definition: dcmotor9.h:122
pin_name_t shd
Definition: dcmotor9.h:116
pin_name_t pw1
Definition: dcmotor9.h:117
pin_name_t an
Definition: dcmotor9.h:115
Click ctx object definition.
Definition: dcmotor9.h:95
digital_out_t pw2
Definition: dcmotor9.h:99
analog_in_t adc
Definition: dcmotor9.h:104
pwm_t pwm
Definition: dcmotor9.h:103
digital_out_t shd
Definition: dcmotor9.h:98