Watchdog Timer on attiny1614 #493
Replies: 5 comments 2 replies
-
Here is the whole file if it helps. |
Beta Was this translation helpful? Give feedback.
-
// As a function
void wdt_reset() {
__asm__ __volatile__ ("wdr"::);
} // as a macro (which is all that wdt.h does)
#define wdt_reset() __asm__ __volatile__ ("wdr"::) Both produce binary identical output; and no matter how you get a wdt_reset() you call it like you would any function or functionlike macro. ... And I did end up checking anyway. I think the enable/disable functions from wdt.h should work too. Not because AVR_libc libraries were updated for these parts or anything, but just because it's the same as the xmega parts for which it was updated ages ago. You can lose the stupid double underscores on either side of the asm and volatile keywords, but if I go recommending that some standards weenie on a non-Arduino-IDE platform who is using avr-gcc with a more stringent mode will cry foul (those keywords, in that context, are not ISO standard C, you see, and compilers are supposed to prefix and postfix any beyond-the-standard keywords with that). |
Beta Was this translation helpful? Give feedback.
-
I can't believe how quickly you solved this for me. The macro seemed to work! I searched the internet for days, and continued to reread the 1614 datasheet, only to continue to fail. I am looking forward to a long term test to see if the micro-controller locks up again. You are a true selfless gentleman, Miles |
Beta Was this translation helpful? Give feedback.
-
Lol - simple, I don't have the time to do all this stuff! As for this specific matter, IMO it's what support people call a gotcha, where the nature of the problem is immediately apparent amnd tjhe so;lution is known. Since I don't consider writing inline assembly to bne a particularly big deal, have used thw WDT on a bunch of parts, and and read the avr-libc headers for one reason or another on at least o9ne occsion per file.... it's not like I had to think tio solve it. I am addingn to the relevant section of the core docs, because I hadn't realized I hadnt' area,ly mnentioned how to actuazlly, like, se it from within a sketcb |
Beta Was this translation helpful? Give feedback.
-
Many thanks to this thread. #include <avr/wdt.h> |
Beta Was this translation helpful? Give feedback.
-
First off, Thanks Dr. Azzy for this awesome core. I am a novice, and this is my first time I can't work something out on my own.
I have been trying to implement the atitny 1614 native watchdog timer for a week, and I am having no luck.
I would like to perform a reset if program control does not go back to the main loop within 8 seconds. I would like to use normal, and not the windowed mode, which I understand is, windowed mode would do a hard reset if program control returned to the main loop to soon.
I seem to have the below code working to reset every 8 seconds, but I can’t seem to find the correct command to reset the watchdog timer itself.
The 1614 datasheet references a WDR but I can't find out how to execute it.
Apologies for the laymen speak, I am new to this at an old age, and any help would be appreciated.
Thanks,
Miles
cut from setup;
` digitalWrite(IRLED, HIGH);delay(250);
digitalWrite(IRLED, LOW);delay(200);
digitalWrite(IRLED, HIGH);
LEDTimerStart = millis();
_PROTECTED_WRITE(WDT.CTRLA,0xB); // added and changed SpenceKonde readme.md, I thinks its normal mode 8secs
}
void loop()//====================== Loop BEGIN ========================================//
{
// Can't find the correct code to put here to reset the the Watchdog timer only (WDR)
CheckButtonState();
CheckForAndSend();
BTN_OneAndThree();
// Turns off LED
if ((millis() - LEDTimerStart) > LEDTimeout) {
digitalWrite(IRLED, LOW);
}
// Turns off FCU after 60 min
if ((millis() - LEDTimerStart) > ShutDownTimeOut) {
digitalWrite(PowerEnable, LOW);
}
}
//----------End Of Void Loop----------------------------//
void CheckButtonState()
{
CB1 = digitalRead(SW1);
CB2 = digitalRead(SW2);
Volts = analogRead(VoltsP);
if (CB1 == LOW) {
setIRLED(); LEDTimerStart = millis();
SW1State = SW1State + 1;
}
if (CB1 == HIGH) {
SW1State = SW1State - 1;
}
if (SW1State >= OnDebounce) {
SW1State = OnDebounce;
}
if (SW1State <= OffDebounce) {
SW1State = OffDebounce;
}
if (CB2 == LOW) {
setIRLED(); LEDTimerStart = millis();
SW2State = SW2State + 1;
}
if (CB2 == HIGH) {
SW2State = SW2State - 1;
}
if (SW2State >= OnDebounce) {
SW2State = OnDebounce;
}
if (SW2State <= OffDebounce) {
SW2State = OffDebounce;
}
if (Volts > 75) {
setIRLED(); LEDTimerStart = millis();
SW3State = SW3State + 1;
}
if (Volts <= 75) {
SW3State = SW3State - 1;
}
if (SW3State >= OnDebounce) {
SW3State = OnDebounce;
}
if (SW3State <= OffDebounce) {
SW3State = OffDebounce;
}
}`
TLTR
I am an amateur when it comes to coding micro-controllers, but I am really stuck on this one. I am using the 1614 as part of a wireless HID mouse and keyboard. The 1614 just does some IR emitter functions for a tracker and sends button states, battery voltage, ect to a 32u4 via NRF 24L01. Everything worked perfect for years using the 328PBs
Unfortunately now that I switched to the 1614, I get a very infrequent random lock up that requires a reset.
Thanks again,
Miles
Beta Was this translation helpful? Give feedback.
All reactions