Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example
Read the latest documentation,Participate in: 【Find Errors in Documentation and Win Prizes】 Activity

The latest documentation content can be found at:https://docs.openluat.com/air780e/luatos/app/service/wdt

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

1. Introduction to Watchdog Circuit

The Watchdog Timer (WDT) is a monitoring circuit primarily used in embedded systems to enhance the reliability and stability of the system. With the help of the watchdog circuit, when the system encounters anomalies such as program runaway or deadlock, it can automatically reset and restart the system.

1.1 Working Principle of the Watchdog

The watchdog circuit typically includes a timer, a feed signal, and a reset output. During normal system operation, the main controller (MCU) periodically sends a pulse to the feed signal to ‘feed’ the watchdog, preventing it from timing out. If the MCU fails to feed the watchdog within the specified time, the watchdog timer will time out and output a reset signal to reset the MCU.

1.2 Application Architecture of the Watchdog

In practical applications, the watchdog chip is usually connected to a GPIO port of the MCU. During its normal operation, the MCU regularly writes a high or low signal to this port to inform the watchdog that it is still functioning correctly. If the MCU fails to send the signal on time, the watchdog will trigger a reset operation.

1.3 Functions and Hardware of Watchdog Chips

Some watchdog chips, such as the TPV6823, have multiple pins, including power pins (VCC), feed signal pins (WDI), reset output pins (RESETn), and manual reset input pins (MRn). These pins provide various reset methods and timing settings to meet different application needs.

1.4 Timing of the Watchdog

The timing of the watchdog typically needs to be maintained over a relatively long period, such as around 200 milliseconds. This setting ensures that during normal operation, even if the MCU fails to feed the watchdog in a timely manner due to interference, the watchdog will not immediately reset the system, thereby giving the MCU enough time to respond and handle the issue.

1.5 Types of Watchdogs

Watchdogs can be classified into independent watchdogs and window watchdogs. Independent watchdogs have lower timing accuracy requirements, while window watchdogs are used in scenarios that require high timing accuracy.

1.6 Differences Between Hardware and Software Watchdog

Hardware watchdogs utilize independent timer circuits to achieve monitoring functions, offering higher reliability. Software watchdogs, on the other hand, use internal timers or other mechanisms of the processor to implement monitoring. Although they can simplify hardware design to some extent, they are generally less reliable than hardware watchdogs.

In summary, the watchdog is an essential system protection mechanism that ensures the normal operation of the system by periodically ‘feeding’ the watchdog. When the system encounters anomalies, the watchdog can promptly reset the system, preventing deadlocks and program runaway issues, thereby enhancing the system’s reliability and stability. In practical applications, developers need to choose the appropriate watchdog solution based on specific requirements and set appropriate timing parameters to achieve optimal protection effects.

2. Overview of Demonstration Functionality

This article demonstrates how to use the watchdog timer (WDT) library to prevent embedded devices from crashing, primarily through the Air780E core board and LuatOS system. The watchdog circuit is a monitoring circuit mainly applied in embedded systems to enhance the system’s reliability and stability. With the help of the watchdog circuit, when the system encounters anomalies such as program runaway or deadlock, it can automatically reset and restart the system.

The demonstration is divided into two parts: normal operation and fault scenario simulation.

In normal operation, the example code initializes the watchdog library, sets the timeout and feeding period. Then, it creates a task that periodically feeds the watchdog to prevent the watchdog timer from timing out. If the watchdog timer times out, the system will automatically restart.

In the fault scenario simulation part, we add a new task called fault_task, which enters an infinite loop without feeding the watchdog. This way, when the watchdog timer times out, the system will automatically restart, simulating the device’s ability to recover from a fault scenario.

This demonstration illustrates the critical role of the watchdog timer in embedded systems, effectively preventing system crashes and enhancing system stability and reliability.

3. Demonstration Hardware Environment

3.1 Development Board

This article takes the Air780E core board as an example, as shown in the figure below:

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example
For detailed usage instructions of this core board, refer to: https://docs.openluat.com/air780e/product/

The product manual for the Air780E includes the “Core_Air780E Development Board Usage Instructions VX.X.X.pdf”, with the latest version of the usage instructions at the time of writing this article being: “Core_Air780E Development Board Usage Instructions V1.0.5.pdf” ; If you encounter any issues during use, you can directly refer to this usage instruction PDF document.

3.2 SIM Card

In mainland China, IoT cards or mobile phone cards from mobile, telecom, and unicom can be used.

3.3 PC Computer

Windows 7 and above version of the Windows system.

3.4 Data Communication Cable

1. USB to Type-C data cable

One end is a USB interface, and the other end is a Type-C interface.

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

4. Demonstration Software Environment

4.1 Luatools Download Debugging Tool

The Luatools tool is launched by Hezhao, supporting the latest firmware acquisition, firmware packaging, trace printing, and offline burning functions.

For tool usage instructions, refer to: Luatools Download and Detailed Use: https://docs.openluat.com/Luatools/

4.2 Source Code and Firmware

1) Low-level core download address: LuatOS firmware version download address: https://docs.openluat.com/air780e/luatos/firmware/

The firmware used in this demo is from the core_V1112 compressed package, specifically LuatOS-SoC_V1112_EC618_FULL.soc

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

2) Demo location

This demo mainly demonstrates how to use the watchdog timer (wdt) library in the LuatOS system to prevent device crashes.

Demo location: https://gitee.com/openLuat/LuatOS-Air780E/tree/master/demo/wdt

3) The source code and firmware are packaged and compressed, as shown below

The core folder in the compressed package contains the firmware, and the code folder contains the script code.

5. Hardware and Software Materials

5.1 Introduction to Watchdog Operation Library

5.1.1 Introduction to Watchdog Library

This library provides a series of API functions for managing and operating the watchdog timer, allowing developers to conveniently manage the watchdog timer in the LuatOS system, thereby improving device stability.

5.1.2 API Interface Introduction

The API interfaces used in this tutorial can be referenced at: https://wiki.luatos.com/api/wdt.html?highlight=watchdog

5.2 Air780E Core Board Burning Instructions

5.2.1 Selecting Firmware and Scripts

1) Open the Luatools tool

2) Click on Project Management Test

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

3) Operate according to the illustration

Note that everyone only needs to follow through to the fourth step; the fifth step can be done after following the subsequent operations.

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

5.2.2 Burning

1) Connect the Air780E core board to the computer via a USB data cable, as shown in the figure below:

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

2) Follow the operations below to burn it

At this point, you need to first click on the Luatools tool to download the low-level and script/download script, and then proceed with the following operations.

If the development board is powered off: At this point, hold down the download mode button (BOOT key), then press and hold the power button (POW key) to power on. If everything goes smoothly, the development board will enter download mode, and the Luatools tool’s download progress bar will start running. At this point, you can release the BOOT key and POW key, waiting for the tool to indicate that the download is complete.

If the development board is already powered on: At this point, you can first hold down the BOOT key, then briefly press the reset key (RST key), and the development board will restart and enter download mode.

5.2.3 Port Display in Different Modes

1) Normal Boot Mode

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

2) Download Mode

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

6. Function Verification

6.1 Program Normal Operation

6.1.1 Example Code Introduction

1) Project Information: The project name (PROJECT) and version (VERSION) are defined at the beginning, and this information is output through logs.

2) Import System Library: The sys library is commonly used in LuatOS and is imported using require(“sys”).

3) Task Initialization: A new task is created using the sys.taskInit function. In the task, it checks if the wdt library is available; if not, it enters an infinite loop, outputting a prompt message once per second.

4) WDT Configuration:

  • Initialize the wdt library and set the timeout to 9 seconds.

  • Set a timer to feed the watchdog every 3 seconds, ensuring that the device does not restart under normal operation.

  • It is indicated that if a software crash or hardware failure occurs, the device will automatically restart after a maximum of 18 seconds.

5) Run System: Finally, start the system with sys.run(), and no other statements should be added afterwards.

6.1.2 Complete Code Display

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

6.1.3 Running Result Display

View logs using the Luatools tool

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

6.2 Adding Infinite Loop to Simulate Fault Scenario

6.2.1 Example Code Introduction

We created a new task named fault_task in the original example code, which will enter an infinite loop. Since this new task will not feed the watchdog, the device will automatically restart after timing out. This effectively simulates the watchdog’s timeout scenario.

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

6.2.2 Complete Code Display

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

6.2.3 Running Result Display

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

7. Conclusion

This demonstration, through the Air780E core board and LuatOS system, details how to use the watchdog timer (WDT) library to prevent embedded devices from crashing. As an important system protection mechanism, the watchdog circuit can automatically reset and restart the system in the event of system anomalies, thereby enhancing the system’s reliability and stability.

In the demonstration, we first introduced the working principle, application architecture, timing settings, and differences between hardware and software watchdogs. Next, through practical operations, we demonstrated how to integrate the watchdog timer into a simple LuatOS project and set appropriate parameters to ensure that the system can automatically recover under both normal operation and fault scenarios.

This demonstration deepens our understanding of the working principles and application value of the watchdog timer in embedded systems, as well as how to effectively utilize the watchdog library to enhance system stability and reliability in actual projects. This is a crucial skill for embedded system developers.

8. Extensions

8.1 Application Scenarios of Watchdog Timers

Watchdog timers are widely applied in various embedded systems and IoT devices, particularly in scenarios requiring high reliability. Some typical application scenarios include:

1) Industrial Control Systems: In industrial production processes, control systems require high stability and reliability. Watchdog timers can ensure that the system quickly recovers from disturbances or anomalies.

2) Automotive Electronic Systems: Automotive electronic systems face complex electromagnetic environments and vibrations. Watchdog timers can help the system maintain stable operation after power-on reset, preventing system crashes due to software or hardware failures.

3) Medical Devices: Medical devices have high requirements for stability and reliability. Watchdog timers can ensure that devices do not stop working due to failures during long-term operation, safeguarding patient safety and equipment continuity.

4) Communication Devices: In communication systems, watchdog timers can be used to monitor and protect network devices, ensuring the stability and reliability of data transmission.

8.2 Design Considerations for Watchdog Timers

When designing and implementing watchdog timers, several key factors need to be considered:

1) Timeout Duration: The timeout duration refers to the time interval from when the watchdog timer starts counting to when it triggers the reset signal. This time needs to be set based on the specific application requirements, typically balancing system stability and response speed.

2) Feeding Cycle: The feeding cycle refers to the time interval at which the main controller sends pulses to the watchdog chip. The feeding cycle should be set short enough to prevent the watchdog timer from mistakenly triggering a reset during normal operation.

3) Watchdog Reset Output: Watchdog timers typically have a reset output pin used to provide a reset signal to the main controller. When designing, it is essential to ensure that the reset output pin’s level is compatible with the reset input pin of the main controller.

4) Power Consumption: When designing watchdog timers, their power consumption needs to be considered, especially in low-power applications. Choosing low-power watchdog chips and reasonable power supply design is crucial for the overall power consumption of the system.

5) Compatibility and Scalability: When designing watchdog timers, their compatibility and scalability with other systems need to be considered. Ensuring that the watchdog timer can seamlessly integrate with other hardware and software components and can be easily expanded or upgraded in the future is essential.

By comprehensively considering these factors, developers can design and implement a stable, reliable, and efficient watchdog timer solution to ensure the normal operation of embedded systems and the stability of data transmission.

9. Common Questions

9.1 How does a Watchdog Timer work?

The watchdog timer maintains timing by having the main controller periodically send pulse signals to it. If the main controller fails to send a pulse within the specified time, the watchdog timer will trigger a reset signal to reset the main controller.

9.2 How to configure the timeout and feeding cycle of the Watchdog Timer?

In embedded operating systems like LuatOS, the timeout and feeding cycle of the watchdog timer are typically configured via API functions. Appropriate time intervals can be set based on specific application needs.

If using the watchdog operation library mentioned in this article, you can follow these steps to configure:

1) Initialize the Watchdog: Use the wdt.init(timeout) function to initialize the watchdog timer, where the timeout parameter is the timeout duration in milliseconds. For example, if you want the watchdog’s timeout to be 9000 milliseconds, you can call it like this:

2) Set Watchdog Timeout (Optional): If the device supports it, you can call wdt.setTimeout(timeout) to reset the watchdog’s timeout duration, which is also in milliseconds. For example:

3) Periodically Feed the Watchdog: Use the wdt.feed() function to feed the watchdog to reset the timeout timer. It is recommended to periodically call this function using a timer. For example, you can set it to feed the watchdog every 3000 milliseconds:

By following these steps, you can successfully configure the timeout and feeding cycle of the watchdog timer, ensuring that the device does not restart due to not feeding the watchdog.

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

▼ Contact Hezhao Marketing Department Head ▼

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

Scan the QR code to add friends on WeChat/Enterprise WeChat

▼ Learn More About Hezhao ▼

Tu Ge & Hezhao strategic cooperation empowers the Cat.1 module to go overseas low-power testing tool—Hezhao Power Analysis Instrument

Charging forward with 2 microamps! The development history of Hezhao’s low power

Exploring the Air780E Low Power 4G Module: Watchdog Timer (WDT) Example

Leave a Comment