步进电机使用总结
1、步进电机励磁顺序
2、驱动电路
3、步进电机驱动芯片
UPA1759G 为NMOS。
4、需要注意的几点:
1) 我们使用的步进电机 800pps为最佳。
2) 使用定时器定时880pps即1250us执行一拍
3) 步进电机为共阳极,驱动器为NMOS的UPA1759G。软件处理时需要反向驱动处理
4) 步进电机的执行一次尽量整步(8拍的倍数)执行
5) 步进电机正反向转动时,不应清除当前8拍计数值,而是进行正向加,反向减。
5、步进电机驱动程序
/**********************************************************************
* step_motor.c
* 步进电机执行模块
* 模块功能:按照调用执行相应步进电机的相应步数
* 保存各个步进电机当前的状态(当前所走步数、是否达到目标位置)
*********************************************************************/
#include <config.h>
#include <axentone_io_setting.h>
#include <f_arch.h>
/**********需要修改的部分 start******************************************************/
// 步进电机旋转方向
#define VALVE_ONE_MOTOR_POS_AS_CLOCK_WISE 1
#define VALVE_TWO_MOTOR_POS_AS_CLOCK_WISE 0
#define NOZZLE_MOTOR_POS_AS_CLOCK_WISE 0
#define HIGH 1 // 表示高低电平
#define LOW 0
/**********需要修改的部分 end******************************************************/
#define MOTOR_INTERVAL_US 1250 // 1300 //500 // 370 // 700 // 1300 // 步进电机每步间隔时间 64us的整数倍1280us
/* 步进电机时序 */
static const uint8 _pos_mode[8] ={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01}; // positive eightbeat
static const uint8 _neg_mode[8] ={0x01,0x03,0x02,0x06,0x04,0x0C,0x08,0x09}; // negative eightbeat
#if(VALVE_ONE_MOTOR_POS_AS_CLOCK_WISE == 1)
static const uint8 *valve_one_motor_pos= _pos_mode;
#else
static const uint8 *valve_one_motor_pos= _neg_mode;
#endif
#if(VALVE_TWO_MOTOR_POS_AS_CLOCK_WISE == 1)
static const uint8 *valve_two_motor_pos= _pos_mode;
#else
static const uint8 *valve_two_motor_pos= _neg_mode;
#endif
#if(NOZZLE_MOTOR_POS_AS_CLOCK_WISE == 1)
static const uint8 *nozzle_motor_pos = _pos_mode;
#else
static const uint8 *nozzle_motor_pos = _neg_mode;
#endif
/*******************************************************************************************/
//让外部检测步进电机是否已经达到目标位置
struct _motors_ok
{
unsignedvalve_one_motor_ok: 1;
unsignedvalve_two_motor_ok: 1;
unsignednozzle_motor_ok: 1;
};
static struct _motors_ok motors = {
1,
1,
1,
};
uint8 is_valve_one_motor_ok(void)
{
returnmotors.valve_one_motor_ok;
}
uint8 is_valve_two_motor_ok(void)
{
returnmotors.valve_two_motor_ok;
}
uint8 is_nozzle_motor_ok(void)
{
returnmotors.nozzle_motor_ok;
}
static void waiting_for_motors_ok(void)
{
overlay uint8 i = 0;
while(!motors.valve_one_motor_ok||
!motors.valve_two_motor_ok||
!motors.nozzle_motor_ok)
for(i= 0; i < 200; i++) feed_wdt();
}
/*******************************************************************************************/
/*******************************************************************************************/
// 实时记录每个步进电机的步数和拍数
static int16 valve_one_motor_current = 0;
static int16 valve_one_motor_target = 0;