Watchdog timer question

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a program in an Atmega 162.

It takes the time from an RTC chip (DS1337) and displays it on 4 x 7 segment displays.

The display refresh subroutine is accessed via a pin change interrupt that is connected to a square wave output from the RTC chip at 4.096 kHz.

I am looking into the application of a watch dog timer to the program and was planning to put the WDR command in the display refresh subroutine as it is accessed from every part of the program in one form or another.

I set all 3 of the WDP (0,1,2) bits in the WDTCR to allow maximum time to reset (2.1 Seconds at the 5VDC i am using).

I am using a 4 mHz resonator and have unticked the divide by 8 internally fuse (AVR Studio 4).

The WDT works for most of my program but for some parts where the display is momentarialy not refreshed, the program resets. I do not think the delay is anywhere near 2 seconds. is there something else that can affect my WDT time or pre scaler value?

Also how can I check the scan time of a part of my program to see if it should be suitable for the WDR command? Is it a matter of counting the commands in a section?

Should i only be using WDR once in good practice?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wonder, why you avoid the most obvious solution?

The ATmega162 has 4 timers, simple pick one of these.
They are made for exact such applications.

I would suggest about 100Hz refresh rate, so for 4 digits, a 400Hz interrupt would be nice.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I usually have a watchdog reset in my main loop which generally runs say 100 times/second. Lots of tasks run from main and if any lock up and do not return watchdog fires.
The disadvantage of an interrupt driven watchdog reset, is that the MCU might actually be locked up, but the interrupt probably still works and the watchdog does not cause a WDT reset.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

Last Edited: Mon. Jan 17, 2011 - 12:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, an internal timer as an alternative to access the display refresh subroutine but if it is already being refreshed at the moment i.e. accessed at 4kHz it should still reset the WDT in time...?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the external 4kHz clock was unreliable, you should use a timer.
Also 4kHz was 10 times higher as needed.

If the multiplex interrupt crashed by other reason, you should search the fault.
The watchdog was not intended to hide your software faults.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The internal WD oscillator can vary widely- 20% is not uncommon so factor that in with your timing restraints.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I set all 3 of the WDP (0,1,2) bits in the WDTCR
I would guess you are not getting that done properly, with the result being a watchdog set to 15ms. Getting WDE set takes no special method, getting prescale bits does. You end up with WDE set, but prescale not set as desired.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cool, got it sorted.
I took the pin change out of the equation all together and set up a 4kHz timer to refresh the display.
I must of been in safety level 1 and had to set wdce before making the change (by the way how do you check what safety level you are currently in?)

Placed the WDR command in the refresh display routine and it works. Thanks for the help.