In this post, we will see how to use the watchdog and what is the limit for your industrial controller Arduino designed for industrial automation.
Requirements
Ethernet or 20 I/Os PLC Arduino:Ā Ā Ā Ā Ethernet PLCĀ Ā Ā Ā Ā 20 I/Os PLC
Watchdog library:Ā Ā avr/wdt.h library
What is the watchdog?
Watchdog is an electronic timer that allows to reset the system in case of computer malfunctions and recover from it.
Watchdog consists of a decrementing timer, when the timer reaches zero the system resets. Then you always have to refresh the watchdog.
Software
You should use the Watchdog libraryĀ ā#include <avr/wdt.h>ā provided by Arduino in order to program our own Watchdog.
Functions:
#defineĀ | wdt_reset()Ā Ā Ā __asm__ __volatile__ (āwdrā) |
#defineĀ | WDTO_500MSĀ Ā Ā 5 |
#defineĀ | WDTO_1SĀ Ā Ā 6 |
#defineĀ | WDTO_2SĀ Ā Ā 7 |
#defineĀ | WDTO_4SĀ Ā Ā 8 |
#defineĀ | WDTO_8SĀ Ā Ā 9 |
IMPORTANT: The Ardbox PLC watchdog cannot work under 500ms. There are no limitations for M-Duino PLC.
Below you will find an example about how to use it:Ā the Watchdog lib
/* Copyright (c) 2017 Boot&Work Corp., S.L. All rights reserved This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <avr/wdt.h> ////////////////////////////////////////////////////////////////////////////////////////////// void setup() { Serial.begin(9600L); // Set the watchdog on 500 ms wdt_enable(WDTO_500MS); } ////////////////////////////////////////////////////////////////////////////////////////////// void loop() { // Refresh the watchdog wdt_reset(); // WORK HERE, but faster than 500ms Serial.println("Watchdog is working if you don't see the points"); delay(550); Serial.println("..."); }
How to use the Watchdog with your industrial PLC