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 "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 
63 #define STEPPER18_STEP_RES_FULL 1
64 #define STEPPER18_STEP_RES_HALF 2
65 #define STEPPER18_STEP_RES_QUARTER 4
66 #define STEPPER18_STEP_RES_1div8 8
67 #define STEPPER18_STEP_RES_1div16 16
68 #define STEPPER18_STEP_RES_1div32 32
69 #define STEPPER18_STEP_RES_1div64 64
70 #define STEPPER18_STEP_RES_1div128 128
71 #define STEPPER18_STEP_RES_1div256 256
72 
77 #define STEPPER18_SPEED_VERY_SLOW 1
78 #define STEPPER18_SPEED_SLOW 2
79 #define STEPPER18_SPEED_MEDIUM 3
80 #define STEPPER18_SPEED_FAST 4
81 #define STEPPER18_SPEED_VERY_FAST 5
82 
88 #define STEPPER18_SET_DEV_ADDR 0x60
89  // stepper18_set
91 
106 #define STEPPER18_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
108  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
109  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
110  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
111  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
113  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
114  // stepper18_map // stepper18
117 
122 typedef struct
123 {
124  // Output pins
125  digital_out_t en;
126  digital_out_t dir;
127  digital_out_t slp;
128  digital_out_t stp;
130  // Input pins
131  digital_in_t flt;
133  // Modules
134  i2c_master_t i2c;
136  // I2C slave address
137  uint8_t slave_address;
139  // Motor stepps
140  uint16_t steps;
141  float resolution;
142 
143 
144 } stepper18_t;
145 
150 typedef struct
151 {
152  pin_name_t scl;
153  pin_name_t sda;
155  pin_name_t en;
156  pin_name_t dir;
157  pin_name_t slp;
158  pin_name_t stp;
159  pin_name_t flt;
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
165 
170 typedef enum
171 {
173  STEPPER18_ERROR = -1
174 
176 
193 
209 
224 
238 err_t stepper18_generic_write ( stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
239 
252 err_t stepper18_set_out_voltage ( stepper18_t *ctx, uint16_t voltage );
253 
262 void stepper18_set_dir ( stepper18_t *ctx, uint8_t value );
263 
272 void stepper18_set_slp ( stepper18_t *ctx, uint8_t value );
273 
282 void stepper18_set_en ( stepper18_t *ctx, uint8_t value );
283 
292 void stepper18_set_stp ( stepper18_t *ctx, uint8_t value );
293 
302 
331 void stepper18_move_motor_angle ( stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed );
332 
361 void stepper18_move_motor_step ( stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed );
362 
372 
373 #ifdef __cplusplus
374 }
375 #endif
376 #endif // STEPPER18_H
377  // stepper18
379 
380 // ------------------------------------------------------------------------ END
STEPPER18_ERROR
@ STEPPER18_ERROR
Definition: stepper18.h:173
stepper18_calculate_resolution
void stepper18_calculate_resolution(stepper18_t *ctx)
Calculate step-degree resolution.
stepper18_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper18.h:162
stepper18_t::en
digital_out_t en
Definition: stepper18.h:125
stepper18_return_value_t
stepper18_return_value_t
Stepper 18 Click return value data.
Definition: stepper18.h:171
stepper18_cfg_t::sda
pin_name_t sda
Definition: stepper18.h:153
stepper18_cfg_t::slp
pin_name_t slp
Definition: stepper18.h:157
stepper18_set_out_voltage
err_t stepper18_set_out_voltage(stepper18_t *ctx, uint16_t voltage)
Set voltage reference.
stepper18_t::slp
digital_out_t slp
Definition: stepper18.h:127
stepper18_t::dir
digital_out_t dir
Definition: stepper18.h:126
stepper18_t::slave_address
uint8_t slave_address
Definition: stepper18.h:137
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:123
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_cfg_t::en
pin_name_t en
Definition: stepper18.h:155
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_t::i2c
i2c_master_t i2c
Definition: stepper18.h:134
stepper18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper18.h:161
stepper18_cfg_setup
void stepper18_cfg_setup(stepper18_cfg_t *cfg)
Stepper 18 configuration object setup function.
stepper18_t::resolution
float resolution
Definition: stepper18.h:141
stepper18_generic_write
err_t stepper18_generic_write(stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
Writing function.
stepper18_t::flt
digital_in_t flt
Definition: stepper18.h:131
STEPPER18_OK
@ STEPPER18_OK
Definition: stepper18.h:172
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_t::stp
digital_out_t stp
Definition: stepper18.h:128
stepper18_default_cfg
err_t stepper18_default_cfg(stepper18_t *ctx)
Stepper 18 default configuration function.
stepper18_cfg_t::stp
pin_name_t stp
Definition: stepper18.h:158
stepper18_set_stp
void stepper18_set_stp(stepper18_t *ctx, uint8_t value)
Set step state.
stepper18_cfg_t::flt
pin_name_t flt
Definition: stepper18.h:159
stepper18_t::steps
uint16_t steps
Definition: stepper18.h:140
stepper18_cfg_t::dir
pin_name_t dir
Definition: stepper18.h:156
stepper18_cfg_t
Stepper 18 Click configuration object.
Definition: stepper18.h:151
stepper18_cfg_t::scl
pin_name_t scl
Definition: stepper18.h:152