This repository has been archived on 2024-12-31. You can view files and clone it, but cannot push or open issues or pull requests.
mfps/App/Src/uniform.c

180 lines
3.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: wujunchao 24472040@qq.com
* @Date: 2024-10-14 14:42:21
* @LastEditors: wujunchao 24472040@qq.com
* @LastEditTime: 2024-10-30 08:47:39
* @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;
}
}
uint8_t ocin1_flag = 0, ocin2_flag = 0;
char uniform_limit(float start, float end)
{
if( ( ocin1 == 0 )&&( direc_select != 0 ) )
{
ocin1_flag = 1;
//电机停止
tmc5160_operate(0,0);
return 1;
}
if (ocin1_flag == 1) //是否经过限位点,防止越过限位点后无法停止
{
if(direc_select != 0)
{
//电机停止
tmc5160_operate(0,0);
return 1;
}else
{
ocin1_flag = 0;
}
}
if( ( ocin2 == 0 )&&( direc_select != 1 ) )
{
ocin2_flag = 1;
//电机停止
tmc5160_operate(0,0);
return 2;
}
if (ocin2_flag == 1) //是否经过限位点,防止越过限位点后无法停止
{
if(direc_select != 1)
{
//电机停止
tmc5160_operate(0,0);
return 2;
}else
{
ocin2_flag = 0;
}
}
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);
}
}