157 lines
3.7 KiB
C
157 lines
3.7 KiB
C
#include "app.h"
|
||
|
||
|
||
//绿灯 NOR ;蓝灯 ERR
|
||
float X_ads1220 = 0; //读到的电压值
|
||
float TEMP_M1820 = 0; //温度
|
||
uint32_t move_step_5mm = 0x0000C800;
|
||
uint32_t move_step_1mm = 0x00002800;
|
||
|
||
uint8_t magnet_tx[7] = {0x05,0x01,0x00,0x01,0x00,0x32,0xFF};
|
||
|
||
HAL_StatusTypeDef hal_check_tx; //用于查看debug发送状态
|
||
uint8_t flash_rd_flag = 0; //flash读取标志
|
||
signed int first_xa_32 = 0; //记录上电时电机位置
|
||
int LEDcnt_ms = 100; //LED计数
|
||
uint16_t SG_RESULT = 0;
|
||
uint8_t TSTEP_RAW[5] = {0};
|
||
uint32_t TSTEP = 0;
|
||
|
||
void app_act (void)
|
||
{
|
||
if(flash_rd_flag == 0) //只读取一次
|
||
{
|
||
flash_rd_flag = 1;
|
||
|
||
STMFLASH_Read(FLASH_SAVE_ADDR,flash_rd,6); //读取当前flash内容
|
||
|
||
magnet_middle = flash_rd[0]; //默认以#25的中点为标准,#50和#110的位置预留
|
||
|
||
}
|
||
|
||
|
||
// 按键操作
|
||
// Key_Scan(); //按键扫描(已放入定时器中断)
|
||
if(old2new_flag == 0)
|
||
{
|
||
key_act(); //执行旧版功能
|
||
}else
|
||
{
|
||
key_act_new(); //执行新版功能
|
||
}
|
||
|
||
//2 定时器
|
||
// if(it_5000ms_flag == 1)
|
||
// {
|
||
// it_5000ms_flag = 0;
|
||
//
|
||
//
|
||
|
||
//
|
||
// }
|
||
|
||
|
||
// 数据采集
|
||
if(it_100ms_flag)
|
||
{
|
||
it_100ms_flag = 0;
|
||
|
||
// HAL_GPIO_WritePin(RS485_EN1_GPIO_Port,RS485_EN1_Pin,GPIO_PIN_SET); //使能485发送,发送结束后在回调函数中拉低
|
||
|
||
// hal_check_tx = HAL_UART_Transmit_IT(&huart2, magnet_tx ,7); //485发送
|
||
|
||
// TMC5160_SPIReadInt(0x12,TSTEP_RAW); //读取TSTEP
|
||
// TSTEP = Raw_32(TSTEP_RAW);
|
||
// TMC5160_SPIReadInt(DRV_STAT_ADDR,DRV_STAT); //读取驱动器状态
|
||
// DRV_STAT_32 = Raw_32(DRV_STAT); // 16-20bit为实际电机电流
|
||
// SG_RESULT = ((uint16_t)DRV_STAT_32) & 0x03FF; //驱动器状态共32bit,其中0-9bit为负载值,读到的负载值越低,负载越高,0代表最高负载
|
||
|
||
get_state();
|
||
|
||
get_magnetv(); //磁感应反馈电压
|
||
|
||
TEMP_M1820 = M1820_Get_Temp(); //温度采集
|
||
|
||
if(old2new_flag == 0)
|
||
{//旧版
|
||
OLED_MenuTest(); //OLED显示,菜单
|
||
}else
|
||
{//新版
|
||
OLED_Menu_New();
|
||
}
|
||
X_ads1220 = Xads1220_filter(25,75); //电阻尺滤波结果(电压值,mv)
|
||
|
||
|
||
process_ttl_receive_timer(); // 串口计时
|
||
|
||
}
|
||
|
||
|
||
// 电阻尺 位移传感器
|
||
Xads1220_record(); //采集数据用于滤波
|
||
|
||
|
||
// 电机
|
||
motor_protect_ads(100,1900); //电阻尺限位
|
||
Deal_Motor();
|
||
|
||
|
||
// 串口数据处理
|
||
Deal_Uart_Data_For_Module();
|
||
|
||
|
||
|
||
|
||
|
||
//9 LED灯状态指示
|
||
if(old2new_flag == 0)
|
||
{ //旧版
|
||
if( Motor_Run == 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( (Motor_Run == 1) && (motor_direc == 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( (Motor_Run == 1) && (motor_direc == 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( ( Motor_Run == 2 ) || ( Motor_Run == 3 ) )
|
||
{
|
||
if(LEDcnt_ms == 100)
|
||
{
|
||
LEDcnt_ms = 0;
|
||
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);
|
||
}
|
||
|
||
if(it_200ms_flag)
|
||
{
|
||
it_200ms_flag = 0;
|
||
|
||
LEDcnt_ms++;
|
||
|
||
if( LEDcnt_ms == 2 )
|
||
{
|
||
LEDcnt_ms = 0;
|
||
HAL_GPIO_TogglePin(LED_NOR_GPIO_Port, LED_NOR_Pin);
|
||
HAL_GPIO_TogglePin(LED_ERR_GPIO_Port, LED_ERR_Pin); //复位移动时两灯闪烁
|
||
}
|
||
}
|
||
}
|
||
}else
|
||
{//新版
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|