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
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 
68 #define STEPPER3_DIR_CW 0
69 #define STEPPER3_DIR_CCW 1
70 
75 #define STEPPER3_PIN_LOW_LEVEL 0
76 #define STEPPER3_PIN_HIGH_LEVEL 1
77 
82 #define STEPPER3_MODE_FULL_STEP 0
83 #define STEPPER3_MODE_HALF_STEP 1
84 
89 #define STEPPER3_MICROSTEP_NUM_PER_STEP 32
90 
95 #define STEPPER3_SPEED_VERY_SLOW 0
96 #define STEPPER3_SPEED_SLOW 1
97 #define STEPPER3_SPEED_MEDIUM 2
98 #define STEPPER3_SPEED_FAST 3
99 #define STEPPER3_SPEED_VERY_FAST 4
100  // stepper3_set
102 
117 #define STEPPER3_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.ina = MIKROBUS( mikrobus, MIKROBUS_AN ); \
119  cfg.inb = MIKROBUS( mikrobus, MIKROBUS_RST ); \
120  cfg.inc = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.ind = MIKROBUS( mikrobus, MIKROBUS_PWM );
122  // stepper3_map // stepper3
125 
130 typedef struct
131 {
132  digital_out_t ina;
133  digital_out_t inb;
134  digital_out_t inc;
135  digital_out_t ind;
137  uint8_t step_mode;
138  uint8_t direction;
140 } stepper3_t;
141 
146 typedef struct
147 {
148  pin_name_t ina;
149  pin_name_t inb;
150  pin_name_t inc;
151  pin_name_t ind;
154 
159 typedef enum
160 {
162  STEPPER3_ERROR = -1
163 
165 
182 
197 
208 void stepper3_set_ina_pin ( stepper3_t *ctx, uint8_t state );
209 
220 void stepper3_set_inb_pin ( stepper3_t *ctx, uint8_t state );
221 
232 void stepper3_set_inc_pin ( stepper3_t *ctx, uint8_t state );
233 
244 void stepper3_set_ind_pin ( stepper3_t *ctx, uint8_t state );
245 
257 void stepper3_set_step_mode ( stepper3_t *ctx, uint8_t mode );
258 
269 void stepper3_set_direction ( stepper3_t *ctx, uint8_t dir );
270 
280 
290 
300 
316 void stepper3_drive_motor ( stepper3_t *ctx, uint32_t steps, uint8_t speed );
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // STEPPER3_H
322  // stepper3
324 
325 // ------------------------------------------------------------------------ END
stepper3_disable_device
void stepper3_disable_device(stepper3_t *ctx)
Stepper 3 disable device function.
stepper3_enable_device
void stepper3_enable_device(stepper3_t *ctx)
Stepper 3 enable device function.
stepper3_set_ina_pin
void stepper3_set_ina_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set ina pin function.
stepper3_cfg_t::inb
pin_name_t inb
Definition: stepper3.h:149
stepper3_t::ind
digital_out_t ind
Definition: stepper3.h:135
stepper3_cfg_t
Stepper 3 Click configuration object.
Definition: stepper3.h:147
stepper3_t
Stepper 3 Click context object.
Definition: stepper3.h:131
stepper3_init
err_t stepper3_init(stepper3_t *ctx, stepper3_cfg_t *cfg)
Stepper 3 initialization function.
stepper3_return_value_t
stepper3_return_value_t
Stepper 3 Click return value data.
Definition: stepper3.h:160
stepper3_set_direction
void stepper3_set_direction(stepper3_t *ctx, uint8_t dir)
Stepper 3 set direction function.
stepper3_set_ind_pin
void stepper3_set_ind_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set ind pin function.
stepper3_set_inc_pin
void stepper3_set_inc_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set inc pin function.
STEPPER3_OK
@ STEPPER3_OK
Definition: stepper3.h:161
stepper3_t::direction
uint8_t direction
Definition: stepper3.h:138
stepper3_cfg_t::ind
pin_name_t ind
Definition: stepper3.h:151
stepper3_switch_direction
void stepper3_switch_direction(stepper3_t *ctx)
Stepper 3 switch direction function.
stepper3_t::inc
digital_out_t inc
Definition: stepper3.h:134
stepper3_drive_motor
void stepper3_drive_motor(stepper3_t *ctx, uint32_t steps, uint8_t speed)
Stepper 3 driver motor function.
stepper3_t::inb
digital_out_t inb
Definition: stepper3.h:133
stepper3_set_inb_pin
void stepper3_set_inb_pin(stepper3_t *ctx, uint8_t state)
Stepper 3 set inb pin function.
stepper3_cfg_t::inc
pin_name_t inc
Definition: stepper3.h:150
STEPPER3_ERROR
@ STEPPER3_ERROR
Definition: stepper3.h:162
stepper3_cfg_t::ina
pin_name_t ina
Definition: stepper3.h:148
stepper3_t::ina
digital_out_t ina
Definition: stepper3.h:132
stepper3_cfg_setup
void stepper3_cfg_setup(stepper3_cfg_t *cfg)
Stepper 3 configuration object setup function.
stepper3_set_step_mode
void stepper3_set_step_mode(stepper3_t *ctx, uint8_t mode)
Stepper 3 set step mode function.
stepper3_t::step_mode
uint8_t step_mode
Definition: stepper3.h:137