stepper18 2.0.0.0
stepper18.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 STEPPER18_H
29#define STEPPER18_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_i2c_master.h"
52
67#define STEPPER18_STEP_RES_FULL 1
68#define STEPPER18_STEP_RES_HALF 2
69#define STEPPER18_STEP_RES_QUARTER 4
70#define STEPPER18_STEP_RES_1div8 8
71#define STEPPER18_STEP_RES_1div16 16
72#define STEPPER18_STEP_RES_1div32 32
73#define STEPPER18_STEP_RES_1div64 64
74#define STEPPER18_STEP_RES_1div128 128
75#define STEPPER18_STEP_RES_1div256 256
76
81#define STEPPER18_SPEED_VERY_SLOW 1
82#define STEPPER18_SPEED_SLOW 2
83#define STEPPER18_SPEED_MEDIUM 3
84#define STEPPER18_SPEED_FAST 4
85#define STEPPER18_SPEED_VERY_FAST 5
86
92#define STEPPER18_SET_DEV_ADDR 0x60
93
94 // stepper18_set
95
110#define STEPPER18_MAP_MIKROBUS( cfg, mikrobus ) \
111 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
112 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
113 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
114 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115 cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116 cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
117 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
118
119 // stepper18_map
120 // stepper18
121
126typedef struct
127{
128 // Output pins
129 digital_out_t en;
130 digital_out_t dir;
131 digital_out_t slp;
132 digital_out_t stp;
134 // Input pins
135 digital_in_t flt;
137 // Modules
138 i2c_master_t i2c;
140 // I2C slave address
143 // Motor stepps
144 uint16_t steps;
146
147
149
154typedef struct
155{
156 pin_name_t scl;
157 pin_name_t sda;
159 pin_name_t en;
160 pin_name_t dir;
161 pin_name_t slp;
162 pin_name_t stp;
163 pin_name_t flt;
165 uint32_t i2c_speed;
166 uint8_t i2c_address;
169
180
197
213
228
242err_t stepper18_generic_write ( stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
243
256err_t stepper18_set_out_voltage ( stepper18_t *ctx, uint16_t voltage );
257
266void stepper18_set_dir ( stepper18_t *ctx, uint8_t value );
267
276void stepper18_set_slp ( stepper18_t *ctx, uint8_t value );
277
286void stepper18_set_en ( stepper18_t *ctx, uint8_t value );
287
296void stepper18_set_stp ( stepper18_t *ctx, uint8_t value );
297
306
335void stepper18_move_motor_angle ( stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed );
336
365void stepper18_move_motor_step ( stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed );
366
376
377#ifdef __cplusplus
378}
379#endif
380#endif // STEPPER18_H
381
382 // stepper18
383
384// ------------------------------------------------------------------------ END
void stepper18_calculate_resolution(stepper18_t *ctx)
Calculate step-degree resolution.
err_t stepper18_init(stepper18_t *ctx, stepper18_cfg_t *cfg)
Stepper 18 initialization function.
void stepper18_set_slp(stepper18_t *ctx, uint8_t value)
Set sleep.
uint8_t stepper18_get_flt(stepper18_t *ctx)
Get fault.
void stepper18_move_motor_step(stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed)
Move motor in step value.
err_t stepper18_generic_write(stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
Writing function.
err_t stepper18_default_cfg(stepper18_t *ctx)
Stepper 18 default configuration function.
err_t stepper18_set_out_voltage(stepper18_t *ctx, uint16_t voltage)
Set voltage reference.
void stepper18_set_dir(stepper18_t *ctx, uint8_t value)
Set direction.
void stepper18_set_en(stepper18_t *ctx, uint8_t value)
Set enable.
void stepper18_cfg_setup(stepper18_cfg_t *cfg)
Stepper 18 configuration object setup function.
void stepper18_set_stp(stepper18_t *ctx, uint8_t value)
Set step state.
void stepper18_move_motor_angle(stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed)
Move motor in angle value.
stepper18_return_value_t
Stepper 18 Click return value data.
Definition stepper18.h:175
@ STEPPER18_ERROR
Definition stepper18.h:177
@ STEPPER18_OK
Definition stepper18.h:176
Stepper 18 Click configuration object.
Definition stepper18.h:155
pin_name_t stp
Definition stepper18.h:162
pin_name_t slp
Definition stepper18.h:161
uint32_t i2c_speed
Definition stepper18.h:165
pin_name_t flt
Definition stepper18.h:163
pin_name_t dir
Definition stepper18.h:160
pin_name_t scl
Definition stepper18.h:156
pin_name_t en
Definition stepper18.h:159
pin_name_t sda
Definition stepper18.h:157
uint8_t i2c_address
Definition stepper18.h:166
Stepper 18 Click context object.
Definition stepper18.h:127
uint16_t steps
Definition stepper18.h:144
float resolution
Definition stepper18.h:145
digital_in_t flt
Definition stepper18.h:135
digital_out_t slp
Definition stepper18.h:131
digital_out_t stp
Definition stepper18.h:132
i2c_master_t i2c
Definition stepper18.h:138
digital_out_t en
Definition stepper18.h:129
uint8_t slave_address
Definition stepper18.h:141
digital_out_t dir
Definition stepper18.h:130