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/app.c

99 lines
2.7 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.

#include "app.h"
//绿灯 NOR ;蓝灯 ERR
float X_ads1220 = 0; //读到的电压值
float X_ads1220_L = 36.875; //电压值上限
float X_ads1220_H = 1311.150; //电压值下限
float X_ads1220_prc = 0; //电压百分比(即位移百分比)
float TEMP_M1820 = 0; //温度
uint32_t move_step_5mm = 0x0000C800;
uint32_t move_step_1mm = 0x00002800;
char ocin1 = 0,ocin2 = 0; //位置开关远离为1接近为0
char oled_init_flag = 0,oled_init_result = 0;
//int i2c_error_temp = 0;
void app_act (void)
{
//1 按键操作
// Key_Scan();//按键扫描(已放入定时器中断)
key_act(); //按键执行功能
//2 定时器
if(it_1000ms_flag == 1)
{
it_1000ms_flag = 0;
// OLED_Act(); //OLED显示,操作显存后统一发送
// OLED_DisplayTest(); //OLED显示只发送需要显示的部分
OLED_MenuTest();
}
//3 串口通信测试
// uart_test();
//4 数据采集
if(it_100ms_flag)
{
it_100ms_flag = 0;
TEMP_M1820 = M1820_Get_Temp(); //温度采集
X_ads1220 = Xads1220_filter(4,16); //电阻尺滤波结果电压值mv
X_ads1220_prc =(X_ads1220 - X_ads1220_L)/(X_ads1220_H - X_ads1220_L);
// 串口计时
process_ttl_receive_timer();
}
//5 电阻尺 位移传感器
Xads1220_record();
//6 电机
// motor_protect_ads(0.10, 0.90); //根据电阻尺位移限位
// motor_protect_ocin(); //根据位置开关限位
// tmc5160_operate(tmc5160_sw, move_step_5mm); //第一个参数代表模式选择第二个参数为步长电机转动一圈滑块移动5mm
Deal_Motor();
//7 串口数据处理
Deal_Uart_Data_For_Module();
//8 位置开关
ocin1 = HAL_GPIO_ReadPin(OCIN1_GPIO_Port,OCIN1_Pin); //低电平接近,高电平远离
ocin2 = HAL_GPIO_ReadPin(OCIN2_GPIO_Port,OCIN2_Pin); //低电平接近,高电平远离
//9 LED灯状态指示
if( (tmc5160_sw == 0) || ((tmc5160_sw == 3) && (busy_flag == 0)) )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_SET);//停止状态两灯熄灭
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_SET);
}
if(tmc5160_sw == 1)
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_RESET);//正向转动绿灯亮
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_SET);
}
if(tmc5160_sw == 2)
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_RESET);//反向转动蓝灯亮
}
if( (tmc5160_sw == 3) && (busy_flag == 1) )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_RESET);//复位移动时两灯亮
}
}