stepper11 2.0.0.0
stepper11.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 STEPPER11_H
29#define STEPPER11_H
30
31#ifdef __cplusplus
32extern "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 STEPPER11_REG_INPUT_PORT 0x00
60#define STEPPER11_REG_OUTPUT_PORT 0x01
61#define STEPPER11_REG_POLARITY 0x02
62#define STEPPER11_REG_CONFIGURATION 0x03
63 // stepper11_reg
65
80#define STEPPER11_SPEED_SLOW 1
81#define STEPPER11_SPEED_MEDIUM 2
82#define STEPPER11_SPEED_FAST 3
83
88#define STEPPER11_RESOLUTION_FULL 0x4
89#define STEPPER11_RESOLUTION_HALF_A 0x2
90#define STEPPER11_RESOLUTION_HALF_B 0x1
91#define STEPPER11_RESOLUTION_QUARTER 0x6
92#define STEPPER11_RESOLUTION_1div8 0x5
93#define STEPPER11_RESOLUTION_1div16 0x3
94#define STEPPER11_RESOLUTION_1div32 0x7
95
100#define STEPPER11_TORQUE_100 0x0
101#define STEPPER11_TORQUE_70 0x1
102#define STEPPER11_TORQUE_50 0x2
103#define STEPPER11_TORQUE_30 0x3
104
110#define STEPPER11_SET_DEV_ADDR 0x70
111 // stepper11_set
113
128#define STEPPER11_MAP_MIKROBUS( cfg, mikrobus ) \
129 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
130 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
131 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
132 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
133 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
135 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
136 // stepper11_map // stepper11
139
144typedef struct
145{
146 // Output pins
147 digital_out_t en;
148 digital_out_t dir;
149 digital_out_t rst;
150 digital_out_t clk;
152 // Input pins
153 digital_in_t int_pin;
155 // Modules
156 i2c_master_t i2c;
158 // I2C slave address
160 // ctx variable
161 uint16_t steps;
166
171typedef struct
172{
173 pin_name_t scl;
174 pin_name_t sda;
176 pin_name_t en;
177 pin_name_t dir;
178 pin_name_t rst;
179 pin_name_t clk;
180 pin_name_t int_pin;
182 uint32_t i2c_speed;
183 uint8_t i2c_address;
186
191typedef enum
192{
194 STEPPER11_ERROR = -1
195
197
214
230
245
260err_t stepper11_generic_write ( stepper11_t *ctx, uint8_t reg, uint8_t tx_data );
261
276err_t stepper11_generic_read ( stepper11_t *ctx, uint8_t reg, uint8_t *rx_data );
277
286void stepper11_set_direction ( stepper11_t *ctx, uint8_t state );
287
296void stepper11_set_enable ( stepper11_t *ctx, uint8_t state );
297
306void stepper11_set_reset ( stepper11_t *ctx, uint8_t state );
307
316void stepper11_set_clock ( stepper11_t *ctx, uint8_t state );
317
326
336
346
356
375err_t stepper11_set_step_resolution ( stepper11_t *ctx, uint8_t step_res );
376
392err_t stepper11_set_torque ( stepper11_t *ctx, uint8_t torque );
393
406void stepper11_move_motor_angle ( stepper11_t *ctx, float degree, uint8_t speed );
407
420void stepper11_move_motor_step ( stepper11_t *ctx, uint16_t steps, uint8_t speed );
421
422#ifdef __cplusplus
423}
424#endif
425#endif // STEPPER11_H
426 // stepper11
428
429// ------------------------------------------------------------------------ END
err_t stepper11_default_cfg(stepper11_t *ctx)
Stepper 11 default configuration function.
err_t stepper11_set_step_resolution(stepper11_t *ctx, uint8_t step_res)
Set step resolution.
uint8_t stepper11_get_sd(stepper11_t *ctx)
Get stall detection flag.
void stepper11_set_reset(stepper11_t *ctx, uint8_t state)
Set restart.
void stepper11_cfg_setup(stepper11_cfg_t *cfg)
Stepper 11 configuration object setup function.
uint8_t stepper11_get_interrupt(stepper11_t *ctx)
Get interrupt.
void stepper11_set_enable(stepper11_t *ctx, uint8_t state)
Set enable.
void stepper11_move_motor_step(stepper11_t *ctx, uint16_t steps, uint8_t speed)
Move motor in step value.
void stepper11_set_clock(stepper11_t *ctx, uint8_t state)
Set clock state.
uint8_t stepper11_get_mo(stepper11_t *ctx)
Get electrical angle monitoring signal.
err_t stepper11_generic_write(stepper11_t *ctx, uint8_t reg, uint8_t tx_data)
Stepper 11 I2C writing function.
void stepper11_move_motor_angle(stepper11_t *ctx, float degree, uint8_t speed)
Move motor in angle value.
err_t stepper11_set_torque(stepper11_t *ctx, uint8_t torque)
Set torque.
uint8_t stepper11_get_diag(stepper11_t *ctx)
Get anomaly detection flag.
err_t stepper11_generic_read(stepper11_t *ctx, uint8_t reg, uint8_t *rx_data)
Stepper 11 I2C reading function.
void stepper11_set_direction(stepper11_t *ctx, uint8_t state)
Set direction.
err_t stepper11_init(stepper11_t *ctx, stepper11_cfg_t *cfg)
Stepper 11 initialization function.
stepper11_return_value_t
Stepper 11 Click return value data.
Definition: stepper11.h:192
@ STEPPER11_OK
Definition: stepper11.h:193
@ STEPPER11_ERROR
Definition: stepper11.h:194
Stepper 11 Click configuration object.
Definition: stepper11.h:172
pin_name_t clk
Definition: stepper11.h:179
uint32_t i2c_speed
Definition: stepper11.h:182
pin_name_t dir
Definition: stepper11.h:177
pin_name_t scl
Definition: stepper11.h:173
pin_name_t en
Definition: stepper11.h:176
pin_name_t int_pin
Definition: stepper11.h:180
pin_name_t sda
Definition: stepper11.h:174
pin_name_t rst
Definition: stepper11.h:178
uint8_t i2c_address
Definition: stepper11.h:183
Stepper 11 Click context object.
Definition: stepper11.h:145
uint16_t steps
Definition: stepper11.h:161
float resolution
Definition: stepper11.h:162
uint8_t step_resolution
Definition: stepper11.h:163
digital_in_t int_pin
Definition: stepper11.h:153
i2c_master_t i2c
Definition: stepper11.h:156
digital_out_t clk
Definition: stepper11.h:150
digital_out_t en
Definition: stepper11.h:147
digital_out_t rst
Definition: stepper11.h:149
uint8_t slave_address
Definition: stepper11.h:159
digital_out_t dir
Definition: stepper11.h:148