stepper16 2.0.0.0
stepper16.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 STEPPER16_H
29#define STEPPER16_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#include "drv_spi_master.h"
52
73#define STEPPER16_REG_CR1 0x01
74#define STEPPER16_REG_CR2 0x02
75#define STEPPER16_REG_CR3 0x03
76#define STEPPER16_REG_CR4 0x04
77#define STEPPER16_REG_CR5 0x0B
78#define STEPPER16_REG_CR6 0x0C
79#define STEPPER16_REG_SR1 0x05
80#define STEPPER16_REG_SR2 0x06
81#define STEPPER16_REG_SR3 0x07
82#define STEPPER16_REG_SR4 0x08
83#define STEPPER16_REG_SR5 0x09
84#define STEPPER16_REG_SR6 0x0A
85
86 // stepper16_reg
87
102#define STEPPER16_STEP_RES_FULL 0x7
103#define STEPPER16_STEP_RES_HALF 0x3
104#define STEPPER16_STEP_RES_QUARTER 0x2
105#define STEPPER16_STEP_RES_1div8 0x1
106#define STEPPER16_STEP_RES_1div16 0x0
107
112#define STEPPER16_SPEED_VERY_SLOW 1
113#define STEPPER16_SPEED_SLOW 2
114#define STEPPER16_SPEED_MEDIUM 3
115#define STEPPER16_SPEED_FAST 4
116#define STEPPER16_SPEED_VERY_FAST 5
117
118 // stepper16_set
119
134#define STEPPER16_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
136 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
137 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
138 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
139 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
140 cfg.nxt = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
141 cfg.err = MIKROBUS( mikrobus, MIKROBUS_INT )
142
143 // stepper16_map
144 // stepper16
145
150typedef struct
151{
152 // Output pins
153 digital_out_t dir;
154 digital_out_t nxt;
155 digital_out_t cs;
157 // Input pins
158 digital_in_t err;
160 // Modules
161 spi_master_t spi;
162 pin_name_t chip_select;
164 //status bits
165 uint8_t spierr;
166 uint8_t uv;
167 uint8_t eldef;
168 uint8_t tsd;
169 uint8_t tw;
171 uint16_t steps;
176
181typedef struct
182{
183 // Communication gpio pins
184 pin_name_t miso;
185 pin_name_t mosi;
186 pin_name_t sck;
187 pin_name_t cs;
189 // Additional gpio pins
190 pin_name_t dir;
191 pin_name_t nxt;
192 pin_name_t err;
194 // static variable
195 uint32_t spi_speed;
196 spi_master_mode_t spi_mode;
197 spi_master_chip_select_polarity_t cs_polarity;
200
211
228
243
258
272err_t stepper16_generic_write ( stepper16_t *ctx, uint8_t reg, uint16_t data_in );
273
287err_t stepper16_generic_read ( stepper16_t *ctx, uint8_t reg, uint16_t *data_out );
288
297void stepper16_set_next ( stepper16_t *ctx, uint8_t value );
298
307void stepper16_set_dir ( stepper16_t *ctx, uint8_t value );
308
317
328
337
351void stepper16_set_step_resolution ( stepper16_t *ctx, uint8_t step_res );
352
367void stepper16_move_motor_angle ( stepper16_t *ctx, float degree, uint8_t speed );
368
383void stepper16_move_motor_step ( stepper16_t *ctx, uint16_t steps, uint8_t speed );
384
394
395#ifdef __cplusplus
396}
397#endif
398#endif // STEPPER16_H
399
400 // stepper16
401
402// ------------------------------------------------------------------------ END
void stepper16_wake_up(stepper16_t *ctx)
Transimt wake up signal.
void stepper16_hard_reset(stepper16_t *ctx)
Resets device.
err_t stepper16_default_cfg(stepper16_t *ctx)
Stepper16 default configuration function.
void stepper16_cfg_setup(stepper16_cfg_t *cfg)
Stepper16 configuration object setup function.
err_t stepper16_init(stepper16_t *ctx, stepper16_cfg_t *cfg)
Stepper16 initialization function.
err_t stepper16_generic_read(stepper16_t *ctx, uint8_t reg, uint16_t *data_out)
Stepper16 data reading function.
err_t stepper16_generic_write(stepper16_t *ctx, uint8_t reg, uint16_t data_in)
Stepper16 data writing function.
void stepper16_move_motor_step(stepper16_t *ctx, uint16_t steps, uint8_t speed)
Move motor in step value.
void stepper16_calculate_resolution(stepper16_t *ctx)
Calculate step-degree resolution.
void stepper16_set_next(stepper16_t *ctx, uint8_t value)
Set next step state.
void stepper16_set_dir(stepper16_t *ctx, uint8_t value)
Set direction.
uint8_t stepper16_get_error_flag(stepper16_t *ctx)
Get error.
void stepper16_set_step_resolution(stepper16_t *ctx, uint8_t step_res)
Set step resolution.
void stepper16_move_motor_angle(stepper16_t *ctx, float degree, uint8_t speed)
Move motor in angle value.
stepper16_return_value_t
Stepper16 Click return value data.
Definition stepper16.h:206
@ STEPPER16_ERROR
Definition stepper16.h:208
@ STEPPER16_OK
Definition stepper16.h:207
Stepper16 Click configuration object.
Definition stepper16.h:182
pin_name_t nxt
Definition stepper16.h:191
spi_master_chip_select_polarity_t cs_polarity
Definition stepper16.h:197
pin_name_t sck
Definition stepper16.h:186
pin_name_t err
Definition stepper16.h:192
spi_master_mode_t spi_mode
Definition stepper16.h:196
pin_name_t mosi
Definition stepper16.h:185
uint32_t spi_speed
Definition stepper16.h:195
pin_name_t dir
Definition stepper16.h:190
pin_name_t miso
Definition stepper16.h:184
pin_name_t cs
Definition stepper16.h:187
Stepper16 Click context object.
Definition stepper16.h:151
digital_out_t cs
Definition stepper16.h:155
spi_master_t spi
Definition stepper16.h:161
uint16_t steps
Definition stepper16.h:171
uint8_t uv
Definition stepper16.h:166
float resolution
Definition stepper16.h:172
uint8_t step_resolution
Definition stepper16.h:173
uint8_t tw
Definition stepper16.h:169
digital_out_t nxt
Definition stepper16.h:154
uint8_t spierr
Definition stepper16.h:165
digital_in_t err
Definition stepper16.h:158
pin_name_t chip_select
Definition stepper16.h:162
uint8_t tsd
Definition stepper16.h:168
uint8_t eldef
Definition stepper16.h:167
digital_out_t dir
Definition stepper16.h:153