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
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 
53 #define STEPPER18_STEP_RES_FULL 1
54 #define STEPPER18_STEP_RES_HALF 2
55 #define STEPPER18_STEP_RES_QUARTER 4
56 #define STEPPER18_STEP_RES_1div8 8
57 #define STEPPER18_STEP_RES_1div16 16
58 #define STEPPER18_STEP_RES_1div32 32
59 #define STEPPER18_STEP_RES_1div64 64
60 #define STEPPER18_STEP_RES_1div128 128
61 #define STEPPER18_STEP_RES_1div256 256
62 
67 #define STEPPER18_SPEED_VERY_SLOW 1
68 #define STEPPER18_SPEED_SLOW 2
69 #define STEPPER18_SPEED_MEDIUM 3
70 #define STEPPER18_SPEED_FAST 4
71 #define STEPPER18_SPEED_VERY_FAST 5
72 
78 #define STEPPER18_SET_DEV_ADDR 0x60
79  // stepper18_set
81 
96 #define STEPPER18_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
98  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
99  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
100  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
101  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
102  cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
103  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
104  // stepper18_map // stepper18
107 
112 typedef struct
113 {
114  // Output pins
115  digital_out_t en;
116  digital_out_t dir;
117  digital_out_t slp;
118  digital_out_t stp;
120  // Input pins
121  digital_in_t flt;
123  // Modules
124  i2c_master_t i2c;
126  // I2C slave address
127  uint8_t slave_address;
129  // Motor stepps
130  uint16_t steps;
131  float resolution;
132 
133 
134 } stepper18_t;
135 
140 typedef struct
141 {
142  pin_name_t scl;
143  pin_name_t sda;
145  pin_name_t en;
146  pin_name_t dir;
147  pin_name_t slp;
148  pin_name_t stp;
149  pin_name_t flt;
151  uint32_t i2c_speed;
152  uint8_t i2c_address;
155 
160 typedef enum
161 {
163  STEPPER18_ERROR = -1
164 
166 
183 
198 err_t stepper18_init ( stepper18_t *ctx, stepper18_cfg_t *cfg );
199 
213 err_t stepper18_default_cfg ( stepper18_t *ctx );
214 
228 err_t stepper18_generic_write ( stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
229 
242 err_t stepper18_set_out_voltage ( stepper18_t *ctx, uint16_t voltage );
243 
252 void stepper18_set_dir ( stepper18_t *ctx, uint8_t value );
253 
262 void stepper18_set_slp ( stepper18_t *ctx, uint8_t value );
263 
272 void stepper18_set_en ( stepper18_t *ctx, uint8_t value );
273 
282 void stepper18_set_stp ( stepper18_t *ctx, uint8_t value );
283 
291 uint8_t stepper18_get_flt ( stepper18_t *ctx );
292 
321 void stepper18_move_motor_angle ( stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed );
322 
351 void stepper18_move_motor_step ( stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed );
352 
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 #endif // STEPPER18_H
367  // stepper18
369 
370 // ------------------------------------------------------------------------ END
STEPPER18_ERROR
Definition: stepper18.h:162
stepper18_calculate_resolution
void stepper18_calculate_resolution(stepper18_t *ctx)
Calculate step-degree resolution.
stepper18_return_value_t
stepper18_return_value_t
Stepper 18 Click return value data.
Definition: stepper18.h:159
stepper18_set_out_voltage
err_t stepper18_set_out_voltage(stepper18_t *ctx, uint16_t voltage)
Set voltage reference.
stepper18_set_slp
void stepper18_set_slp(stepper18_t *ctx, uint8_t value)
Set sleep.
stepper18_t
Stepper 18 Click context object.
Definition: stepper18.h:111
stepper18_get_flt
uint8_t stepper18_get_flt(stepper18_t *ctx)
Get fault.
stepper18_move_motor_step
void stepper18_move_motor_step(stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed)
Move motor in step value.
stepper18_set_en
void stepper18_set_en(stepper18_t *ctx, uint8_t value)
Set enable.
stepper18_init
err_t stepper18_init(stepper18_t *ctx, stepper18_cfg_t *cfg)
Stepper 18 initialization function.
stepper18_set_dir
void stepper18_set_dir(stepper18_t *ctx, uint8_t value)
Set direction.
stepper18_cfg_setup
void stepper18_cfg_setup(stepper18_cfg_t *cfg)
Stepper 18 configuration object setup function.
stepper18_generic_write
err_t stepper18_generic_write(stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
Writing function.
STEPPER18_OK
Definition: stepper18.h:161
stepper18_move_motor_angle
void stepper18_move_motor_angle(stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed)
Move motor in angle value.
stepper18_default_cfg
err_t stepper18_default_cfg(stepper18_t *ctx)
Stepper 18 default configuration function.
stepper18_set_stp
void stepper18_set_stp(stepper18_t *ctx, uint8_t value)
Set step state.
stepper18_cfg_t
Stepper 18 Click configuration object.
Definition: stepper18.h:139