javos65 / WDTZero

Allows to use the WatchDog functionality for Arduino Zero, MKRZero and MKR1000 only
15 stars 12 forks source link

Clear() freezes MCU for ~10ms #10

Open AndrejValand opened 3 years ago

AndrejValand commented 3 years ago

clear() function locks up the MCU for about 10ms as its waiting for synchronisation. For a fast running main loop i propose replacing the while(WDT->STATUS.bit.SYNCBUSY); loop with

void WDTZero::clearinloop() { if((WDT->STATUS.bit.SYNCBUSY)==0){ WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY; // Clear WTD bit WDTZeroCounter = _ewtcounter; // Reset the early warning downcounter value }
}

Or some other solution that would work in loop as also outside the loop and would not lock up the MCU