Giving external Reset to Microcontroller with its own GPIO pin - Page 1
Forum section: electronics / general

author: muthukural001
author_rank: Regular Contributor
timestamp: January 28, 2020, 04:43:31 pm
content: Hello All,This is regarding giving external reset to Microcontroller ATMEGA328PB from its GPIO pin. Minimum reset pulse width required to reset the microcontroller is 2.5us. I am wondering that the circuit that I attached will give >2.5us pulse.The logic is that when GPIO goes high, the reset pin goes low. I am having the below queries,Q1: what will be the state of the GPIO pin the moment Microcontroller sees the falling edge on the reset pin? It will stay high until the minimum reset pulse width criteria achieved?Q2: Implemented a voltage divider with GPIO pin and a bulk capacitor to drive gate of the MOSFET. The reason for voltage divider and a bulk capacitor added is to hold up the high state if the GPIO pin goes to tristate after seeing the falling edge on the reset pin. Is this ok?Q3: Is there any other alternate to do the above?Thanks and Regards,Muthu

author: retrolefty
author_rank: Super Contributor
timestamp: January 28, 2020, 05:55:48 pm
content: I've seen several external circuits designed so a micro could reset it's self but they either take a ridiculous number of external components or consumes power when not needed, etc. The best way to do it on a avr328 type is to engage the watchdog timer with it's minimum trigger time. Works great and uses 0 parts, no output pin, and zero wiring.

author: FenTiger
author_rank: Regular Contributor
timestamp: January 28, 2020, 06:54:51 pm
content: You can get ICs to generate a reset for you, such as this one:http://www.ti.com/lit/pdf/snvs154This looks like it'll do what you want without any extra parts.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 28, 2020, 07:10:33 pm
content: Quote from: FenTiger on January 28, 2020, 06:54:51 pmYes. Doubles as a voltage supervisor as well.As retrolefty said, there should be a very good reason for not willing to do it in pure software though (through provoking a reset.)

author: MarkR42
author_rank: Regular Contributor
timestamp: February 03, 2020, 10:58:14 am
content: This does seem like an unnecessary complexity.Why not have a small finger coming out of the box and presses the mechanical reset button?The microcontroller you're using has a software reset (I think everything does) which you can just activate. This triggers the same logic as power-on or external reset.It also probably has a hardware watchdog built-in, which will reset the chip if configured.

author: IanJ
author_rank: Unknown
timestamp: February 03, 2020, 11:56:56 am
content: Quote from: muthukural001 on January 28, 2020, 04:43:31 pmThe problem with some of these circuits is the startup condition of the circuit I.e. what exactly happens when power is applied. You can find your mcu doesnt even want to start up due to reset pin voltage levels and timing.Then theres reliability if you pull power and back in again etc etc.....Ian.

author: mark03
author_rank: Frequent Contributor
timestamp: February 03, 2020, 05:34:12 pm
content: Quote from: retrolefty on January 28, 2020, 05:55:48 pm^^^ This. Is there any MCU on the market today which cannot be reset from program code, without needing a hardware "trick" like the one proposed?

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 03, 2020, 07:30:50 pm
content: Quote from: mark03 on February 03, 2020, 05:34:12 pmWell, not the one the OP is using, but that may surprise you, yes there are!I remember working on Cypress FX1/FX2 MCUs years ago (which are still on the market AFAIK), and IIRC, they had no embedded watchdog and no real means of properly triggering a full reset from software. So if you wanted that, you'd need an external reset/watchdog chip.I'm sure there still are a few other MCUs in this case, but yes, it's become an oddity and if you can, they should just be avoided.

author: IDEngineer
author_rank: Super Contributor
timestamp: February 03, 2020, 11:15:42 pm
content: Quote from: SiliconWizard on February 03, 2020, 07:30:50 pmSeems like code could always cause at least asoftreset by simply setting the PC to the startup address. Perhaps that would be enough in some circumstances. However, a true hard reset would likely also clear some hardware/peripherals to known states so it's definitely not a 100% solution.Just occurred to me: I wonder if watchdog resets truly yield the same internal state as an externally-generated reset? That sounds like it could be vendor- or device-specific. I've never had a reason to investigate it.EDIT: Just checked the PIC18F family that I'm presently using and its WDT drops right into the same internal Chip_Reset signal as the external pin, so at least in this one case the WDT yields the same result as an external reset.

author: Scrts
author_rank: Frequent Contributor
timestamp: February 03, 2020, 11:51:22 pm
content: There's also a known way in the industry to do kamikaze resets is to hook up external watchdog and simply stop serving it once you need a hard reset with known boot up sequence.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 04, 2020, 02:45:44 am
content: Quote from: IDEngineer on February 03, 2020, 11:15:42 pmOn all MCUs I have ever used, I'd say yes. The only thing that would obviously differ is the state of the "reset cause" register, for the MCUs that have one. In this case, there's usually one bit per "cause", with often the following: external reset, brown-out, watchdog, unhandled trap...

author: wraper
author_rank: Unknown
timestamp: February 04, 2020, 02:51:58 am
content: Quote from: SiliconWizard on January 28, 2020, 07:10:33 pmAtmega has it's own voltage supervisor though.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 04, 2020, 03:08:14 pm
content: Quote from: wraper on February 04, 2020, 02:51:58 amSo definitely no rationale for using an external IC for this MCU.Even if it's obvious: this wouldn't even be any safer than using internal means (watchdog for instance), as it would require the toggling of a GPIO, which would assume that code can still be correctly executed on the CPU.

author: Jan Audio
author_rank: Frequent Contributor
timestamp: February 04, 2020, 05:07:16 pm
content: Just return from your main loop.Will it reset Atmega also ?

author: GeorgeOfTheJungle
author_rank: Super Contributor
timestamp: February 04, 2020, 05:54:51 pm
content: Code:((void(*)())NULL)(); //Play it again Sam :-)

author: David Hess
author_rank: Super Contributor
timestamp: February 04, 2020, 06:52:40 pm
content: If I had to do it externally, I would tend toward some variation of a set/reset latch but that leaves how to reset it. Ultimately this becomes a triggered monstable multivibrator unless there is some specific condition to wait for before allowing the microcontroller to come out of reset. There are microprocessor supervisory ASICs specifically designed to perform this function.

author: cv007
author_rank: Frequent Contributor
timestamp: February 05, 2020, 12:01:44 am
content: >Just return from your main loop.>Will it reset Atmega also ?There may have been different ways it was done in the past (and I guess it depends on the c runtime library), but if you return from main (on an avr) you get a cli and are then into an endless loop (until ext/wdt/por/bor takes you away). So unless you want to be in an endless loop with interrupts off (on an avr), don't return from main. A 'bad interrupt' will end up with a jump to 0 (not a great idea in any case, but on an avr0/1 since no reti you will leave the lvl0ex bit set and no more interrupts).Unless you reset the registers to their default settings, you will be left with a potential 'mess' on your hands (peripheral registers in unknown states) if you try anything other than some form of true reset. On the avr, the watchdog does the job, with some cleanup needed after. On the avr0/1 you now can do a software reset (and the bad interrupt function should do a software reset so the ex bits are cleared). On the lowly pic, you get an instruction to do the job.One unusual thing on something like a pic16F15354 (and similar), is the pps registers only take on the reset values after a power on reset. They can be handy bits to communicate to the 'other side' of the reset when needed without having to deal with ram as the comm bits.

author: mark03
author_rank: Frequent Contributor
timestamp: February 05, 2020, 01:31:11 am
content: This is probably a dumb question, but if you were going do the reset externally, what's wrong with simply connecting a GPIO directly to reset, with a pull-up resistor (assuming an active-low reset)? When you drive the GPIO low, wouldn't it stay low just long enough to trigger the reset, then go tri-state as the reset takes hold?

author: cv007
author_rank: Frequent Contributor
timestamp: February 05, 2020, 07:57:48 am
content: >When you drive the GPIO low, wouldn't it stay low just long enough to trigger the reset, then go tri-state as the reset takes hold?I think you end up 'losing' your pins before the 2.5us, so you may not get to the required time (the 'guarantee' pulse time which always produces a reset). What happens in that case, I don't know but maybe you end up with no reset and all your pins back to default state.

author: David Hess
author_rank: Super Contributor
timestamp: February 05, 2020, 10:19:58 am
content: Quote from: mark03 on February 05, 2020, 01:31:11 amIf reset is not edge triggered, then the race condition may not allow reset to be completed leaving the microcontroller in an unknown state.

author: Jan Audio
author_rank: Frequent Contributor
timestamp: February 05, 2020, 02:36:45 pm
content: Quote from: cv007 on February 05, 2020, 12:01:44 amExpert knowledge i tend to forget, might remember vaguely once i need it, and also forget where i readed it.For the rest : very nice to know.