The **AVR Watchdog** is a hardware unit that, when the program runs into an unexpected situation—like "flying off"—it **resets the microcontroller**. Think of it like a puppy watching the door: if it doesn't get attention in time, it might "bite" by resetting the system.
Here’s a watchdog initialization code generated by ICC’s App Builder:
```c
// Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
WDR(); // Prevents timeout on enabling
WDTCR = 0x0F; // WATCHDOG ENABLED - don’t forget to issue WDRs
}
```
However, this code alone isn’t sufficient. To fully enable the watchdog, you must also set `WDTCR = 0x1F` before `WDTCR = 0x0F`. The last line reminds us: **don’t forget to feed the dog** (i.e., use `WDR()`), or the watchdog will reset the system.
The watchdog works as an automatic counter that resets the microcontroller if it doesn’t get cleared within a certain time. If the program gets stuck or crashes, the watchdog triggers a reset, hoping to recover the system. This is especially useful for transient issues, but not for long-term problems or hardware failures.
In simple terms, the watchdog acts like a security monitor. When the program runs normally, it “feeds†the watchdog with a reset signal. But if the program crashes and stops feeding, the watchdog will trigger a system reset.
The AVR watchdog can be either a **soft dog** or a **hard dog**, depending on fuse settings. If the fuse isn’t set, it's a soft dog, meaning the program can disable or enable it. If the fuse is set, it becomes a hard dog, which cannot be turned off once enabled.
Does calling `WDR()` really count as “feeding the dog� Yes—it’s like giving the watchdog a reset signal. You should call it periodically, ideally before the watchdog timer overflows. If your loop cycle is shorter than the watchdog timeout, one `WDR()` per loop is enough.
Here’s a sample program demonstrating the watchdog’s reset function. Normally, the program would enter an infinite loop, but the watchdog resets the MCU, causing the LED to flash continuously.
```c
// Watchdog reset demo program
#include
#include
void port_init(void) {
PORTA = 0x03;
DDRA = 0x03;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
void watchdog_init(void) {
WDR();
WDTCR = 0x1F; // Required step not generated by ICC
WDTCR = 0x0F; // Enable watchdog
}
void Delay(void) {
unsigned char i, j;
for(i = 200; i > 0; i--) {
for(j = 200; j > 0; j--);
}
WDR(); // Feed the dog
}
void init_devices(void) {
CLI();
port_init();
watchdog_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00;
SEI();
}
int main(void) {
unsigned int i;
init_devices();
for(i = 10; i > 0; i--) {
PORTA = 0x02;
Delay();
PORTA = 0x01;
Delay();
}
while(1) {
// Normally, the program would loop here.
// Without WDR(), the watchdog would reset the MCU.
}
}
```
**Note**: To properly configure the watchdog, you must directly assign values to `WDTCR`, not use bitwise OR (`|=`). Also, according to the datasheet, changing the watchdog settings requires a specific sequence:
1. Write `1` to `WDCE` and `WDE` in the same instruction.
2. Set `WDE` and `WDP` within the next 4 clock cycles, then clear `WDCE`.
So before setting `WDTCR = 0x0F`, make sure to first write `WDTCR = 0x1F`.
This ensures the watchdog is correctly initialized and functions as intended.Compact style Generators
Compact style generators are portable and lightweight power generators that are designed to provide electricity in outdoor or remote locations. They are typically smaller in size and have a lower power output compared to larger generators, making them suitable for powering smaller appliances and devices.
Compact style generators are often used for camping, tailgating, outdoor events, and other activities where access to electricity may be limited. They are easy to transport and can be carried by hand or in a small vehicle. Some compact generators are even designed to be backpack portable, allowing users to take them on hiking or backpacking trips.
These generators are usually powered by gasoline, propane, or batteries. Gasoline-powered compact generators are the most common and offer a good balance between power output and fuel efficiency. Propane-powered generators are quieter and produce fewer emissions but may have a slightly lower power output. Battery-powered generators are the most environmentally friendly option but typically have a lower power output and limited runtime.
Compact style generators often feature multiple outlets, including standard AC outlets, USB ports, and DC outlets, allowing users to power a variety of devices simultaneously. Some models also come with additional features such as built-in inverters for clean and stable power output, low oil shutdown to protect the engine, and noise-reducing technology for quieter operation.
When choosing a compact style generator, it is important to consider the power requirements of the devices you plan to power, the runtime needed, and the noise level acceptable for your specific application. It is also recommended to follow the manufacturer's guidelines for safe operation and maintenance of the generator.
Portable Compact style Generators,Lightweight Compact style Generators,silent Compact Generators
Grandwatt Electric Corp. , https://www.grandwattelectric.com