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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
67 #define STEPPER18_STEP_RES_FULL 1
68 #define STEPPER18_STEP_RES_HALF 2
69 #define STEPPER18_STEP_RES_QUARTER 4
70 #define STEPPER18_STEP_RES_1div8 8
71 #define STEPPER18_STEP_RES_1div16 16
72 #define STEPPER18_STEP_RES_1div32 32
73 #define STEPPER18_STEP_RES_1div64 64
74 #define STEPPER18_STEP_RES_1div128 128
75 #define STEPPER18_STEP_RES_1div256 256
76 
81 #define STEPPER18_SPEED_VERY_SLOW 1
82 #define STEPPER18_SPEED_SLOW 2
83 #define STEPPER18_SPEED_MEDIUM 3
84 #define STEPPER18_SPEED_FAST 4
85 #define STEPPER18_SPEED_VERY_FAST 5
86 
92 #define STEPPER18_SET_DEV_ADDR 0x60
93  // stepper18_set
95 
110 #define STEPPER18_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
112  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
113  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
114  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116  cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
117  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
118  // stepper18_map // stepper18
121 
126 typedef struct
127 {
128  // Output pins
129  digital_out_t en;
130  digital_out_t dir;
131  digital_out_t slp;
132  digital_out_t stp;
134  // Input pins
135  digital_in_t flt;
137  // Modules
138  i2c_master_t i2c;
140  // I2C slave address
141  uint8_t slave_address;
143  // Motor stepps
144  uint16_t steps;
145  float resolution;
146 
147 
148 } stepper18_t;
149 
154 typedef struct
155 {
156  pin_name_t scl;
157  pin_name_t sda;
159  pin_name_t en;
160  pin_name_t dir;
161  pin_name_t slp;
162  pin_name_t stp;
163  pin_name_t flt;
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
169 
174 typedef enum
175 {
177  STEPPER18_ERROR = -1
178 
180 
197 
213 
228 
242 err_t stepper18_generic_write ( stepper18_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
243 
256 err_t stepper18_set_out_voltage ( stepper18_t *ctx, uint16_t voltage );
257 
266 void stepper18_set_dir ( stepper18_t *ctx, uint8_t value );
267 
276 void stepper18_set_slp ( stepper18_t *ctx, uint8_t value );
277 
286 void stepper18_set_en ( stepper18_t *ctx, uint8_t value );
287 
296 void stepper18_set_stp ( stepper18_t *ctx, uint8_t value );
297 
306 
335 void stepper18_move_motor_angle ( stepper18_t *ctx, float degree, uint8_t step_res, uint8_t speed );
336 
365 void stepper18_move_motor_step ( stepper18_t *ctx, uint16_t steps, uint8_t step_res, uint8_t speed );
366 
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 #endif // STEPPER18_H
381  // stepper18
383 
384 // ------------------------------------------------------------------------ END
STEPPER18_ERROR
@ STEPPER18_ERROR
Definition: stepper18.h:177
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:166
stepper18_t::en
digital_out_t en
Definition: stepper18.h:129
stepper18_return_value_t
stepper18_return_value_t
Stepper 18 Click return value data.
Definition: stepper18.h:175
stepper18_cfg_t::sda
pin_name_t sda
Definition: stepper18.h:157
stepper18_cfg_t::slp
pin_name_t slp
Definition: stepper18.h:161
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:131
stepper18_t::dir
digital_out_t dir
Definition: stepper18.h:130
stepper18_t::slave_address
uint8_t slave_address
Definition: stepper18.h:141
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:127
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:159
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:138
stepper18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper18.h:165
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:145
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:135
STEPPER18_OK
@ STEPPER18_OK
Definition: stepper18.h:176
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:132
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:162
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:163
stepper18_t::steps
uint16_t steps
Definition: stepper18.h:144
stepper18_cfg_t::dir
pin_name_t dir
Definition: stepper18.h:160
stepper18_cfg_t
Stepper 18 Click configuration object.
Definition: stepper18.h:155
stepper18_cfg_t::scl
pin_name_t scl
Definition: stepper18.h:156