1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Watchdog Timer

Discussion in 'AVR' started by rabhishek91, Apr 10, 2013.

  1. rabhishek91

    rabhishek91 New Member

    Joined:
    Feb 15, 2013
    Messages:
    66
    Likes:
    0
    Location:
    Karnataka, INDIA
    Hi everyone.:)
    Today i learnt about watchdog timer in my college and thought of trying it using ATmega32.

    My objective is to set watchdog timer condition at 20 seconds (approx.) and light the LED.
    Is it possible ? According to the datasheet(attached below) in the Watchdog Timer Prescaler select maximum time-out is 2.2 seconds.
    Is it possible to generate timeout at 20 seconds ?

    Can i make use some variable to keep track of its time out and then decide ?
    Ex- If the variable equal to 10 (i.e 10 time outs ) then light an LED.

    Also WDT oscillation cycles are nothing but WDT operating frequency right ?

    I am sorry to post lot of questions.Please help. :confused:
    Thanks in advance.:)
     

    Attached Files:

  2. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Most people would not use a watch dog timer to time your led. There are other timers.

    The watchdog timer resets the processor. In doing so the program starts from the very beginning and all initialized variables will be reinitialized.
     
  3. rabhishek91

    rabhishek91 New Member

    Joined:
    Feb 15, 2013
    Messages:
    66
    Likes:
    0
    Location:
    Karnataka, INDIA
    Thanks for your reply sir.
    I didn't knew that Watchdog timer resets processor.

    So is it impossible to serve my objective using Watchdog timers ?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA

    Not impossible but you have to play some games.
    Method 1
    You could slow the processor to 1/10 the speed and the 2 seconds become 20. Then you could turn the LED on at the start of the program, then off, then wait for the WDT to expire.

    Method 2
    Use a counter variable but do not initialize it in the normal way.
    If the counter is not between 0 and 10 you set it to 0.
    If it is < 10 you add 1 to it.
    if it is equal to 10 you blink the led and set it to 0.
    Note that this could be off by a count or two but you can figure that out easy enough.
     
    • Like Like x 1
  6. rabhishek91

    rabhishek91 New Member

    Joined:
    Feb 15, 2013
    Messages:
    66
    Likes:
    0
    Location:
    Karnataka, INDIA
    Sir how would one slow down the processor speed by 1/10th?
    ATmega32 has inbuilt 1MHz watchdog timer . Is it dependent on CPU clock ?
     
  7. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Just don't use the watchdog timer to blink a LED.. It is not meant to do that. There are many better ways to do it. Like delay functions.. and "ordinary" timers.

    Of course if you just want to learn how to use the WDT, then go for it and experiment. Nothing wrong with that.

    No, you can't slow down the watchdog oscillator. You can use the WDT interrupt to count the events when the WDT expires.

    Here is a nice tutorial. It is for Atmega328, but most of the stuff is valid for ATmega32 too.
    http://www.embedds.com/using-watchdog-timer-in-your-projects/
     
    Last edited: Apr 11, 2013
  8. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    As I have said and misterT has said using the WDT is not a good way to do this.

    My assumption is that the WDT is derived from the processor clock. CHeck the datasheet to verify.
     
  9. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    It has a separate, dedicated, 1Mhz oscillator. The frequency of it can't be changed.
     
  10. rabhishek91

    rabhishek91 New Member

    Joined:
    Feb 15, 2013
    Messages:
    66
    Likes:
    0
    Location:
    Karnataka, INDIA
    Yes sir. Your right i'll not use Watchdog timer.
     
  11. rabhishek91

    rabhishek91 New Member

    Joined:
    Feb 15, 2013
    Messages:
    66
    Likes:
    0
    Location:
    Karnataka, INDIA
    Thank you. :)
     

Share This Page