stm32 T型加速控制步进电机



#define  AXIS_PULSE_0    GPIO_Pin_8
#define  AXIS_PULSE_1    GPIO_Pin_2
#define  AXIS_PULSE_2    GPIO_Pin_7
#define  AXIS_PULSE_3    GPIO_Pin_3

u16 AxisPulsePin[4] = {AXIS_PULSE_0, AXIS_PULSE_1, AXIS_PULSE_2, AXIS_PULSE_3};// pa8, pa2, pa7, pa3
u16 AxisDirPin[4] = {GPIO_Pin_0, GPIO_Pin_2, GPIO_Pin_3, GPIO_Pin_13}; // pc0, pc2, pc3, pc13

double tim_count_num = 1000000;
#define step_psc 71

#define STOP  0 //停止
#define ACCEL 1 //加速
#define DECEL 2 //减速
#define RUN   3 //最大速度运行
#define PAUSE 4 //减速停止

AxisData axisData[4];  //工作状态

void get_ad_step(long steps, double start_speed, double max_speed, double a_speed, double d_speed, int *a_step, int *d_step){
 int a, d;
 double count = 0;
 double v = start_speed;
 a = 1;
 d = 1;
 while(v < max_speed){
  v += a_speed/v;
  a ++;
 }
 v = start_speed;
 while(v < max_speed){
  v += d_speed/v;
  d++;
 }
 if(a + d <= steps){
  *a_step = a;
  *d_step = d;
 }else{
  *a_step = steps * a /(a + d);
  *d_step = steps - *a_step;
 }
}

void init_axis_data(int ax, long steps, double start_speed, double max_speed, double a_speed, double d_speed)
{
 int a_step, d_step;
 get_ad_step(steps, start_speed, max_speed, a_speed, d_speed, &a_step, &d_step);
 
 if(steps >= 0)
 {
  axisData[ax].dir = 1;
  axisData[ax].step_count = steps;
 }else{
  axisData[ax].dir = -1;
  axisData[ax].step_count = -steps;
 }
 axisData[ax].start_speed = start_speed;
 axisData[ax].cur_speed = start_speed;
 axisData[ax].max_speed = max_speed;
 axisData[ax].a_speed = a_speed;
 axisData[ax].d_speed = d_speed;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值