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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define STEPPER11_REG_INPUT_PORT 0x00
70 #define STEPPER11_REG_OUTPUT_PORT 0x01
71 #define STEPPER11_REG_POLARITY 0x02
72 #define STEPPER11_REG_CONFIGURATION 0x03
73  // stepper11_reg
75 
90 #define STEPPER11_SPEED_SLOW 1
91 #define STEPPER11_SPEED_MEDIUM 2
92 #define STEPPER11_SPEED_FAST 3
93 
98 #define STEPPER11_RESOLUTION_FULL 0x4
99 #define STEPPER11_RESOLUTION_HALF_A 0x2
100 #define STEPPER11_RESOLUTION_HALF_B 0x1
101 #define STEPPER11_RESOLUTION_QUARTER 0x6
102 #define STEPPER11_RESOLUTION_1div8 0x5
103 #define STEPPER11_RESOLUTION_1div16 0x3
104 #define STEPPER11_RESOLUTION_1div32 0x7
105 
110 #define STEPPER11_TORQUE_100 0x0
111 #define STEPPER11_TORQUE_70 0x1
112 #define STEPPER11_TORQUE_50 0x2
113 #define STEPPER11_TORQUE_30 0x3
114 
120 #define STEPPER11_SET_DEV_ADDR 0x70
121  // stepper11_set
123 
138 #define STEPPER11_MAP_MIKROBUS( cfg, mikrobus ) \
139  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
140  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
141  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
142  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
143  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
144  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
145  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
146  // stepper11_map // stepper11
149 
154 typedef struct
155 {
156  // Output pins
157  digital_out_t en;
158  digital_out_t dir;
159  digital_out_t rst;
160  digital_out_t clk;
162  // Input pins
163  digital_in_t int_pin;
165  // Modules
166  i2c_master_t i2c;
168  // I2C slave address
169  uint8_t slave_address;
170  // ctx variable
171  uint16_t steps;
172  float resolution;
173  uint8_t step_resolution;
175 } stepper11_t;
176 
181 typedef struct
182 {
183  pin_name_t scl;
184  pin_name_t sda;
186  pin_name_t en;
187  pin_name_t dir;
188  pin_name_t rst;
189  pin_name_t clk;
190  pin_name_t int_pin;
192  uint32_t i2c_speed;
193  uint8_t i2c_address;
196 
201 typedef enum
202 {
204  STEPPER11_ERROR = -1
205 
207 
224 
240 
255 
270 err_t stepper11_generic_write ( stepper11_t *ctx, uint8_t reg, uint8_t tx_data );
271 
286 err_t stepper11_generic_read ( stepper11_t *ctx, uint8_t reg, uint8_t *rx_data );
287 
296 void stepper11_set_direction ( stepper11_t *ctx, uint8_t state );
297 
306 void stepper11_set_enable ( stepper11_t *ctx, uint8_t state );
307 
316 void stepper11_set_reset ( stepper11_t *ctx, uint8_t state );
317 
326 void stepper11_set_clock ( stepper11_t *ctx, uint8_t state );
327 
336 
346 
355 uint8_t stepper11_get_mo ( stepper11_t *ctx );
356 
365 uint8_t stepper11_get_sd ( stepper11_t *ctx );
366 
385 err_t stepper11_set_step_resolution ( stepper11_t *ctx, uint8_t step_res );
386 
402 err_t stepper11_set_torque ( stepper11_t *ctx, uint8_t torque );
403 
416 void stepper11_move_motor_angle ( stepper11_t *ctx, float degree, uint8_t speed );
417 
430 void stepper11_move_motor_step ( stepper11_t *ctx, uint16_t steps, uint8_t speed );
431 
432 #ifdef __cplusplus
433 }
434 #endif
435 #endif // STEPPER11_H
436  // stepper11
438 
439 // ------------------------------------------------------------------------ END
stepper11_get_mo
uint8_t stepper11_get_mo(stepper11_t *ctx)
Get electrical angle monitoring signal.
STEPPER11_ERROR
@ STEPPER11_ERROR
Definition: stepper11.h:204
stepper11_cfg_t::dir
pin_name_t dir
Definition: stepper11.h:187
stepper11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper11.h:192
stepper11_cfg_t::sda
pin_name_t sda
Definition: stepper11.h:184
stepper11_t::en
digital_out_t en
Definition: stepper11.h:157
stepper11_cfg_t::rst
pin_name_t rst
Definition: stepper11.h:188
stepper11_t::i2c
i2c_master_t i2c
Definition: stepper11.h:166
stepper11_t::slave_address
uint8_t slave_address
Definition: stepper11.h:169
stepper11_cfg_t::scl
pin_name_t scl
Definition: stepper11.h:183
stepper11_get_diag
uint8_t stepper11_get_diag(stepper11_t *ctx)
Get anomaly detection flag.
stepper11_t::dir
digital_out_t dir
Definition: stepper11.h:158
stepper11_cfg_setup
void stepper11_cfg_setup(stepper11_cfg_t *cfg)
Stepper 11 configuration object setup function.
stepper11_t::resolution
float resolution
Definition: stepper11.h:172
stepper11_get_sd
uint8_t stepper11_get_sd(stepper11_t *ctx)
Get stall detection flag.
stepper11_set_reset
void stepper11_set_reset(stepper11_t *ctx, uint8_t state)
Set restart.
stepper11_set_step_resolution
err_t stepper11_set_step_resolution(stepper11_t *ctx, uint8_t step_res)
Set step resolution.
stepper11_set_clock
void stepper11_set_clock(stepper11_t *ctx, uint8_t state)
Set clock state.
stepper11_move_motor_step
void stepper11_move_motor_step(stepper11_t *ctx, uint16_t steps, uint8_t speed)
Move motor in step value.
stepper11_init
err_t stepper11_init(stepper11_t *ctx, stepper11_cfg_t *cfg)
Stepper 11 initialization function.
stepper11_t
Stepper 11 Click context object.
Definition: stepper11.h:155
stepper11_t::step_resolution
uint8_t step_resolution
Definition: stepper11.h:173
stepper11_return_value_t
stepper11_return_value_t
Stepper 11 Click return value data.
Definition: stepper11.h:202
stepper11_t::steps
uint16_t steps
Definition: stepper11.h:171
stepper11_cfg_t::en
pin_name_t en
Definition: stepper11.h:186
stepper11_generic_write
err_t stepper11_generic_write(stepper11_t *ctx, uint8_t reg, uint8_t tx_data)
Stepper 11 I2C writing function.
stepper11_default_cfg
err_t stepper11_default_cfg(stepper11_t *ctx)
Stepper 11 default configuration function.
stepper11_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper11.h:190
stepper11_t::clk
digital_out_t clk
Definition: stepper11.h:160
stepper11_set_torque
err_t stepper11_set_torque(stepper11_t *ctx, uint8_t torque)
Set torque.
stepper11_t::int_pin
digital_in_t int_pin
Definition: stepper11.h:163
stepper11_t::rst
digital_out_t rst
Definition: stepper11.h:159
stepper11_cfg_t
Stepper 11 Click configuration object.
Definition: stepper11.h:182
stepper11_get_interrupt
uint8_t stepper11_get_interrupt(stepper11_t *ctx)
Get interrupt.
STEPPER11_OK
@ STEPPER11_OK
Definition: stepper11.h:203
stepper11_generic_read
err_t stepper11_generic_read(stepper11_t *ctx, uint8_t reg, uint8_t *rx_data)
Stepper 11 I2C reading function.
stepper11_set_enable
void stepper11_set_enable(stepper11_t *ctx, uint8_t state)
Set enable.
stepper11_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper11.h:193
stepper11_cfg_t::clk
pin_name_t clk
Definition: stepper11.h:189
stepper11_move_motor_angle
void stepper11_move_motor_angle(stepper11_t *ctx, float degree, uint8_t speed)
Move motor in angle value.
stepper11_set_direction
void stepper11_set_direction(stepper11_t *ctx, uint8_t state)
Set direction.