an idea to power reset the MCU?

johnny78

Full Member level 5
Joined
Jun 28, 2017
Messages
256
Helped
1
Reputation
2
Reaction score
4
Trophy points
1,298
Activity points
3,340
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
 

The 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.
 

Hi,
the WDT couldnt reset it
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
 

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.
 

thx Klaus
there is alot to do with my design but for now i cant do all those checks & i have alreaady installed over than 50 pcs of this device & it works 24/24 365/365 days & i couldnt find a reason for this issue & yes the WDT couldnt reset the mcu & im sure its working because i have tested the method few times to make sure it works
so simply if i reset by power to fix this issue automatically when it happens & yes i have Pic projects working since 10 years or more working without any issue
& sure its reliable but i cant find the reason of my problem right now

& im thinking maybe i need an external reset method in case the MCU got frozen which cant activate reset pulse

any ideas will be great
thanks
Johnny
--- Updated ---

thx Brad
sure im looking for a way to reset the MCU automatically its 24/24 working device
i have the mains sensor which i can use it to reset the power on when mains available (momentary reset)
i have an idea but its not so clear in my mind to use P channel mosfet & i was thinking to trigger it by the MCU but now im thinking its not useful because it may not work if the MCU got frozen really

any idea will be great
thanks
Johnny
--- Updated ---

this is the method im thinking of but is 100ms enough period of time to reset the MCU & the peripherals?
then when i try this method to reset there is no power source to power the mcu so the pin will trigger the NPN transistor & set a flag to know reset is occured
& after that the pin will go low when the MCU looses power then when it starts again the pin will stay off when reading the reset flag

anyway im thinking of external reset source in case the MCU got frozen really

thanks
Johnny
 
Last edited:

Hi,

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
 

i like your way of thinking but as a solution to fix my problem immediately i thought of reset
i have no time now to re design with no errors unfortunately
im thinking of an external reset source in case my MCU hangs
 

Can 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.
 

Hi

as i guess this P channel mosfet will power my MCU & when applying negative pulse to npn transistor gate the power through the mosfet will disconnect
im looking for an idea to use the reset source from the optocoupler to trigger the NPN gate for lets say 500ms
(correct me if im thinking wrong)
i have 1 more free pin left on the mcu i can use it if necessary
any idea will b great

thanks
Johnny
 
Last edited:

I 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.
 

Question, for future design work :

ARM M3, M4, M7 has a fault exception trap mechanism, is that considered sufficient to
restart a runaway processor ?

ARM also has dual core parts (ESP32 also dual core).......
 

There 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
 

The 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.....

 
Last edited:

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 ---

There 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
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
 
Last edited:

& you adviced me to find the reason no curing the issue
And 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.

Klaus
 


And I stand to my recommendation.
i 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
--- Updated ---

i
i 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
its interesting if i fine attiny9 or pic10F202 for this
 
Last edited:

The 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.
 
i 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
 

i 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
unfortunately i couldnt find any 6 pin mcu
the cheapest one is at90s1200 which i was lookin for programming it but no solution without old parallel port
if you have a solution will be great
 

The 10F202 I used was in an 8-pin DIP package because I had them in stock but two of the pins are "no connect" and are not internally connected to the die. There is a 6-pin version in SOT23-5 package. They are one of the cheapest MCUs at 0.60 UKP or about 0.70 Euros/USD including tax.
Programming info: https://ww1.microchip.com/downloads/en/DeviceDoc/41228F.pdf

If you look on the internet there are several inexpensive programming tools that cover all the microchip devices including the 10F202.

Brian.
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…