#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;