johnny78
Full Member level 5
- Joined
- Jun 28, 2017
- Messages
- 270
- Helped
- 1
- Reputation
- 2
- Reaction score
- 5
- Trophy points
- 1,298
- Activity points
- 3,469
The WDT is very reliable. Never seen it not to work. And I use the WDT in almost all my industrial designs (with the AVRs and other microcontroller)the WDT couldnt reset it
To reset your ATmega328P, use a P-channel MOSFET to control power. Connect the MOSFET's source to Vcc, drain to the MCU, and gate to ground through an NPN transistor controlled by an MCU pin. To reset, set the pin LOW to cut power for 100ms, then set it HIGH to restore power. This method ensures a complete power cycle for the MCU and peripherals.hi Guys
i have a problem with my armega328p which it got frozen few times
the WDT couldnt reset it So i was thinking of power reset by feeding power through a P channel Mosfet then reset power by cutting the power for a while
im using 16x2 i2c lcd & ds1307 with the Atmega328p & im not sure if the MCU got frozen or just the LCD so i have 2 questions
1:is it enough perrod of time if i cut the power by using a pin of the mcu then after restart the reset condition finished
2:give me an idea to do this please
thanks
Johnny
thx KlausHi,
The WDT is very reliable. Never seen it not to work. And I use the WDT in almost all my industrial designs (with the AVRs and other microcontroller)
IF (emphasized) a hang happens AND the WDT does not work ... there must be a hardware problem .. as root problem.
I´m the designer who removes the root problem instead of curing a symptom.
Thus my way to get a reliably working design is to focus on the the real cause of the problem.
* I would inspect schematic
* and PCB layout
regarding
* power supply stability
* (GND) noise
* ESD problems (or other overvoltage / negative voltage sources)
* oscillator problems
* others
****
I can confirm that the AVRs really work reliably. Many of my designs work 24/7 in a chemical plant. And a fail for longer than 10s would cause a production batch worth of 40,000$ to to be lost. The company would surely report every loss of batch to the ones responsible (in this case: me) for the fail.
Klaus
thx BradThe simple method is to install a manual switch in the power supply wire. (The P-transistor is a useful method if your system gets a signal to change state via timer or sensor of some kind.)
However if you simply wish to push a finger on a button to reset (or restart) your system, then decide which you want: a) normally On or b) normally Off. Either way is under your control. You can have a switch for the mcu and a switch for the lcd. Test what sequence works for your system. You'll have to operate manually for now. Further down the road you can build a circuit that works automatically when it detects a freeze-up.
Examine whether any component in your system warns against applying voltage while it's unpowered.
this is the method im thinking of but is 100ms enough period of time to reset the MCU & the peripherals?To reset your ATmega328P, use a P-channel MOSFET to control power. Connect the MOSFET's source to Vcc, drain to the MCU, and gate to ground through an NPN transistor controlled by an MCU pin. To reset, set the pin LOW to cut power for 100ms, then set it HIGH to restore power. This method ensures a complete power cycle for the MCU and peripherals.
i like your way of thinking but as a solution to fix my problem immediately i thought of resetHi,
the problem I see:
I assume there is a problem with noise, ESD, power supply ... if so, then this also will hit your "reset circuit" ... so how can you be sure your reset circuit will work properly under the same conditions your microcontroller goes hang?
For me it´s like a house getting destroyed .. now you build a second house to "protect" the first house. Without investigating what really caused the fisrrst house to break.
Earthquake, high water, wind, soemthing else?
I´d say: each cause needs it´s own focus and solution ... to really get an improvement.
As said: my idea is not to reset a microcontroller if it hangs, but to avoid that the microcontroller hangs in first place.
Klaus
HiCan you find a pin which stops changing state when the mcu freezes? That can be your detection method. A capacitor-type circuit should be able to sense if nothing has happened for some time (maybe several seconds).
Then it triggers your reset circuit. The reset circuit can be the P-device, designed to activate for the required length of time via another capacitor-type circuit holding the bias (hi or low, depending) for that length of time.
What are the advantages in using traps in a processor versus watchdog timer
In embedded systems and processor design, both traps and watchdog timers are used to improve system reliability, but they serve different purposes and offer distinct advantages. Here's a comparison of the two:
Traps
A "trap" is a mechanism where the processor automatically transfers control to a specific piece of code (often called an exception handler or interrupt service routine) when certain predefined conditions are met.
Advantages of Using Traps:
- Specific Error Handling:
- Traps allow for detailed and specific error handling, as they can be configured to trigger on various specific conditions, such as illegal instructions, divide-by-zero errors, or memory access violations.
- This specificity enables the system to take precise corrective actions depending on the type of fault.
- Immediate Response:
- Traps are designed to respond immediately when an error condition occurs, ensuring quick handling of issues that could potentially corrupt data or cause system instability.
- Debugging Aid:
- Traps can be used in debugging to catch errors like invalid memory access or illegal operations, helping developers identify and correct bugs during the development phase.
- Support for Complex Operating Systems:
- In complex operating systems, traps are essential for managing system-level events, such as page faults in virtual memory management, which require immediate handling to continue program execution correctly.
- Interrupt Handling:
- Traps can also serve as a general-purpose mechanism for handling interrupts, allowing the processor to temporarily pause its current tasks to address more urgent matters.
Watchdog Timer
A watchdog timer (WDT) is a hardware or software timer that resets the system if it is not periodically "kicked" (reset) by the software. It is primarily used to detect and recover from system malfunctions, such as when the system becomes unresponsive.
Advantages of Using Watchdog Timers:
- System Stability:
- Watchdog timers are critical in maintaining system stability, especially in environments where the system needs to run continuously without human intervention.
- If the system hangs or gets stuck in an infinite loop, the watchdog timer will trigger a reset, bringing the system back to a known good state.
- Simplicity:
- Implementing a watchdog timer is typically straightforward, making it a simple and effective solution for ensuring that a system can recover from software malfunctions.
- Hardware-Induced Reliability:
- Since the watchdog timer is usually implemented in hardware, it operates independently of the system software. This independence ensures that the system will reset even if the software becomes completely unresponsive.
- Failsafe Mechanism:
- Watchdog timers act as a last-resort failsafe. Even if all other error detection mechanisms fail, the watchdog timer will ensure that the system does not stay in an erroneous state indefinitely.
- Suitable for Real-Time Systems:
- In real-time systems, where timely execution is crucial, a watchdog timer ensures that any unhandled or prolonged delays will lead to a system reset, maintaining the timeliness of operations.
Comparison and Use Cases:
In practice, many systems use both traps and watchdog timers together to leverage the advantages of both: traps for handling specific faults and watchdog timers as a failsafe mechanism to ensure system recovery.
- Traps are more appropriate for situations where you need precise error handling and the ability to diagnose specific types of faults. They are highly useful in complex systems where the nature of errors can vary, and the system must take appropriate corrective actions without necessarily resetting.
- Watchdog Timers are more suited to scenarios where system reliability and uptime are critical, and the risk of the system becoming unresponsive needs to be mitigated. They provide a simple, hardware-based solution to recover from severe system failures.
But if trap faults are periodic, repeating, then a watchdog is ineffective ?
You're correct that if trap faults are periodic and repeating, a watchdog timer alone might be ineffective in addressing the underlying issue. Here's why:
Repetitive Trap Faults and Watchdog Timers:
- Periodic Trap Faults: If the system encounters the same fault repeatedly at regular intervals, the system might still appear to be "alive" and continue kicking the watchdog timer. As a result, the watchdog timer won't trigger a reset, because the system hasn’t become completely unresponsive or hung—it’s just stuck in a loop of encountering the same fault and recovering from it.
- Ineffectiveness of Watchdog in This Scenario: Since the watchdog timer is designed to reset the system only if the software stops kicking it (i.e., the system hangs or becomes unresponsive), it won't reset the system if the system keeps recovering from traps and continuing to run, even if it's not functioning correctly or efficiently.
Mitigating Repetitive Trap Faults:
- Enhanced Error Handling:
- Implement a more sophisticated error-handling mechanism within the trap handlers. For example, if a particular fault is encountered too frequently, the system could escalate the response (e.g., log the error, notify the user, or ultimately trigger a system reset) instead of simply recovering and continuing.
- Watchdog Timer with Trap Detection:
- Some systems use a combination of a watchdog timer and error counters. For instance, the system could monitor how often certain traps are triggered within a specific time frame. If the same trap is triggered too frequently, this could trigger a reset or enter a safe state, even if the watchdog timer hasn’t timed out.
- Use of Redundant Mechanisms:
- Alongside the watchdog timer, implementing a secondary check for periodic faults can be effective. For example, an additional counter could track the number of times a specific fault occurs. If this counter exceeds a threshold, it could trigger a system reset or switch to a recovery mode, even if the watchdog timer hasn’t been triggered.
- Root Cause Analysis and Fixing the Bug:
- The ideal solution is to address the root cause of the repetitive trap faults. Identifying and fixing the underlying bug or issue that is causing the repeated faults will eliminate the problem altogether.
Conclusion:
While watchdog timers are great for recovering from complete system hangs, they may not be effective in scenarios where the system repeatedly encounters the same fault but remains responsive enough to keep resetting the watchdog. In such cases, additional mechanisms or enhanced error handling should be used to detect and respond to these repetitive faults.
thx BrianI have an MCU working in a very high noise environment where large pumps are constantly turning on and off. I get around occasional freezes with a second MCU, a PIC10F202 working as an external watchdog. It gets reset every second by a pulse from the MCU (which in turn comes via WiFi from a different source) and if it doesn't see a pulse in 60 seconds it pulls the main MCU reset pin low. Costs pennies and drives two LEDs, one is a stretched pulse from the reset, the other to say a reset is in progress. 5 components in total, including the supply decoupling cap.
I can share the code and schematic but you still need something to indicate a crash has not occurred.
Brian.
that's what i was looking for & already have mentioned that by sharing my idea about external reset circuitThere are dedicated watchdog ICs. Doing basically what Brian describes.
Go to the distributor of your choice and do a search for "watchdog" ... (did I need to mention this?)
Klaus
thanks DanaThe point of post #11 was to get community feedback on trap usage.
ChatGPT states the following :
So watchdogs ineffective for memory faults causing repetitive code execution errors. Resetting a processor only
to startup and fault trying to execute code not very useful.....
And I stand to my recommendation.& you adviced me to find the reason no curing the issue
thx Brian
its the same issue i have which i couldnt know the reason & that's what im looking for but its very expensive to add another MCU for power reset
im looking for something simpler but reliable at the same time & yes as i mentioned in my schematic i have the manis sensor which i can use to reset with every mains available
if you share your schematic it can give me some ideas & experience
thanks
Johnny
--- Updated ---
that's what i was looking for & already have mentioned that by sharing my idea about external reset circuit
& you adviced me to find the reason no curing the issue but this is something hard to achieve if it was that easy why they invented WDT or external reset circuits ?
anyway its valuable information i have got from you all
thanks
Johnny
--- Updated ---
thanks Dana
im not that expert but i can know when WDT is working or not & i have projects running since more than 10 years with no problems at all
& the issue with this device happened with no logical reason & the WDT couldnt reset it
Johnny
i wish if it was that easyAnd I stand to my recommendation.
Still it´s your design, you decide what to do.
But I wanted to point out that you don´t need to design your own watchdog circuit ... as discrete hardware or using a microcontroller with software.
... since there are ready to buy simple and reliable solutions ... to keep the effort low.
i need something like:Klaus
its interesting if i fine attiny9 or pic10F202 for thisi wish if it was that easy
i need something like:
on setup
1:turn high reset pin
2:delay(500);
3:turn low reset pin
4:end
& i have a source pulse for this
thanks
Johnny
'External Watchdog module for PML unit.
'This PIC is reset by the one second time signal sent by MQTT
' and echoed on the PML's SDA pin on the ISCP port.
'It is basically a monostable with monitor LEDs, reset once a second and providing a
'reset to the ESP32 if 60 seconds elapses
OPTION_REG = 0x08
GPIO = 0x03
Retry:
ConfigPin GP0 = Input 'Active low reset to ESP32
ConfigPin GP1 = Output 'LED pulsed at reset to show activity
ConfigPin GP2 = Output 'LED pulsed while ESP32 reset is active
GP0 = 1 'Don't force an immediate reset !
GP1 = 1 'Source current to blue (activity) LED
GP2 = 0 'Red (reset) LED should be off
WaitMs 200 'turn blue LED off after 200mS
GP1 = 0
WaitMs 59800 'watchdog time delay
GP2 = 1 'turn red LED on to announce imminent reset
WaitMs 200 'turn red LED off ...
GP2 = 0
ConfigPin GP0 = Output ' .. and pull GP0 low
GP0 = 0
WaitMs 200 ' delay before repeating process in case a reset failed
GP0 = 1
WaitMs 10
Goto Retry
i will check if i can find pic10f202 or attiny9 or 10The schematic is so simple I will describe it:
PIC10F202 in DIP8 package, you can use the 6 pin version
pin 1 - no connection
pin 2 - VDD (3.3V)
pin 3 - (GP2) Anode of red LED
pin 4 - (GP1) Anode of blue LED
pin 5 - (GP0) active low reset output to main MCU
pin 6 - no connection
pin 7 - VSS (GND)
pin 8 - (/MCLR) periodic low pulses to reset watchdog timer
Both LED cathodes are joined and go to ground through a single 150 Ohm resistor.
A 100nF ceramic capacitor bridges VDD and VSS.
And the code is written in Oshonsoft BASIC:
Code:'External Watchdog module for PML unit. 'This PIC is reset by the one second time signal sent by MQTT ' and echoed on the PML's SDA pin on the ISCP port. 'It is basically a monostable with monitor LEDs, reset once a second and providing a 'reset to the ESP32 if 60 seconds elapses OPTION_REG = 0x08 GPIO = 0x03 Retry: ConfigPin GP0 = Input 'Active low reset to ESP32 ConfigPin GP1 = Output 'LED pulsed at reset to show activity ConfigPin GP2 = Output 'LED pulsed while ESP32 reset is active GP0 = 1 'Don't force an immediate reset ! GP1 = 1 'Source current to blue (activity) LED GP2 = 0 'Red (reset) LED should be off WaitMs 200 'turn blue LED off after 200mS GP1 = 0 WaitMs 59800 'watchdog time delay GP2 = 1 'turn red LED on to announce imminent reset WaitMs 200 'turn red LED off ... GP2 = 0 ConfigPin GP0 = Output ' .. and pull GP0 low GP0 = 0 WaitMs 200 ' delay before repeating process in case a reset failed GP0 = 1 WaitMs 10 Goto Retry
On my PCBs there is a row of pins to connect to the ESP32 MCU so it can be programmed after assembly, it carries 3.3V, GND, Reset, GPIO0, TX and RX for programming but it also has two pins for future I2C expansion so I use one of those to pulse the reset to the watchdog. After initial programming the firmware can be updated over the air.
I just checked the log files and I get about two resets per month but considering the unit has connections to three water pumps, an AC line power monitor and two solar inverters it's hardly surprising it sees lots of noise. It runs 24/7.
Brian.
unfortunately i couldnt find any 6 pin mcui will check if i can find pic10f202 or attiny9 or 10
also i can add an extra reset source
1: reset on mains available
2:reset on pin state hangs on the main mcu
thanks
Johnny
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?