about watchdog setting [using Codevision]

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

Hello to everybody.My question is about setting the watch dog timer in an ATMega 8 and the reset that causes.
The code in C is:
WDTCR=0x18;
WDTCR=0x08;//16ms the reset interval
i have not issue the command #asm("wdr") but in Avrstudio nothing seems to happen and in the real board also.I have set the fuse.
What i am doing wrong.Please help.

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

For avr-gcc, you would be better off using the functions in .

Regards,
Steve A.

The Board helps those that help themselves.

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

In the Atmega8 datasheet/chapter Watchdog Timer there is a piece of code telling you the way of how to change the prescaller or to stop it.

That code works.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

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

I reply to my post.I solve the problem.The watchdog timer really does not work in CVAVR compiler if the delay_ms(xx) command is used or probably only if the #include header used.But the problem really exists and related with the delay command.

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

Quote:

The watchdog timer really does not work in CVAVR compiler if the delay_ms(xx) command is used

What you mean it works exactly like it says it will in the manual?
Quote:
void delay_ms(unsigned int n)

generates a delay of n milliseconds.
This function automatically resets the wtachdog timer every 1ms by generating the wdr instruction.


Well there's a surprise.

It's usually worth reading manuals before trying to use things.

(someone should tell Pavel that "wtachdog" is spelt wrong in that ;-))

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

Note that if the app has multiple watchdog setup sequences, you should use a sequence based on the pattern as the Wizard would produce it, to avoid the optimizer "breaking" the 4-cycle rule.

// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/16k
#pragma optsize-
WDTCR=0x18;
WDTCR=0x08;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hello staff ja a while I'm away but always has something that makes us
back!

My problem is this I need to make an oscillator using one of these
two micro-controllers. Atmega8l or Atinny85L This is relatively easy!

But I will make it difficult. My power consumption is extremely critical, accurate
generate a frequency of only 150Hz, with a pulse width of 300us and consumption
maximum of 60 Microamps!

I'm trying to use the Power Down mode. I did some testing and got a frequency
of 57 Hz at most and can not move forward. Could someone help? Not found
almost nothing to put the micro-controller in "coma" and agree it's time you want.
Ja could make him stay in a coma and wakes him, but I'm not having success in
obtain a frequency greater than 57 Hz, if someone give a help, would be very
grateful.

#include
#include
#include
#include
#include
#include

ISR(WDT_vect, ISR_NAKED)
{

_WD_CONTROL_REG = _BV(WDIE);
PORTB = _BV(PB3);
_delay_us(300);
reti();
}

void save_power(void)
{

ADCSRA &=~(_BV(ADIE));
TIMSK &=~(1<<TOIE0);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
GIMSK|=(1<<PCIE);
sleep_mode();
sleep_cpu();

}

void turn_off_watchdog(void)
// disable the watchdog timer first, in case of this application code is been
loaded by the bootloader
{

MCUSR &= ~(_BV(WDRF)|_BV(WDE));
_WD_CONTROL_REG &= ~(_BV(WDE));
_WD_CONTROL_REG &= ~(_BV(WDIE));
wdt_disable();

}

int main(void){

DDRB = 0xff;
PORTB = 0x00;

turn_off_watchdog();

wdt_enable(WDTO_15MS);
_WD_CONTROL_REG = _BV(WDIE); /* generate watchdog interrupts

sei(); /* enable interrupts */

while(1)
{

save_power();

}
}

This is the source of the C program I'm using for the test, I'm using the WinAVR and the Attiny85V.

Thank you very much.

Regards

Antonio Cesario

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

thank you guys
you saved me , that's great.
clawson, you solved my problem! I've faced the same problem, now it's ok.
thank you