|
|
各位大佬请教一下:
STC32G12K128运行中复位,RSTFLAG=0x14(LVDRSTF+SWRSTF同时置位),怎么排查到底是哪个复位原因呢?
复位现象: - 触发条件:串口命令启动电机B(BS600,目标600mm/s)持续运行后复位
- 复位时间高度随机:2秒 / 227秒 / 340秒 / 957秒都出现过,无周期规律
- 空载不启动电机时长时间运行不复位
不管运行哪个电机都会触发复位,请各位大佬帮忙看看,谢谢; - 串口打印内容如下:
- [10:42:08.508]发送→S600
- [10:44:20.851]接收←====== Start success ======(初始化才打印,电机运行过程中突然出现此信息,说明复位)
-
- [10:44:25.956]发送→S600
- [10:56:58.387]接收←====== Start success ======(初始化才打印,电机运行过程中突然出现此信息,说明复位)
第三次打印:我添加了复位寄存器标志:
[11:11:33.061]发送→S600
[11:13:57.882]接收←====== Start success ======
[RST] PCON=0x20 WDT=0x07 IAP=0x00 RSTFLAG=0x14
[RST] flag: LVD=1 WDT=0 SW=1 ROMOV=0 EX=0
[RST] Cause: LVD reset (VCC dropped)
[RST] Note : SW=1 is companion flag of LVD, NOT real SW reset
[RST] Hint : check PSU load ability / wiring / LVD threshold
主程序源代码:
void main(void)
{
u8 pcon_save = PCON; /* bit4=POF上电, bit5=LVDF低压复位 */
u8 wdt_save = WDT_CONTR; /* bit7=WDT_FLAG看门狗复位标志 (复位后原始值) */
u8 iap_save = IAP_CONTR; /* bit6=SWBS, bit5=SWRST 软件复位 */
u8 rstflag_save = 0;
u8 eaxfr_save;
/* ★读取RSTFLAG扩展寄存器 (必须在最开头, 防止初始化覆盖标志) */
eaxfr_save = P_SW2;
P_SW2 |= 0x80; /* EAXFR=1, 使能扩展SFR访问 */
rstflag_save = RSTFLAG;
RSTFLAG = rstflag_save; /* ★写1清除标志 (写0无效, 写1清对应位) */
P_SW2 = eaxfr_save; /* 恢复EAXFR */
WDT_CONTR = 0x36; /* 使能看门狗, PS=2(8分频), IDLE_WDT=1 */ //90ms=2 3=180 4=360 5=720ms
WDT_CONTR |= 0x10; /* CLR_WDT=1, 立即喂狗一次 */
/* 初始化 (system_init + GPIO + UART + Timer + controll + debug) */
schedule_init();
EA = 1;
delay_ms(10);
printf("====== Start success ======\r\n");
printf(" [RST] PCON=0x%02X WDT=0x%02X IAP=0x%02X RSTFLAG=0x%02X\r\n",
pcon_save, wdt_save, iap_save, rstflag_save);
printf(" [RST] flag: LVD=%d WDT=%d SW=%d ROMOV=%d EX=%d\r\n",
(rstflag_save >> 4) & 1, (rstflag_save >> 3) & 1,
(rstflag_save >> 2) & 1, (rstflag_save >> 1) & 1,
rstflag_save & 1);
if (rstflag_save & 0x10) {
printf(" [RST] Cause: LVD reset (VCC dropped)\r\n");
if (rstflag_save & 0x04)
printf(" [RST] Note : SW=1 is companion flag of LVD, NOT real SW reset\r\n");
if (rstflag_save & 0x02)
printf(" [RST] Note : ROMOV=1, CPU mis-executed during VCC drop\r\n");
printf(" [RST] Hint : check PSU load ability / wiring / LVD threshold\r\n");
} else if (rstflag_save & 0x08) {
printf(" [RST] Cause: Watchdog timeout\r\n");
} else if (rstflag_save & 0x02) {
printf(" [RST] Cause: PC runaway (invalid ROM area)\r\n");
if (pcon_save & 0x20)
printf(" [RST] Note : PCON.LVDF=1, VCC also dropped - power suspect\r\n");
} else if (rstflag_save & 0x04) {
printf(" [RST] Cause: SW reset without LVD/WDT - IAP_CONTR mis-write?\r\n");
} else if (rstflag_save & 0x01) {
printf(" [RST] Cause: External RST pin (P5.4)\r\n");
} else if (pcon_save & 0x10) {
printf(" [RST] Cause: Power-On reset\r\n");
} else {
printf(" [RST] Cause: Unknown (check hardware)\r\n");
}
PCON &= ~(0x30); /* 清除POF/LVDF标志 */
WDT_CONTR &= ~0x80; /* 清除WDT_FLAG标志 */
//printf("UART1 cmds: HELP\r\n");
//printf(" MotorA: START STOP S<rpm> + - DIR P I G INFO\r\n");
//printf(" MotorB: BSTART BSTOP BS<rpm> B+ B- BDIR BINFO\r\n");
//printf(" Dual: AB<rpm> ESTOP\r\n");
while (1) {
if (B_1ms) {
B_1ms = 0;
schedule_loop();
}
}
}
|
|