I am using atmega328pb controller and Arduino Framework with mini-core. The problem is that the microcontroller goes into a never-ending loop while power up. I found this while debugging.
Actually, I am using while(1) loops in the program, and temporarily I have solved this problem by using the watchdog timer. Please check the below code for more details.
Can anyone let me know the reason for this problem?
bool Fault_ckeck()
{
if (millis() - FAULT_CNT > FAULT_TMG) return 1; else return 0;
}
bool WCO_Fault_ckeck()
{
if (millis() - WCO_FAULT_CNT > FAULT_TMG) return 1; else return 0;
}
bool WCFR_Fault_ckeck()
{
if (millis() - WCFR_FAULT_CNT > FAULT_TMG) return 1; else return 0;
}
bool WCUP_Fault_ckeck()
{
if (millis() - WCUP_FAULT_CNT > FAULT_TMG) return 1; else return 0;
}
void WCUP_EMR_STP()
{
DWGUP.hardStop();
DWCFR.hardStop();
DWCO.hardStop();
while (1) {
if (STARTUP_FLAG == START_TOTAL) wdt_reset();
if (millis() - ER_SIG_CNT > WCUP_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}
void WCFR_EMR_STP()
{
DWCFR.hardStop();
DWGUP.hardStop();
DWCO.hardStop();
while (1) {
if (STARTUP_FLAG == START_TOTAL) wdt_reset();
if (millis() - ER_SIG_CNT > WCFR_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}
void WCO_EMR_STP()
{
DWCO.hardStop();
DWGUP.hardStop();
DWCFR.hardStop();
while (1) {
if (STARTUP_FLAG == START_TOTAL) wdt_reset();
if (millis() - ER_SIG_CNT > WCO_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}
void STARTUP_WCUP_EMR_STP()
{
DWGUP.hardStop();
DWCFR.hardStop();
DWCO.hardStop();
while (1) {
if (millis() - ER_SIG_CNT > WCUP_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}
void STARTUP_WCFR_EMR_STP()
{
DWCFR.hardStop();
DWGUP.hardStop();
DWCO.hardStop();
while (1) {
if (millis() - ER_SIG_CNT > WCFR_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}
void STARTUP_WCO_EMR_STP()
{
DWCO.hardStop();
DWGUP.hardStop();
DWCFR.hardStop();
while (1) {
if (millis() - ER_SIG_CNT > WCO_EMR_STP_TMG) {
digitalWrite(EMR_STP, !digitalRead(EMR_STP));
ER_SIG_CNT = millis();
}
}
}