dcmotor24 2.1.0.0
dcmotor24.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 DCMOTOR24_H
29#define DCMOTOR24_H
30
31#ifdef __cplusplus
32extern "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_spi_master.h"
52#include "spi_specifics.h"
53#include "drv_pwm.h"
54
75#define DCMOTOR24_CFG_DR 0x0002u
76#define DCMOTOR24_CFG_CL_2p5A 0x0000u
77#define DCMOTOR24_CFG_CL_4A 0x0004u
78#define DCMOTOR24_CFG_CL_6p6A 0x0008u
79#define DCMOTOR24_CFG_CL_8p6A 0x000Cu
80#define DCMOTOR24_CFG_CL_MASK 0x000Cu
81#define DCMOTOR24_CFG_VSR 0x0100u
82#define DCMOTOR24_CFG_ISR 0x0200u
83#define DCMOTOR24_CFG_ISR_DIS 0x0400u
84#define DCMOTOR24_CFG_OL_ON 0x0800u
85
90#define DCMOTOR24_DIA_OL_OFF 0x0001u
91#define DCMOTOR24_DIA_OL_ON 0x0002u
92#define DCMOTOR24_DIA_VS_UV 0x0004u
93#define DCMOTOR24_DIA_VDD_OV 0x0008u
94#define DCMOTOR24_DIA_ILIM 0x0010u
95#define DCMOTOR24_DIA_TWARN 0x0020u
96#define DCMOTOR24_DIA_TSD 0x0040u
97#define DCMOTOR24_DIA_ACT 0x0080u
98#define DCMOTOR24_DIA_OC_LS1 0x0100u
99#define DCMOTOR24_DIA_OC_LS2 0x0200u
100#define DCMOTOR24_DIA_OC_HS1 0x0400u
101#define DCMOTOR24_DIA_OC_HS2 0x0800u
102#define DCMOTOR24_DIA_SGND_OFF 0x4000u
103#define DCMOTOR24_DIA_SBAT_OFF 0x8000u
104
109#define DCMOTOR24_DIR_REVERSE 0
110#define DCMOTOR24_DIR_FORWARD 1
111
116#define DCMOTOR24_DEF_FREQ 5000
117
126#define DCMOTOR24_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
127#define DCMOTOR24_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
128
129 // dcmotor24_set
130
145#define DCMOTOR24_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
147 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
148 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
149 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
150 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
151 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
153
154 // dcmotor24_map
155 // dcmotor24
156
161typedef struct
162{
163 // Output pins
164 digital_out_t dir;
165 digital_out_t en;
167 // Modules
168 spi_master_t spi;
169 pwm_t pwm;
171 pin_name_t chip_select;
172 uint32_t pwm_freq;
174 uint16_t config_word;
175
177
182typedef struct
183{
184 // Communication gpio pins
185 pin_name_t miso;
186 pin_name_t mosi;
187 pin_name_t sck;
188 pin_name_t cs;
189 pin_name_t pwm;
191 // Additional gpio pins
192 pin_name_t dir;
193 pin_name_t en;
195 // static variable
196 uint32_t spi_speed;
197 spi_master_mode_t spi_mode;
198 spi_master_chip_select_polarity_t cs_polarity;
199 uint32_t dev_pwm_freq;
202
213
230
245
259
271err_t dcmotor24_write_config ( dcmotor24_t *ctx, uint16_t config_word );
272
284err_t dcmotor24_read_diag ( dcmotor24_t *ctx, uint16_t *diag );
285
296void dcmotor24_set_direction ( dcmotor24_t *ctx, uint8_t dir );
297
307
317
327
339err_t dcmotor24_set_duty_cycle ( dcmotor24_t *ctx, float duty_cycle );
340
352
364
365#ifdef __cplusplus
366}
367#endif
368#endif // DCMOTOR24_H
369
370 // dcmotor24
371
372// ------------------------------------------------------------------------ END
dcmotor24_return_value_t
DC Motor 24 Click return value data.
Definition dcmotor24.h:208
@ DCMOTOR24_ERROR
Definition dcmotor24.h:210
@ DCMOTOR24_OK
Definition dcmotor24.h:209
err_t dcmotor24_read_diag(dcmotor24_t *ctx, uint16_t *diag)
DC Motor 24 read diag function.
void dcmotor24_enable_output(dcmotor24_t *ctx)
DC Motor 24 enable output function.
err_t dcmotor24_init(dcmotor24_t *ctx, dcmotor24_cfg_t *cfg)
DC Motor 24 initialization function.
void dcmotor24_set_direction(dcmotor24_t *ctx, uint8_t dir)
DC Motor 24 set direction function.
err_t dcmotor24_pwm_stop(dcmotor24_t *ctx)
DC Motor 24 stop PWM module.
void dcmotor24_disable_output(dcmotor24_t *ctx)
DC Motor 24 disable output function.
err_t dcmotor24_set_duty_cycle(dcmotor24_t *ctx, float duty_cycle)
DC Motor 24 sets PWM duty cycle.
void dcmotor24_cfg_setup(dcmotor24_cfg_t *cfg)
DC Motor 24 configuration object setup function.
err_t dcmotor24_pwm_start(dcmotor24_t *ctx)
DC Motor 24 start PWM module.
err_t dcmotor24_default_cfg(dcmotor24_t *ctx)
DC Motor 24 default configuration function.
void dcmotor24_switch_direction(dcmotor24_t *ctx)
DC Motor 24 switch direction function.
err_t dcmotor24_write_config(dcmotor24_t *ctx, uint16_t config_word)
DC Motor 24 write config function.
This file contains SPI specific macros, functions, etc.
DC Motor 24 Click configuration object.
Definition dcmotor24.h:183
spi_master_chip_select_polarity_t cs_polarity
Definition dcmotor24.h:198
pin_name_t sck
Definition dcmotor24.h:187
spi_master_mode_t spi_mode
Definition dcmotor24.h:197
pin_name_t mosi
Definition dcmotor24.h:186
uint32_t spi_speed
Definition dcmotor24.h:196
uint32_t dev_pwm_freq
Definition dcmotor24.h:199
pin_name_t dir
Definition dcmotor24.h:192
pin_name_t en
Definition dcmotor24.h:193
pin_name_t pwm
Definition dcmotor24.h:189
pin_name_t miso
Definition dcmotor24.h:185
pin_name_t cs
Definition dcmotor24.h:188
DC Motor 24 Click context object.
Definition dcmotor24.h:162
spi_master_t spi
Definition dcmotor24.h:168
uint16_t config_word
Definition dcmotor24.h:174
uint32_t pwm_freq
Definition dcmotor24.h:172
digital_out_t en
Definition dcmotor24.h:165
pin_name_t chip_select
Definition dcmotor24.h:171
pwm_t pwm
Definition dcmotor24.h:169
digital_out_t dir
Definition dcmotor24.h:164