油温测量优化
This commit is contained in:
+34
-27
@@ -51,7 +51,7 @@ uint8_t modbusRxBuf[16]; // Modbus接收缓冲匿
|
||||
uint8_t modbusTxBuf[16]; // Modbus发鿁缓冲区
|
||||
volatile uint8_t rxFlag = 0; // 接收完成标志
|
||||
|
||||
static uint16_t temp;
|
||||
static uint16_t gusOilTemp = 0;
|
||||
static uint16_t level;
|
||||
//uint8_t UART1_Rx_flg = 0;
|
||||
/* USER CODE END PTD */
|
||||
@@ -176,7 +176,7 @@ void Process_Modbus(void)
|
||||
uint16_t deep = level; // 模拟温度倿(实际应从传感器读叿)
|
||||
modbusTxBuf[3] = deep >> 8; // 高字芿
|
||||
modbusTxBuf[4] = deep & 0xFF; // 低字芿
|
||||
uint16_t temp = temp_value[3]; // 模拟温度倿(实际应从传感器读叿)
|
||||
uint16_t temp = gusOilTemp; // 模拟温度倿(实际应从传感器读叿)
|
||||
modbusTxBuf[5] = temp >> 8; // 高字芿
|
||||
modbusTxBuf[6] = temp & 0xFF; // 低字芿
|
||||
AppendCRC(modbusTxBuf, 7); // 添加CRC校验
|
||||
@@ -189,7 +189,7 @@ void Process_Modbus(void)
|
||||
modbusTxBuf[0] = SLAVE_ADDR; // 从机地址
|
||||
modbusTxBuf[1] = 0x03; // 功能砿
|
||||
modbusTxBuf[2] = 0x02; // 返回字节敿(2字节)
|
||||
uint16_t temp = temp_value[3]; // 模拟温度倿(实际应从传感器读叿)
|
||||
uint16_t temp = gusOilTemp; // 模拟温度倿(实际应从传感器读叿)
|
||||
modbusTxBuf[3] = temp >> 8; // 高字芿
|
||||
modbusTxBuf[4] = temp & 0xFF; // 低字芿
|
||||
AppendCRC(modbusTxBuf, 5); // 添加CRC校验
|
||||
@@ -292,6 +292,11 @@ void check_level(void)
|
||||
HAL_GPIO_WritePin(HEAT2_GPIO_Port, HEAT2_Pin,GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HEAT3_GPIO_Port, HEAT3_Pin,GPIO_PIN_SET);
|
||||
break;
|
||||
default:
|
||||
HAL_GPIO_WritePin(HEAT1_GPIO_Port, HEAT1_Pin,GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HEAT2_GPIO_Port, HEAT2_Pin,GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HEAT3_GPIO_Port, HEAT3_Pin,GPIO_PIN_RESET);
|
||||
break;
|
||||
}
|
||||
|
||||
if(HAL_GetTick() < ulTick + 1000) return;
|
||||
@@ -307,35 +312,37 @@ void check_level(void)
|
||||
usIndex++;
|
||||
if(usIndex >= iSampleNum)
|
||||
{
|
||||
printf("calculate %d\r\n", iCheckIndex);
|
||||
iLevelBuf[iCheckIndex] = calculate(ausTempBuf[iCheckIndex + 1]);
|
||||
if (iCheckIndex < 3) {
|
||||
printf("calculate %d\r\n", iCheckIndex);
|
||||
iLevelBuf[iCheckIndex] = calculate(ausTempBuf[iCheckIndex + 1]);
|
||||
|
||||
if (iLevelBuf[0] && iLevelBuf[1] && iLevelBuf[2])
|
||||
{
|
||||
level = 3;
|
||||
} else if (iLevelBuf[0] && iLevelBuf[1])
|
||||
{
|
||||
level = 2;
|
||||
} else if (iLevelBuf[0])
|
||||
{
|
||||
level = 1;
|
||||
} else
|
||||
{
|
||||
level = 0;
|
||||
if (iLevelBuf[0] && iLevelBuf[1] && iLevelBuf[2])
|
||||
{
|
||||
level = 3;
|
||||
} else if (iLevelBuf[0] && iLevelBuf[1])
|
||||
{
|
||||
level = 2;
|
||||
} else if (iLevelBuf[0])
|
||||
{
|
||||
level = 1;
|
||||
} else
|
||||
{
|
||||
level = 0;
|
||||
}
|
||||
} else {
|
||||
gusOilTemp = 0;
|
||||
for(int i=0 ; i<iSampleNum;i++)
|
||||
{
|
||||
gusOilTemp += ausTempBuf[0][i];
|
||||
}
|
||||
gusOilTemp /= iSampleNum;
|
||||
|
||||
printf("temp %d,level %d\r\n", gusOilTemp, level);
|
||||
}
|
||||
|
||||
temp = 0;
|
||||
for(int i=0 ; i<iSampleNum;i++)
|
||||
{
|
||||
temp += ausTempBuf[0][i];
|
||||
}
|
||||
temp /= iSampleNum;
|
||||
|
||||
printf("temp %d,level %d\r\n", temp, level);
|
||||
|
||||
usIndex = 0;
|
||||
iCheckIndex++;
|
||||
if(iCheckIndex >= 3) iCheckIndex = 0;
|
||||
if(iCheckIndex >= 4) iCheckIndex = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user