stepper19 2.1.0.0
stepper19.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 STEPPER19_H
29#define STEPPER19_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
73#define STEPPER19_REG_IN_PORT 0x00
74#define STEPPER19_REG_OUT_PORT 0x01
75#define STEPPER19_REG_POL_INV 0x02
76#define STEPPER19_REG_CONFIG 0x03
77
78 // stepper19_reg
79
94#define STEPPER19_PIN_STATE_LOW 0
95#define STEPPER19_PIN_STATE_HIGH 1
96
101#define STEPPER19_DIR_CLOCKWISE 0
102#define STEPPER19_DIR_COUNTERCLOCKWISE 1
103
108#define STEPPER19_PIN_NONE 0x00
109#define STEPPER19_PIN_M0 0x01
110#define STEPPER19_PIN_M1 0x02
111#define STEPPER19_PIN_DEC0 0x04
112#define STEPPER19_PIN_DEC1 0x08
113#define STEPPER19_PIN_TOFF 0x10
114#define STEPPER19_PIN_STP 0x20
115#define STEPPER19_PIN_DIR 0x40
116
121#define STEPPER19_CTRL_STEP_DIR_GPIO 0
122#define STEPPER19_CTRL_STEP_DIR_PORT_EXP 1
123
128#define STEPPER19_PORT_EXP_DEFAULT_CFG 0x03
129
134#define STEPPER19_MSTEP_MODE_FULL 1
135#define STEPPER19_MSTEP_MODE_HALF 2
136#define STEPPER19_MSTEP_MODE_1_4 4
137#define STEPPER19_MSTEP_MODE_1_8 8
138#define STEPPER19_MSTEP_MODE_1_16 16
139#define STEPPER19_MSTEP_MODE_1_32 32
140#define STEPPER19_MSTEP_MODE_1_64 64
141#define STEPPER19_MSTEP_MODE_1_128 128
142#define STEPPER19_MSTEP_MODE_1_256 256
143
148#define STEPPER19_DECAY_MODE_DYN 0
149#define STEPPER19_DECAY_MODE_XRP 1
150#define STEPPER19_DECAY_MODE_F_30 2
151#define STEPPER19_DECAY_MODE_SLW 3
152
157#define STEPPER19_TOFF_7US 0
158#define STEPPER19_TOFF_16US 1
159
164#define STEPPER19_STEP_DELAY_DEF_100US 2ul
165
170#define STEPPER19_FULL_STEP 1.0f
171#define STEPPER19_STEP_SPEED_MIN 1
172#define STEPPER19_STEP_SPEED_MAX 100
173#define STEPPER19_ANGLE_360_DEGREES 360.0f
174
179#define STEPPER19_FULL_CIRCLE 360.0
180#define STEPPER19_RESOLUTION 4096.0
181#define STEPPER19_VREF 3330.0
182
188#define STEPPER19_DEVICE_ADDRESS_0 0x70
189#define STEPPER19_DEVICE_ADDRESS_1 0x72
190#define STEPPER19_DEVICE_ADDRESS_2 0x74
191#define STEPPER19_DEVICE_ADDRESS_3 0x76
192
193 // stepper19_set
194
209#define STEPPER19_MAP_MIKROBUS( cfg, mikrobus ) \
210 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
211 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
212 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
213 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
214 cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
215 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
216
217 // stepper19_map
218 // stepper19
219
224typedef struct
225{
226 // Output pins
227 digital_out_t en;
228 digital_out_t dir;
229 digital_out_t stp;
231 // Input pins
232 digital_in_t flt;
234 // Modules
235 i2c_master_t i2c;
237 // I2C slave address
240 // Motor stepps
246
251typedef struct
252{
253 pin_name_t scl;
254 pin_name_t sda;
256 pin_name_t en;
257 pin_name_t dir;
258 pin_name_t stp;
259 pin_name_t flt;
261 uint32_t i2c_speed;
262 uint8_t i2c_address;
265
276
293
308
322
337err_t stepper19_generic_write ( stepper19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
338
353err_t stepper19_generic_read ( stepper19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
354
369err_t stepper19_port_exp_write ( stepper19_t *ctx, uint8_t reg, uint8_t data_in );
370
385err_t stepper19_port_exp_read ( stepper19_t *ctx, uint8_t reg, uint8_t *data_out );
386
401err_t stepper19_set_pins ( stepper19_t *ctx, uint8_t set_mask, uint8_t clr_mask );
402
416err_t stepper19_set_microstep_mode ( stepper19_t *ctx, uint8_t ms_mode );
417
431err_t stepper19_set_decay_mode ( stepper19_t *ctx, uint8_t decay_mode );
432
446err_t stepper19_set_toff ( stepper19_t *ctx, uint8_t toff );
447
459
471
485err_t stepper19_set_direction ( stepper19_t *ctx, uint8_t dir );
486
500err_t stepper19_set_step ( stepper19_t *ctx, uint8_t step );
501
515err_t stepper19_make_one_step ( stepper19_t *ctx, uint8_t step_speed );
516
532err_t stepper19_rotate_by_angle ( stepper19_t *ctx, uint8_t step_speed, float angle, uint16_t res_360 );
533
548err_t stepper19_rotate_by_step ( stepper19_t *ctx, uint8_t step_speed, uint16_t steps );
549
563
564
565
566#ifdef __cplusplus
567}
568#endif
569#endif // STEPPER19_H
570
571 // stepper19
572
573// ------------------------------------------------------------------------ END
err_t stepper19_port_exp_write(stepper19_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 19 port expander data writing function.
void stepper19_cfg_setup(stepper19_cfg_t *cfg)
Stepper 19 configuration object setup function.
void stepper19_disable_device(stepper19_t *ctx)
Stepper 19 disable device function.
err_t stepper19_init(stepper19_t *ctx, stepper19_cfg_t *cfg)
Stepper 19 initialization function.
err_t stepper19_rotate_by_step(stepper19_t *ctx, uint8_t step_speed, uint16_t steps)
Stepper 19 rotates the shaft through a desired step function.
void stepper19_enable_device(stepper19_t *ctx)
Stepper 19 enable device function.
uint8_t stepper19_fault_indication(stepper19_t *ctx)
Stepper 19 fault indication function.
err_t stepper19_port_exp_read(stepper19_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 19 port expander data reading function.
err_t stepper19_set_step(stepper19_t *ctx, uint8_t step)
Stepper 19 sets the step function.
err_t stepper19_rotate_by_angle(stepper19_t *ctx, uint8_t step_speed, float angle, uint16_t res_360)
Stepper 19 rotates the shaft through a desired angle function.
err_t stepper19_set_direction(stepper19_t *ctx, uint8_t dir)
Stepper 19 sets the direction function.
err_t stepper19_make_one_step(stepper19_t *ctx, uint8_t step_speed)
Stepper 19 make the one step function.
err_t stepper19_set_microstep_mode(stepper19_t *ctx, uint8_t ms_mode)
Stepper 19 sets the microstepping mode function.
err_t stepper19_generic_read(stepper19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Stepper 19 I2C reading function.
err_t stepper19_set_pins(stepper19_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Stepper 19 sets the pin states function.
err_t stepper19_set_toff(stepper19_t *ctx, uint8_t toff)
Stepper 19 set toff function.
err_t stepper19_generic_write(stepper19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Stepper 19 I2C writing function.
err_t stepper19_set_decay_mode(stepper19_t *ctx, uint8_t decay_mode)
Stepper 19 sets the decay mode function.
err_t stepper19_default_cfg(stepper19_t *ctx)
Stepper 19 default configuration function.
stepper19_return_value_t
Stepper 19 Click return value data.
Definition stepper19.h:271
@ STEPPER19_OK
Definition stepper19.h:272
@ STEPPER19_ERROR
Definition stepper19.h:273
Stepper 19 Click configuration object.
Definition stepper19.h:252
pin_name_t stp
Definition stepper19.h:258
uint32_t i2c_speed
Definition stepper19.h:261
pin_name_t flt
Definition stepper19.h:259
pin_name_t dir
Definition stepper19.h:257
pin_name_t scl
Definition stepper19.h:253
pin_name_t en
Definition stepper19.h:256
pin_name_t sda
Definition stepper19.h:254
uint8_t i2c_address
Definition stepper19.h:262
Stepper 19 Click context object.
Definition stepper19.h:225
uint8_t step_dir_mode
Definition stepper19.h:243
digital_in_t flt
Definition stepper19.h:232
digital_out_t stp
Definition stepper19.h:229
i2c_master_t i2c
Definition stepper19.h:235
float microstep_mode
Definition stepper19.h:242
digital_out_t en
Definition stepper19.h:227
float step_delay
Definition stepper19.h:241
uint8_t slave_address
Definition stepper19.h:238
digital_out_t dir
Definition stepper19.h:228