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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 #include "drv_pwm.h"
40 
61 #define DCMOTOR24_CFG_DR 0x0002u
62 #define DCMOTOR24_CFG_CL_2p5A 0x0000u
63 #define DCMOTOR24_CFG_CL_4A 0x0004u
64 #define DCMOTOR24_CFG_CL_6p6A 0x0008u
65 #define DCMOTOR24_CFG_CL_8p6A 0x000Cu
66 #define DCMOTOR24_CFG_CL_MASK 0x000Cu
67 #define DCMOTOR24_CFG_VSR 0x0100u
68 #define DCMOTOR24_CFG_ISR 0x0200u
69 #define DCMOTOR24_CFG_ISR_DIS 0x0400u
70 #define DCMOTOR24_CFG_OL_ON 0x0800u
71 
76 #define DCMOTOR24_DIA_OL_OFF 0x0001u
77 #define DCMOTOR24_DIA_OL_ON 0x0002u
78 #define DCMOTOR24_DIA_VS_UV 0x0004u
79 #define DCMOTOR24_DIA_VDD_OV 0x0008u
80 #define DCMOTOR24_DIA_ILIM 0x0010u
81 #define DCMOTOR24_DIA_TWARN 0x0020u
82 #define DCMOTOR24_DIA_TSD 0x0040u
83 #define DCMOTOR24_DIA_ACT 0x0080u
84 #define DCMOTOR24_DIA_OC_LS1 0x0100u
85 #define DCMOTOR24_DIA_OC_LS2 0x0200u
86 #define DCMOTOR24_DIA_OC_HS1 0x0400u
87 #define DCMOTOR24_DIA_OC_HS2 0x0800u
88 #define DCMOTOR24_DIA_SGND_OFF 0x4000u
89 #define DCMOTOR24_DIA_SBAT_OFF 0x8000u
90 
95 #define DCMOTOR24_DIR_REVERSE 0
96 #define DCMOTOR24_DIR_FORWARD 1
97 
102 #define DCMOTOR24_DEF_FREQ 5000
103 
112 #define DCMOTOR24_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
113 #define DCMOTOR24_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
114  // dcmotor24_set
116 
131 #define DCMOTOR24_MAP_MIKROBUS( cfg, mikrobus ) \
132  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
133  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
134  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
135  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
136  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
137  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
138  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
139  // dcmotor24_map // dcmotor24
142 
147 typedef struct
148 {
149  // Output pins
150  digital_out_t dir;
151  digital_out_t en;
153  // Modules
154  spi_master_t spi;
155  pwm_t pwm;
157  pin_name_t chip_select;
158  uint32_t pwm_freq;
160  uint16_t config_word;
161 
162 } dcmotor24_t;
163 
168 typedef struct
169 {
170  // Communication gpio pins
171  pin_name_t miso;
172  pin_name_t mosi;
173  pin_name_t sck;
174  pin_name_t cs;
175  pin_name_t pwm;
177  // Additional gpio pins
178  pin_name_t dir;
179  pin_name_t en;
181  // static variable
182  uint32_t spi_speed;
183  spi_master_mode_t spi_mode;
184  spi_master_chip_select_polarity_t cs_polarity;
185  uint32_t dev_pwm_freq;
188 
193 typedef enum
194 {
196  DCMOTOR24_ERROR = -1
197 
199 
216 
231 
245 
257 err_t dcmotor24_write_config ( dcmotor24_t *ctx, uint16_t config_word );
258 
270 err_t dcmotor24_read_diag ( dcmotor24_t *ctx, uint16_t *diag );
271 
282 void dcmotor24_set_direction ( dcmotor24_t *ctx, uint8_t dir );
283 
293 
303 
313 
325 err_t dcmotor24_set_duty_cycle ( dcmotor24_t *ctx, float duty_cycle );
326 
338 
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif // DCMOTOR24_H
355  // dcmotor24
357 
358 // ------------------------------------------------------------------------ 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:154
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:185
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dcmotor24_t::config_word
uint16_t config_word
Definition: dcmotor24.h:160
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:174
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:155
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:148
dcmotor24_t::chip_select
pin_name_t chip_select
Definition: dcmotor24.h:157
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:172
dcmotor24_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor24.h:184
dcmotor24_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor24.h:182
dcmotor24_cfg_t::sck
pin_name_t sck
Definition: dcmotor24.h:173
dcmotor24_cfg_t::miso
pin_name_t miso
Definition: dcmotor24.h:171
dcmotor24_return_value_t
dcmotor24_return_value_t
DC Motor 24 Click return value data.
Definition: dcmotor24.h:194
dcmotor24_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor24.h:175
dcmotor24_t::dir
digital_out_t dir
Definition: dcmotor24.h:150
dcmotor24_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor24.h:158
dcmotor24_t::en
digital_out_t en
Definition: dcmotor24.h:151
DCMOTOR24_OK
@ DCMOTOR24_OK
Definition: dcmotor24.h:195
DCMOTOR24_ERROR
@ DCMOTOR24_ERROR
Definition: dcmotor24.h:196
dcmotor24_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor24.h:183
dcmotor24_cfg_t
DC Motor 24 Click configuration object.
Definition: dcmotor24.h:169
dcmotor24_cfg_t::dir
pin_name_t dir
Definition: dcmotor24.h:178
dcmotor24_cfg_t::en
pin_name_t en
Definition: dcmotor24.h:179
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.