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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define STEPPER19_REG_IN_PORT 0x00
60 #define STEPPER19_REG_OUT_PORT 0x01
61 #define STEPPER19_REG_POL_INV 0x02
62 #define STEPPER19_REG_CONFIG 0x03
63  // stepper19_reg
65 
80 #define STEPPER19_PIN_STATE_LOW 0
81 #define STEPPER19_PIN_STATE_HIGH 1
82 
87 #define STEPPER19_DIR_CLOCKWISE 0
88 #define STEPPER19_DIR_COUNTERCLOCKWISE 1
89 
94 #define STEPPER19_PIN_NONE 0x00
95 #define STEPPER19_PIN_M0 0x01
96 #define STEPPER19_PIN_M1 0x02
97 #define STEPPER19_PIN_DEC0 0x04
98 #define STEPPER19_PIN_DEC1 0x08
99 #define STEPPER19_PIN_TOFF 0x10
100 #define STEPPER19_PIN_STP 0x20
101 #define STEPPER19_PIN_DIR 0x40
102 
107 #define STEPPER19_CTRL_STEP_DIR_GPIO 0
108 #define STEPPER19_CTRL_STEP_DIR_PORT_EXP 1
109 
114 #define STEPPER19_PORT_EXP_DEFAULT_CFG 0x03
115 
120 #define STEPPER19_MSTEP_MODE_FULL 1
121 #define STEPPER19_MSTEP_MODE_HALF 2
122 #define STEPPER19_MSTEP_MODE_1_4 4
123 #define STEPPER19_MSTEP_MODE_1_8 8
124 #define STEPPER19_MSTEP_MODE_1_16 16
125 #define STEPPER19_MSTEP_MODE_1_32 32
126 #define STEPPER19_MSTEP_MODE_1_64 64
127 #define STEPPER19_MSTEP_MODE_1_128 128
128 #define STEPPER19_MSTEP_MODE_1_256 256
129 
134 #define STEPPER19_DECAY_MODE_DYN 0
135 #define STEPPER19_DECAY_MODE_XRP 1
136 #define STEPPER19_DECAY_MODE_F_30 2
137 #define STEPPER19_DECAY_MODE_SLW 3
138 
143 #define STEPPER19_TOFF_7US 0
144 #define STEPPER19_TOFF_16US 1
145 
150 #define STEPPER19_STEP_DELAY_DEF_100US 2ul
151 
156 #define STEPPER19_FULL_STEP 1.0f
157 #define STEPPER19_STEP_SPEED_MIN 1
158 #define STEPPER19_STEP_SPEED_MAX 100
159 #define STEPPER19_ANGLE_360_DEGREES 360.0f
160 
165 #define STEPPER19_FULL_CIRCLE 360.0
166 #define STEPPER19_RESOLUTION 4096.0
167 #define STEPPER19_VREF 3330.0
168 
174 #define STEPPER19_DEVICE_ADDRESS_0 0x70
175 #define STEPPER19_DEVICE_ADDRESS_1 0x72
176 #define STEPPER19_DEVICE_ADDRESS_2 0x74
177 #define STEPPER19_DEVICE_ADDRESS_3 0x76
178  // stepper19_set
180 
195 #define STEPPER19_MAP_MIKROBUS( cfg, mikrobus ) \
196  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
197  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
198  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
199  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
200  cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
201  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
202  // stepper19_map // stepper19
205 
210 typedef struct
211 {
212  // Output pins
213  digital_out_t en;
214  digital_out_t dir;
215  digital_out_t stp;
217  // Input pins
218  digital_in_t flt;
220  // Modules
221  i2c_master_t i2c;
223  // I2C slave address
224  uint8_t slave_address;
226  // Motor stepps
227  float step_delay;
229  uint8_t step_dir_mode;
231 } stepper19_t;
232 
237 typedef struct
238 {
239  pin_name_t scl;
240  pin_name_t sda;
242  pin_name_t en;
243  pin_name_t dir;
244  pin_name_t stp;
245  pin_name_t flt;
247  uint32_t i2c_speed;
248  uint8_t i2c_address;
251 
256 typedef enum
257 {
259  STEPPER19_ERROR = -1
260 
262 
279 
294 
308 
323 err_t stepper19_generic_write ( stepper19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
324 
339 err_t stepper19_generic_read ( stepper19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
340 
355 err_t stepper19_port_exp_write ( stepper19_t *ctx, uint8_t reg, uint8_t data_in );
356 
371 err_t stepper19_port_exp_read ( stepper19_t *ctx, uint8_t reg, uint8_t *data_out );
372 
387 err_t stepper19_set_pins ( stepper19_t *ctx, uint8_t set_mask, uint8_t clr_mask );
388 
402 err_t stepper19_set_microstep_mode ( stepper19_t *ctx, uint8_t ms_mode );
403 
417 err_t stepper19_set_decay_mode ( stepper19_t *ctx, uint8_t decay_mode );
418 
432 err_t stepper19_set_toff ( stepper19_t *ctx, uint8_t toff );
433 
445 
457 
471 err_t stepper19_set_direction ( stepper19_t *ctx, uint8_t dir );
472 
486 err_t stepper19_set_step ( stepper19_t *ctx, uint8_t step );
487 
501 err_t stepper19_make_one_step ( stepper19_t *ctx, uint8_t step_speed );
502 
518 err_t stepper19_rotate_by_angle ( stepper19_t *ctx, uint8_t step_speed, float angle, uint16_t res_360 );
519 
534 err_t stepper19_rotate_by_step ( stepper19_t *ctx, uint8_t step_speed, uint16_t steps );
535 
549 
550 
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 #endif // STEPPER19_H
556  // stepper19
558 
559 // ------------------------------------------------------------------------ END
stepper19_t::microstep_mode
float microstep_mode
Definition: stepper19.h:228
stepper19_t::stp
digital_out_t stp
Definition: stepper19.h:215
stepper19_t::flt
digital_in_t flt
Definition: stepper19.h:218
stepper19_cfg_t::flt
pin_name_t flt
Definition: stepper19.h:245
STEPPER19_OK
@ STEPPER19_OK
Definition: stepper19.h:258
stepper19_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper19.h:248
stepper19_rotate_by_angle
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.
stepper19_t::step_delay
float step_delay
Definition: stepper19.h:227
stepper19_disable_device
void stepper19_disable_device(stepper19_t *ctx)
Stepper 19 disable device function.
stepper19_t
Stepper 19 Click context object.
Definition: stepper19.h:211
stepper19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper19.h:247
stepper19_cfg_t::en
pin_name_t en
Definition: stepper19.h:242
stepper19_generic_read
err_t stepper19_generic_read(stepper19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Stepper 19 I2C reading function.
STEPPER19_ERROR
@ STEPPER19_ERROR
Definition: stepper19.h:259
stepper19_t::step_dir_mode
uint8_t step_dir_mode
Definition: stepper19.h:229
stepper19_make_one_step
err_t stepper19_make_one_step(stepper19_t *ctx, uint8_t step_speed)
Stepper 19 make the one step function.
stepper19_default_cfg
err_t stepper19_default_cfg(stepper19_t *ctx)
Stepper 19 default configuration function.
stepper19_set_pins
err_t stepper19_set_pins(stepper19_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Stepper 19 sets the pin states function.
stepper19_t::slave_address
uint8_t slave_address
Definition: stepper19.h:224
stepper19_port_exp_read
err_t stepper19_port_exp_read(stepper19_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 19 port expander data reading function.
stepper19_set_microstep_mode
err_t stepper19_set_microstep_mode(stepper19_t *ctx, uint8_t ms_mode)
Stepper 19 sets the microstepping mode function.
stepper19_set_toff
err_t stepper19_set_toff(stepper19_t *ctx, uint8_t toff)
Stepper 19 set toff function.
stepper19_t::dir
digital_out_t dir
Definition: stepper19.h:214
stepper19_cfg_setup
void stepper19_cfg_setup(stepper19_cfg_t *cfg)
Stepper 19 configuration object setup function.
stepper19_t::en
digital_out_t en
Definition: stepper19.h:213
stepper19_return_value_t
stepper19_return_value_t
Stepper 19 Click return value data.
Definition: stepper19.h:257
stepper19_cfg_t::dir
pin_name_t dir
Definition: stepper19.h:243
stepper19_cfg_t::stp
pin_name_t stp
Definition: stepper19.h:244
stepper19_fault_indication
uint8_t stepper19_fault_indication(stepper19_t *ctx)
Stepper 19 fault indication function.
stepper19_t::i2c
i2c_master_t i2c
Definition: stepper19.h:221
stepper19_set_step
err_t stepper19_set_step(stepper19_t *ctx, uint8_t step)
Stepper 19 sets the step function.
stepper19_port_exp_write
err_t stepper19_port_exp_write(stepper19_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 19 port expander data writing function.
stepper19_cfg_t::sda
pin_name_t sda
Definition: stepper19.h:240
stepper19_cfg_t
Stepper 19 Click configuration object.
Definition: stepper19.h:238
stepper19_set_decay_mode
err_t stepper19_set_decay_mode(stepper19_t *ctx, uint8_t decay_mode)
Stepper 19 sets the decay mode function.
stepper19_set_direction
err_t stepper19_set_direction(stepper19_t *ctx, uint8_t dir)
Stepper 19 sets the direction function.
stepper19_generic_write
err_t stepper19_generic_write(stepper19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Stepper 19 I2C writing function.
stepper19_enable_device
void stepper19_enable_device(stepper19_t *ctx)
Stepper 19 enable device function.
stepper19_cfg_t::scl
pin_name_t scl
Definition: stepper19.h:239
stepper19_init
err_t stepper19_init(stepper19_t *ctx, stepper19_cfg_t *cfg)
Stepper 19 initialization function.
stepper19_rotate_by_step
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.