|
|
@@ -32,23 +32,6 @@ TaskHandle_t xPidControlTaskHandle = NULL;
|
|
|
/* 闭环运行标志 (仅 preheat 任务写, 本任务读) */
|
|
|
static volatile uint8_t s_running = 0;
|
|
|
|
|
|
-/**
|
|
|
- * @brief 将输出缓冲封装 SET_ALL 帧并立即下发
|
|
|
- * @param 无
|
|
|
- * @return 无
|
|
|
- */
|
|
|
-static void pid_send_set_all(void)
|
|
|
-{
|
|
|
- uint8_t frame[COM_CPLD_FRAME_MAX_LEN];
|
|
|
- uint16_t flen;
|
|
|
-
|
|
|
- flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
|
|
|
- if (flen > 0)
|
|
|
- {
|
|
|
- Com_cpld_usart_send(frame, flen);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* @brief PID 控温任务体
|
|
|
* @note s_running=0 时仅休眠 (预热期间输出由 preheat 任务掌控)
|
|
|
@@ -59,6 +42,8 @@ static void Task_PidControl(void *argument)
|
|
|
{
|
|
|
(void)argument;
|
|
|
uint8_t i;
|
|
|
+ uint8_t frame[COM_CPLD_FRAME_MAX_LEN];
|
|
|
+ uint16_t flen;
|
|
|
|
|
|
printf("PID control task running...\r\n");
|
|
|
|
|
|
@@ -67,13 +52,27 @@ static void Task_PidControl(void *argument)
|
|
|
if (s_running)
|
|
|
{
|
|
|
int16_t sensor4[MID_TEMP_PREHEAT_NUM];
|
|
|
+ uint8_t abort = 0;
|
|
|
|
|
|
- /* 24 路 PTC 闭环: 过程值 = BMC 24 路温度 */
|
|
|
+ /* 批量写输出缓冲 + 封装 SET_ALL 帧须在同一临界区,
|
|
|
+ * 防止高优先级 CPLD 任务抢占读取到写了一半的缓冲 */
|
|
|
+ Mid_PID_LockOutput();
|
|
|
+
|
|
|
+ /* 24 路 PTC 闭环: 过程值 = BMC 24 路温度;
|
|
|
+ * 每路写前复查 s_running, 使 App_pidControl_Stop() 置位后
|
|
|
+ * 能立即放弃本轮剩余写入, 避免残留占空比被下发 */
|
|
|
for (i = 0; i < PID_CHANNEL_MAX; i++)
|
|
|
{
|
|
|
- int16_t pv = Mid_Temp_GetBmcTemp(i);
|
|
|
+ int16_t pv;
|
|
|
float out;
|
|
|
|
|
|
+ if (!s_running)
|
|
|
+ {
|
|
|
+ abort = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ pv = Mid_Temp_GetBmcTemp(i);
|
|
|
if (pv < -90)
|
|
|
{
|
|
|
out = 0.0f; /* 传感器无效, 本路不加热 */
|
|
|
@@ -85,14 +84,27 @@ static void Task_PidControl(void *argument)
|
|
|
Mid_PID_HeaterControl(i, out);
|
|
|
}
|
|
|
|
|
|
- /* 风扇: 按分区对应的 4 路温度分档 */
|
|
|
- for (i = 0; i < MID_TEMP_PREHEAT_NUM; i++)
|
|
|
+ if (!abort)
|
|
|
{
|
|
|
- sensor4[i] = Mid_Temp_GetPreheat(i);
|
|
|
- }
|
|
|
- Mid_PID_FanZoneUpdate(sensor4);
|
|
|
+ /* 风扇: 按分区对应的 4 路温度分档 */
|
|
|
+ for (i = 0; i < MID_TEMP_PREHEAT_NUM; i++)
|
|
|
+ {
|
|
|
+ sensor4[i] = Mid_Temp_GetPreheat(i);
|
|
|
+ }
|
|
|
+ Mid_PID_FanZoneUpdate(sensor4);
|
|
|
|
|
|
- pid_send_set_all();
|
|
|
+ flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
|
|
|
+ Mid_PID_UnlockOutput();
|
|
|
+
|
|
|
+ if (flen > 0)
|
|
|
+ {
|
|
|
+ Com_cpld_usart_send(frame, flen);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Mid_PID_UnlockOutput();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(APP_PIDCONTROL_PERIOD_MS));
|
|
|
@@ -117,9 +129,12 @@ void App_pidControl_Start(uint8_t target)
|
|
|
void App_pidControl_Stop(void)
|
|
|
{
|
|
|
uint8_t i;
|
|
|
+ uint8_t frame[COM_CPLD_FRAME_MAX_LEN];
|
|
|
+ uint16_t flen;
|
|
|
|
|
|
s_running = 0;
|
|
|
|
|
|
+ Mid_PID_LockOutput();
|
|
|
for (i = 0; i < PID_CHANNEL_MAX; i++)
|
|
|
{
|
|
|
Mid_PID_HeaterControl(i, 0.0f);
|
|
|
@@ -128,7 +143,13 @@ void App_pidControl_Stop(void)
|
|
|
{
|
|
|
Mid_PID_FanSetDuty(i, 0);
|
|
|
}
|
|
|
- pid_send_set_all();
|
|
|
+ flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
|
|
|
+ Mid_PID_UnlockOutput();
|
|
|
+
|
|
|
+ if (flen > 0)
|
|
|
+ {
|
|
|
+ Com_cpld_usart_send(frame, flen);
|
|
|
+ }
|
|
|
|
|
|
printf("[PID] stop\r\n");
|
|
|
}
|