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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 #include "drv_pwm.h"
50 
71 #define DCMOTOR24_CFG_DR 0x0002u
72 #define DCMOTOR24_CFG_CL_2p5A 0x0000u
73 #define DCMOTOR24_CFG_CL_4A 0x0004u
74 #define DCMOTOR24_CFG_CL_6p6A 0x0008u
75 #define DCMOTOR24_CFG_CL_8p6A 0x000Cu
76 #define DCMOTOR24_CFG_CL_MASK 0x000Cu
77 #define DCMOTOR24_CFG_VSR 0x0100u
78 #define DCMOTOR24_CFG_ISR 0x0200u
79 #define DCMOTOR24_CFG_ISR_DIS 0x0400u
80 #define DCMOTOR24_CFG_OL_ON 0x0800u
81 
86 #define DCMOTOR24_DIA_OL_OFF 0x0001u
87 #define DCMOTOR24_DIA_OL_ON 0x0002u
88 #define DCMOTOR24_DIA_VS_UV 0x0004u
89 #define DCMOTOR24_DIA_VDD_OV 0x0008u
90 #define DCMOTOR24_DIA_ILIM 0x0010u
91 #define DCMOTOR24_DIA_TWARN 0x0020u
92 #define DCMOTOR24_DIA_TSD 0x0040u
93 #define DCMOTOR24_DIA_ACT 0x0080u
94 #define DCMOTOR24_DIA_OC_LS1 0x0100u
95 #define DCMOTOR24_DIA_OC_LS2 0x0200u
96 #define DCMOTOR24_DIA_OC_HS1 0x0400u
97 #define DCMOTOR24_DIA_OC_HS2 0x0800u
98 #define DCMOTOR24_DIA_SGND_OFF 0x4000u
99 #define DCMOTOR24_DIA_SBAT_OFF 0x8000u
100 
105 #define DCMOTOR24_DIR_REVERSE 0
106 #define DCMOTOR24_DIR_FORWARD 1
107 
112 #define DCMOTOR24_DEF_FREQ 5000
113 
122 #define DCMOTOR24_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
123 #define DCMOTOR24_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
124  // dcmotor24_set
126 
141 #define DCMOTOR24_MAP_MIKROBUS( cfg, mikrobus ) \
142  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
143  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
144  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
145  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
146  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
147  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
148  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
149  // dcmotor24_map // dcmotor24
152 
157 typedef struct
158 {
159  // Output pins
160  digital_out_t dir;
161  digital_out_t en;
163  // Modules
164  spi_master_t spi;
165  pwm_t pwm;
167  pin_name_t chip_select;
168  uint32_t pwm_freq;
170  uint16_t config_word;
171 
172 } dcmotor24_t;
173 
178 typedef struct
179 {
180  // Communication gpio pins
181  pin_name_t miso;
182  pin_name_t mosi;
183  pin_name_t sck;
184  pin_name_t cs;
185  pin_name_t pwm;
187  // Additional gpio pins
188  pin_name_t dir;
189  pin_name_t en;
191  // static variable
192  uint32_t spi_speed;
193  spi_master_mode_t spi_mode;
194  spi_master_chip_select_polarity_t cs_polarity;
195  uint32_t dev_pwm_freq;
198 
203 typedef enum
204 {
206  DCMOTOR24_ERROR = -1
207 
209 
226 
241 
255 
267 err_t dcmotor24_write_config ( dcmotor24_t *ctx, uint16_t config_word );
268 
280 err_t dcmotor24_read_diag ( dcmotor24_t *ctx, uint16_t *diag );
281 
292 void dcmotor24_set_direction ( dcmotor24_t *ctx, uint8_t dir );
293 
303 
313 
323 
335 err_t dcmotor24_set_duty_cycle ( dcmotor24_t *ctx, float duty_cycle );
336 
348 
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 #endif // DCMOTOR24_H
365  // dcmotor24
367 
368 // ------------------------------------------------------------------------ END
dcmotor24_read_diag
err_t dcmotor24_read_diag(dcmotor24_t *ctx, uint16_t *diag)
DC Motor 24 read diag function.
dcmotor24_cfg_setup
void dcmotor24_cfg_setup(dcmotor24_cfg_t *cfg)
DC Motor 24 configuration object setup function.
dcmotor24_t::spi
spi_master_t spi
Definition: dcmotor24.h:164
dcmotor24_init
err_t dcmotor24_init(dcmotor24_t *ctx, dcmotor24_cfg_t *cfg)
DC Motor 24 initialization function.
dcmotor24_enable_output
void dcmotor24_enable_output(dcmotor24_t *ctx)
DC Motor 24 enable output function.
dcmotor24_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor24.h:195
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dcmotor24_t::config_word
uint16_t config_word
Definition: dcmotor24.h:170
dcmotor24_pwm_stop
err_t dcmotor24_pwm_stop(dcmotor24_t *ctx)
DC Motor 24 stop PWM module.
dcmotor24_set_direction
void dcmotor24_set_direction(dcmotor24_t *ctx, uint8_t dir)
DC Motor 24 set direction function.
dcmotor24_cfg_t::cs
pin_name_t cs
Definition: dcmotor24.h:184
dcmotor24_disable_output
void dcmotor24_disable_output(dcmotor24_t *ctx)
DC Motor 24 disable output function.
dcmotor24_t::pwm
pwm_t pwm
Definition: dcmotor24.h:165
dcmotor24_set_duty_cycle
err_t dcmotor24_set_duty_cycle(dcmotor24_t *ctx, float duty_cycle)
DC Motor 24 sets PWM duty cycle.
dcmotor24_switch_direction
void dcmotor24_switch_direction(dcmotor24_t *ctx)
DC Motor 24 switch direction function.
dcmotor24_t
DC Motor 24 Click context object.
Definition: dcmotor24.h:158
dcmotor24_t::chip_select
pin_name_t chip_select
Definition: dcmotor24.h:167
dcmotor24_pwm_start
err_t dcmotor24_pwm_start(dcmotor24_t *ctx)
DC Motor 24 start PWM module.
dcmotor24_cfg_t::mosi
pin_name_t mosi
Definition: dcmotor24.h:182
dcmotor24_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor24.h:194
dcmotor24_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor24.h:192
dcmotor24_cfg_t::sck
pin_name_t sck
Definition: dcmotor24.h:183
dcmotor24_cfg_t::miso
pin_name_t miso
Definition: dcmotor24.h:181
dcmotor24_return_value_t
dcmotor24_return_value_t
DC Motor 24 Click return value data.
Definition: dcmotor24.h:204
dcmotor24_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor24.h:185
dcmotor24_t::dir
digital_out_t dir
Definition: dcmotor24.h:160
dcmotor24_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor24.h:168
dcmotor24_t::en
digital_out_t en
Definition: dcmotor24.h:161
DCMOTOR24_OK
@ DCMOTOR24_OK
Definition: dcmotor24.h:205
DCMOTOR24_ERROR
@ DCMOTOR24_ERROR
Definition: dcmotor24.h:206
dcmotor24_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor24.h:193
dcmotor24_cfg_t
DC Motor 24 Click configuration object.
Definition: dcmotor24.h:179
dcmotor24_cfg_t::dir
pin_name_t dir
Definition: dcmotor24.h:188
dcmotor24_cfg_t::en
pin_name_t en
Definition: dcmotor24.h:189
dcmotor24_default_cfg
err_t dcmotor24_default_cfg(dcmotor24_t *ctx)
DC Motor 24 default configuration function.
dcmotor24_write_config
err_t dcmotor24_write_config(dcmotor24_t *ctx, uint16_t config_word)
DC Motor 24 write config function.