stepper3 2.1.0.0
stepper3.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 STEPPER3_H
29#define STEPPER3_H
30
31#ifdef __cplusplus
32extern "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
72#define STEPPER3_DIR_CW 0
73#define STEPPER3_DIR_CCW 1
74
79#define STEPPER3_PIN_LOW_LEVEL 0
80#define STEPPER3_PIN_HIGH_LEVEL 1
81
86#define STEPPER3_MODE_FULL_STEP 0
87#define STEPPER3_MODE_HALF_STEP 1
88
93#define STEPPER3_MICROSTEP_NUM_PER_STEP 32
94
99#define STEPPER3_SPEED_VERY_SLOW 0
100#define STEPPER3_SPEED_SLOW 1
101#define STEPPER3_SPEED_MEDIUM 2
102#define STEPPER3_SPEED_FAST 3
103#define STEPPER3_SPEED_VERY_FAST 4
104
105 // stepper3_set
106
121#define STEPPER3_MAP_MIKROBUS( cfg, mikrobus ) \
122 cfg.ina = MIKROBUS( mikrobus, MIKROBUS_AN ); \
123 cfg.inb = MIKROBUS( mikrobus, MIKROBUS_RST ); \
124 cfg.inc = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125 cfg.ind = MIKROBUS( mikrobus, MIKROBUS_PWM );
126
127 // stepper3_map
128 // stepper3
129
134typedef struct
135{
136 digital_out_t ina;
137 digital_out_t inb;
138 digital_out_t inc;
139 digital_out_t ind;
141 uint8_t step_mode;
142 uint8_t direction;
144} stepper3_t;
145
150typedef struct
151{
152 pin_name_t ina;
153 pin_name_t inb;
154 pin_name_t inc;
155 pin_name_t ind;
158
163typedef enum
164{
166 STEPPER3_ERROR = -1
167
169
186
201
212void stepper3_set_ina_pin ( stepper3_t *ctx, uint8_t state );
213
224void stepper3_set_inb_pin ( stepper3_t *ctx, uint8_t state );
225
236void stepper3_set_inc_pin ( stepper3_t *ctx, uint8_t state );
237
248void stepper3_set_ind_pin ( stepper3_t *ctx, uint8_t state );
249
261void stepper3_set_step_mode ( stepper3_t *ctx, uint8_t mode );
262
273void stepper3_set_direction ( stepper3_t *ctx, uint8_t dir );
274
284
294
304
320void stepper3_drive_motor ( stepper3_t *ctx, uint32_t steps, uint8_t speed );
321
322#ifdef __cplusplus
323}
324#endif
325#endif // STEPPER3_H
326
327 // stepper3
328
329// ------------------------------------------------------------------------ END
void stepper3_disable_device(stepper3_t *ctx)
Stepper 3 disable device function.
void stepper3_drive_motor(stepper3_t *ctx, uint32_t steps, uint8_t speed)
Stepper 3 driver motor function.
void stepper3_enable_device(stepper3_t *ctx)
Stepper 3 enable device function.
void stepper3_set_inc_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set inc pin function.
void stepper3_set_direction(stepper3_t *ctx, uint8_t dir)
Stepper 3 set direction function.
void stepper3_set_ind_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set ind pin function.
void stepper3_set_ina_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set ina pin function.
void stepper3_cfg_setup(stepper3_cfg_t *cfg)
Stepper 3 configuration object setup function.
void stepper3_set_step_mode(stepper3_t *ctx, uint8_t mode)
Stepper 3 set step mode function.
err_t stepper3_init(stepper3_t *ctx, stepper3_cfg_t *cfg)
Stepper 3 initialization function.
void stepper3_set_inb_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set inb pin function.
void stepper3_switch_direction(stepper3_t *ctx)
Stepper 3 switch direction function.
stepper3_return_value_t
Stepper 3 Click return value data.
Definition stepper3.h:164
@ STEPPER3_ERROR
Definition stepper3.h:166
@ STEPPER3_OK
Definition stepper3.h:165
Stepper 3 Click configuration object.
Definition stepper3.h:151
pin_name_t inc
Definition stepper3.h:154
pin_name_t ina
Definition stepper3.h:152
pin_name_t ind
Definition stepper3.h:155
pin_name_t inb
Definition stepper3.h:153
Stepper 3 Click context object.
Definition stepper3.h:135
digital_out_t inc
Definition stepper3.h:138
uint8_t step_mode
Definition stepper3.h:141
digital_out_t inb
Definition stepper3.h:137
digital_out_t ina
Definition stepper3.h:136
uint8_t direction
Definition stepper3.h:142
digital_out_t ind
Definition stepper3.h:139