152 lines
3.2 KiB
C
152 lines
3.2 KiB
C
/*
|
||
* @Author: wujunchao 24472040@qq.com
|
||
* @Date: 2024-10-14 14:42:21
|
||
* @LastEditors: wujunchao 24472040@qq.com
|
||
* @LastEditTime: 2024-10-15 17:15:02
|
||
* @FilePath: \mfps\App\Src\uniform.c
|
||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||
*/
|
||
#include "uniform.h"
|
||
//2024_10_14新增功能:匀速往/返运动,要求速度可调
|
||
//为避免与旧程序冲突,使用↑↓组合键对[OLED,Key,LED]程序进行切换
|
||
|
||
uint32_t uniform_speed;
|
||
uint32_t uniform_speed_prv;
|
||
uint8_t limit_old = 0;
|
||
|
||
void uniform_motion(void)
|
||
{
|
||
switch (uniform_limit(200, 1800))
|
||
{
|
||
case 0:
|
||
{
|
||
if(limit_old != 0)
|
||
{
|
||
OLED_ShowString(0,6,"-----",16,0);
|
||
OLED_ShowString(64,6,"-----",16,0);
|
||
|
||
limit_old = 0;
|
||
}
|
||
|
||
}
|
||
break;
|
||
|
||
case 1:
|
||
{
|
||
if(limit_old != 1)
|
||
{
|
||
OLED_ShowCN(0,6,20,0); //正常“到”,第6页
|
||
OLED_ShowCN(20,6,21,0); //正常“达”,第6页
|
||
|
||
GREEN_OFF;
|
||
BLUE_ON;
|
||
|
||
limit_old = 1;
|
||
}
|
||
disp_new = 1;
|
||
return;
|
||
}
|
||
|
||
case 2:
|
||
{
|
||
if(limit_old != 2)
|
||
{
|
||
OLED_ShowCN(64,6,20,0); //正常“到”,第6页
|
||
OLED_ShowCN(84,6,21,0); //正常“达”,第6页
|
||
|
||
GREEN_ON;
|
||
BLUE_OFF;
|
||
|
||
limit_old = 2;
|
||
}
|
||
disp_new = 1;
|
||
return;
|
||
}
|
||
|
||
default:
|
||
break;
|
||
}
|
||
|
||
switch (direc_select)
|
||
{
|
||
case 0: //正向运动
|
||
{
|
||
tmc5160_operate(1,51200*60);
|
||
|
||
if(it_500ms_flag)
|
||
{
|
||
it_500ms_flag = 0;
|
||
|
||
GREEN_TOG;
|
||
BLUE_OFF;
|
||
}
|
||
}
|
||
break;
|
||
|
||
case 1: //反向运动
|
||
{
|
||
tmc5160_operate(2,51200*60);
|
||
|
||
if(it_500ms_flag)
|
||
{
|
||
it_500ms_flag = 0;
|
||
|
||
GREEN_OFF;
|
||
BLUE_TOG;
|
||
}
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
char uniform_limit(float start, float end)
|
||
{
|
||
if( ( ocin1 == 0 )&&( direc_select != 0 ) )
|
||
{
|
||
//电机停止
|
||
tmc5160_operate(0,0);
|
||
return 1;
|
||
}
|
||
if( ( ocin2 == 0 )&&( direc_select != 1 ) )
|
||
{
|
||
//电机停止
|
||
tmc5160_operate(0,0);
|
||
return 2;
|
||
}
|
||
|
||
if( ( X_ads1220 <= start )&&( direc_select != 0 ) )
|
||
{
|
||
//电机停止
|
||
tmc5160_operate(0,0);
|
||
return 1;
|
||
}
|
||
if( ( X_ads1220 >= end )&&( direc_select != 1 ) )
|
||
{
|
||
//电机停止
|
||
tmc5160_operate(0,0);
|
||
return 2;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
void speed_set(uint32_t uni_speed)
|
||
{
|
||
if(uni_speed != uniform_speed)
|
||
{
|
||
uniform_speed =uni_speed;
|
||
uniform_speed_prv = uniform_speed;
|
||
|
||
//VMAX
|
||
TMC5160_SPIWriteInt(VMAX_ADDR, uniform_speed,1);
|
||
//V1
|
||
TMC5160_SPIWriteInt(V1_ADDR, uniform_speed/2,1);
|
||
}
|
||
}
|
||
|
||
|
||
|