stepper17  2.0.0.0
stepper17.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 STEPPER17_H
29 #define STEPPER17_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_pwm.h"
39 
60 #define STEPPER17_REG_INPUT_PORT0 0x00
61 #define STEPPER17_REG_INPUT_PORT1 0x01
62 #define STEPPER17_REG_OUTPUT_PORT0 0x02
63 #define STEPPER17_REG_OUTPUT_PORT1 0x03
64 #define STEPPER17_REG_POLARITY_INVERSION_PORT0 0x04
65 #define STEPPER17_REG_POLARITY_INVERSION_PORT1 0x05
66 #define STEPPER17_REG_CONFIGUARTION_PORT0 0x06
67 #define STEPPER17_REG_CONFIGUARTION_PORT1 0x07
68  // stepper17_reg
70 
85 #define STEPPER17_MODE_SLEEP 0x00
86 #define STEPPER17_MODE_NORMAL 0x80
87 
92 #define STEPPER17_STEP_FULL 0x00
93 #define STEPPER17_STEP_HALF_A 0x04
94 #define STEPPER17_STEP_HALF_B 0x02
95 #define STEPPER17_STEP_QUARTER 0x06
96 #define STEPPER17_STEP_1DIV8 0x01
97 #define STEPPER17_STEP_1DIV16 0x05
98 #define STEPPER17_STEP_1DIV32 0x07
99 
104 #define STEPPER17_DECAY_MIXED 0x00
105 #define STEPPER17_DECAY_SLOW 0x08
106 #define STEPPER17_DECAY_FAST 0x10
107 #define STEPPER17_DECAY_ADMD 0x18
108 
113 #define STEPPER17_TORQUE_100PCT 0x00
114 #define STEPPER17_TORQUE_75PCT 0x20
115 #define STEPPER17_TORQUE_50PCT 0x40
116 #define STEPPER17_TORQUE_25PCT 0x60
117 
123 #define STEPPER17_SET_DEV_ADDR 0x20
124 
125 
130 #define STEPPER17_DEF_FREQ 1500
131  // stepper17_set
133 
148 #define STEPPER17_MAP_MIKROBUS( cfg, mikrobus ) \
149  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
150  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
151  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
152  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
153  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
154  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
155  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156  // stepper17_map // stepper17
159 
164 typedef struct
165 {
166  // Output pins
167 
168  digital_out_t en;
169  digital_out_t dir;
170  digital_out_t rst;
172  // Input pins
173 
174  digital_in_t int_pin;
176  // Modules
177 
178  i2c_master_t i2c;
179  pwm_t pwm;
180 
181  // I2C slave address
182 
183  uint8_t slave_address;
184  uint32_t pwm_freq;
185 
186 } stepper17_t;
187 
192 typedef struct
193 {
194  pin_name_t scl;
195  pin_name_t sda;
197  pin_name_t en;
198  pin_name_t dir;
199  pin_name_t rst;
200  pin_name_t clk;
201  pin_name_t int_pin;
203  uint32_t i2c_speed;
204  uint8_t i2c_address;
205  uint32_t dev_pwm_freq;
206 
208 
213 typedef enum
214 {
216  STEPPER17_ERROR = -1
217 
219 
238 
255 err_t stepper17_init ( stepper17_t *ctx, stepper17_cfg_t *cfg );
256 
272 err_t stepper17_default_cfg ( stepper17_t *ctx );
273 
291 err_t stepper17_generic_write ( stepper17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
292 
310 err_t stepper17_generic_read ( stepper17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
311 
323 err_t stepper17_set_duty_cycle ( stepper17_t *ctx, float duty_cycle );
324 
335 err_t stepper17_pwm_stop ( stepper17_t *ctx );
336 
347 err_t stepper17_pwm_start ( stepper17_t *ctx );
348 
357 void stepper17_set_dir_state ( stepper17_t *ctx, uint8_t state );
358 
367 void stepper17_set_rst_state ( stepper17_t *ctx, uint8_t state );
368 
377 void stepper17_set_en_state ( stepper17_t *ctx, uint8_t state );
378 
388 uint8_t stepper17_get_int_state ( stepper17_t *ctx );
389 
401 err_t stepper17_step_resolution ( stepper17_t *ctx, uint8_t resolution );
402 
414 err_t stepper17_torque_setting ( stepper17_t *ctx, uint8_t torque );
415 
427 err_t stepper17_decay_function ( stepper17_t *ctx, uint8_t decay );
428 
440 err_t stepper17_mode ( stepper17_t *ctx, uint8_t mode );
441 
452 uint8_t stepper17_get_error ( stepper17_t *ctx );
453 
464 
475 
476 #ifdef __cplusplus
477 }
478 #endif
479 #endif // STEPPER17_H
480  // stepper17
482 
483 // ------------------------------------------------------------------------ END
STEPPER17_OK
Definition: stepper17.h:214
stepper17_return_value_t
stepper17_return_value_t
Stepper 17 Click return value data.
Definition: stepper17.h:212
stepper17_get_electrical_angle
uint8_t stepper17_get_electrical_angle(stepper17_t *ctx)
Reads MO pin state.
stepper17_t
Stepper 17 Click context object.
Definition: stepper17.h:163
stepper17_set_duty_cycle
err_t stepper17_set_duty_cycle(stepper17_t *ctx, float duty_cycle)
Stepper 17 sets PWM duty cycle.
stepper17_generic_read
err_t stepper17_generic_read(stepper17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Stepper 17 I2C reading function.
stepper17_get_int_state
uint8_t stepper17_get_int_state(stepper17_t *ctx)
Gets interrupt state.
stepper17_mode
err_t stepper17_mode(stepper17_t *ctx, uint8_t mode)
Mode setting.
stepper17_get_error
uint8_t stepper17_get_error(stepper17_t *ctx)
Reads error output.
stepper17_reset_electrical_angle
void stepper17_reset_electrical_angle(stepper17_t *ctx)
Reset electrical angle to initial state.
stepper17_init
err_t stepper17_init(stepper17_t *ctx, stepper17_cfg_t *cfg)
Stepper 17 initialization function.
stepper17_pwm_start
err_t stepper17_pwm_start(stepper17_t *ctx)
Stepper 17 start PWM module.
STEPPER17_ERROR
Definition: stepper17.h:215
stepper17_torque_setting
err_t stepper17_torque_setting(stepper17_t *ctx, uint8_t torque)
Torque setting.
stepper17_generic_write
err_t stepper17_generic_write(stepper17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Stepper 17 I2C writing function.
stepper17_default_cfg
err_t stepper17_default_cfg(stepper17_t *ctx)
Stepper 17 default configuration function.
stepper17_set_en_state
void stepper17_set_en_state(stepper17_t *ctx, uint8_t state)
Enable stepping motor output.
stepper17_decay_function
err_t stepper17_decay_function(stepper17_t *ctx, uint8_t decay)
Decay period setting.
stepper17_cfg_t
Stepper 17 Click configuration object.
Definition: stepper17.h:191
stepper17_set_dir_state
void stepper17_set_dir_state(stepper17_t *ctx, uint8_t state)
Direction control.
stepper17_set_rst_state
void stepper17_set_rst_state(stepper17_t *ctx, uint8_t state)
Set reset pin state.
stepper17_cfg_setup
void stepper17_cfg_setup(stepper17_cfg_t *cfg)
Stepper 17 configuration object setup function.
stepper17_pwm_stop
err_t stepper17_pwm_stop(stepper17_t *ctx)
Stepper 17 stop PWM module.
stepper17_step_resolution
err_t stepper17_step_resolution(stepper17_t *ctx, uint8_t resolution)
Step resolution setting.