avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] wdt_disable() doesn't work on mega168, working example pr


From: Jim Lindsey
Subject: [avr-libc-dev] wdt_disable() doesn't work on mega168, working example provided
Date: Thu, 14 Feb 2008 22:56:40 -0800
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Hey, the wdt_disable() macro doesn't seem to reflect the timed sequence described int the ATmega168 manual. I was looking at this, because the wdt_disable() macro does not seem to work on the 168. I coded up the proper sequence described in the manual, and it seems to work fine. Is this a known issue?

Below is the pseudocode from the manual. The current wdt.h code doesn't do anything with the MCUSR, or clear the WDE bit after starting the WDCE timed sequence. Depending on how the wdt is being used, the current wdt.h wdt_disable() macro either does nothing, or causes a reset.

MANUAL SUGGESTION, p52
void WDT_off(void)
{
        __disable_interrupt();
        __watchdog_reset();
        /* Clear WDRF in MCUSR */
        MCUSR &= ~(1<<WDRF);
        /* Write logical one to WDCE and WDE */
        /* Keep old prescaler to prevent unintentional time-out */
        WDTCSR |= (1<<WDCE) | (1<<WDE);
        /* Turn off WDT */
        WDTCSR = 0x00;
        __enable_interrupt();
}

My wdt_disable(), which seems to work:

inline void wdt_disable() {
    uint8_t origSREG = SREG;
    wdt_reset();
    __asm__ ( "cli" );
    MCUSR &= ~(_BV(WDRF));
    WDTCSR |= _BV(_WD_CHANGE_BIT) | _BV(WDE);
    WDTCSR = 0;
    SREG = origSREG;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]