Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - watch dog timer

(you are viewing a thread; or go back to list of threads)

watch dog timer (by Gaurav P)
I wish to enable watch dog timer is PIC16f628A.
In LDMICRO, I think there's no command as such for enabling WDT.
If I enable the WDT in configuration bits, will it be sufficient? I mean will it reset the PIC in case of a malfunction?
Fri Jan 27 2017, 06:16:49
(no subject) (by Ihor Nehrutsa)
1.1) PIC16f628 datasheet:
...
The WDT has a nominal time-out period of 18 ms (with
no prescaler).
...

1.2) LDmicro executes CLRWDT command "Watchdog reset" every PLC cycle (at begin of the cycle).

So you can't set PLC period more than 18 ms.

2) in ldmicro\mcutable.h PIC16f628 fuses set as
..
//code protection off, data code protection off, LVP disabled,
//BOD reset enabled, RA5/nMCLR is RA5, PWRT enabled,
//WDT disabled,
//HS oscillator
0x3f62,
/*
(1 << 13) | // code protection off,
(1 << 8) | // data code protection off,
(0 << 7) | // LVP disabled,
(1 << 6) | // BOD reset enabled,
(0 << 5) | // RA5/nMCLR is RA5,
(0 << 3) | // PWRT enabled,
(0 << 2) | // WDT disabled,
(2 << 0) | // HS oscillator
*/
...
As you can see WDT is disabled.
But you can try to enable it with your programmer(PICKIT).

You can try this feature. Please report your results.
Fri Jan 27 2017, 07:46:55
(no subject) (by Gaurav P)
Dear Ihor Nehrutsa,
Yes. I have already enabled it thru the flashing software.
But what I doubt is, will it be sufficient to activate the WDT from there or is there any other way to activate it thru LDMICRO as well.
Sun Jan 29 2017, 23:48:56
(no subject) (by MGP)
Gaurav P

The cycletime is much more flexible than the WDT, the WDT without subroutine makes no sense because if the WDT is activated you must do something.
Mon Jan 30 2017, 02:21:13
(no subject) (by Ihor Nehrutsa)
I plan add option to enable WDT from LDmicro (for PIC's MCU),
add WDT command to clear WDT timer,
and add LOCK command to test WDT action.

LOCK command is an artificial situation to provocation the WDT reset.

LOCK command executes goto to the current address, i.e. labelN: goto labelN (l_02e7: rjmp l_02e7), i.e. infinite loop, deadlock, block the program, freeze the program.
LOCK command executes the infinite loop(deadlock of program), but WDT resets the MCU. Only WDT or external reset can unfreeze the program after LOCK command.

wait v4.1.4
Mon Jan 30 2017, 03:34:58
(no subject) (by MGP)
I'm not a fan of resetting the MCU, it's better to activate an output pin if you use that instruction and stop the program.

The programmer himself must reset the MCU so that he can see that something went wrong.

I always use the TCY instruction like the Siemens LOGO!"running led" if I need a visual signal.

But you're the boss ;-)
Mon Jan 30 2017, 04:46:07, download attachment Snap219.jpg
(no subject) (by Ihor Nehrutsa)
https://en.wikipedia.org/wiki/Watchdog_timer

Due to external physical impact (Power Supply, temperature) or imperfections software(protocol) may cause malfunctions(deadlock, dead loop inside the PLC cycle). MCU runs inside dead loop, and you can't affect this error.
Also deadlock maybe cause outside the PLC cycle !!!

RESET MCU
INIT hardware and software
PLC cycle begin
CLRWDT
your LD begin
...
//>>>>dead loop begin
||^^
\\<<<<dead loop end
...
your LD end
PLC cycle end
GOTO PLC cycle begin

//>>>>dead loop2 begin
||^^
\\<<<<dead loop2 end
Mon Jan 30 2017, 08:55:43
(no subject) (by MGP)
Yes, but how you are going to detect your deadloop when the mcu is running and restarts continuously.

You should get at least a signal from the MCU of what's wrong, like with real plc's, they also go in STOP mode.

Btw. I'm not against a WDT instruction or checkbox, but I can not see the benefit of it with a cycletime related program.
I think it is more for people who compile the program in C and add C routines, then it make sense.
Mon Jan 30 2017, 10:44:47
(no subject) (by Ihor Nehrutsa)
MCUCSR – MCU Control and Status Register
The MCU Control and Status Register provides information on which reset source caused an MCU Reset.

Bit 3 – WDRF: Watchdog Reset Flag. This bit is set if a Watchdog Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag.

Bit 2 – BORF: Brown-out Reset Flag. This bit is set if a Brown-out Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag.

Bit 1 – EXTRF: External Reset Flag. This bit is set if an External Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag.

Bit 0 – PORF: Power-on Reset Flag. This bit is set if a Power-on Reset occurs. The bit is reset only by writing a logic zero to the flag.

To make use of the Reset Flags to identify a reset condition, the user should read and then reset the MCUCSR as early as possible in the program. If the register is cleared before another reset occurs, the source of the reset can be found by examining the Reset Flags.
Mon Jan 30 2017, 11:33:26
(no subject) (by Alex)
will this WDT be optional?, i mean, it can be enabled or desabled?, or will it be always enabled like the internal pull-up resistors?
Mon Jan 30 2017, 11:40:04
(no subject) (by Ihor Nehrutsa)
WDT is optional now and will optional in future.
WDT is disabled by default.
But you can enable it with your programmer with ALL versions of LDmicro.
Mon Jan 30 2017, 12:00:22
(no subject) (by Gaurav P)
Let me explain why I need this. If there is any other way out, please let me know.

I have designed a system using PIC16F628A. It is being implemented in a remote location, where the operator / attendant is not available for days.

The power quality in India is horrible. We have to take all the necessary precautions, primarily in hardware and if possible, in program as well.

The power quality in India cause malfunctions due to surges/ noise / harmonics.

This causes the PIC to misbehave abruptly. Some undesired I/O's get activated and desired ones get deactivated, all of a sudden and they continue doing so until the PIC is reset.

So, I was thinking to use a watchdog timer to detect such condition and reset the PIC immediately on detection of such a problem...
Thu Feb 2 2017, 03:27:07
(no subject) (by Ihor Nehrutsa)
LDmicro v4.1.6
http://cq.cx/ladder-forum.pl?action=viewthread&parent=6071
allow set any PIC Configuration Bits

You can anable WDT to enhance the reliability of the device.

See PIC Configuration Bits
https://github.com/LDmicro/LDmicro/wiki/PIC-Configuration-Bits
Sat Feb 18 2017, 05:29:47
How to wake up PIC16F886 by watch dog timer (by Mukesh )
How to wake up PIC16F886 by watch dog timer
Fri Feb 2 2018, 06:56:11
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):