Generating reset from SPST switch both when opening and closing - Page 1
Forum section: electronics / beginners

author: Moriambar
author_rank: Unknown
timestamp: July 20, 2023, 09:16:30 pm
content: Hi, I have a circuit like the one attached, more or less:The closing of a physical spst switch has to:switch a loadbe read by an mcugenerate a reset pulse for an mcu, when the switch changes stateThe first two parts were easy: as per the schematic with a fet and a resistor all is good.The problem is that I have no idea how to generate the reset pulse, no way: it would be feasible if it were only upon closing or opening the switch, but the bidirectionality leaves me clueless.I tried to use passives and fets to no avail. If a component is needed fine, but this should be as low power as possible, since it's a battery operated circuit.The most important thing is that I have to learn what I'm missing and ignore.Cheers!

author: Buriedcode
author_rank: Super Contributor
timestamp: July 20, 2023, 09:49:22 pm
content: Well, what are the other restrictions here? size? cost? power?I'd say a simple edge detector, you can clean up the input with ttl logic, and use XOR to create an edge detector that'll output a pulse on a rising or falling edge. The width of this pulse can be adjusted by varying the values of R and C. Rather than draw something, I stole/found an image from the web:https://sound-au.com/appnotes/an005-f2.gifAs it requires an input that can drive at least some current (the input is both driving the logic input, but also the RC circuit) you'll have to buffer the input from the switch since the 100k pulldown won't have the drive capability. Even though you can get single XOR gates in SOT23-5, if space isn't a problem, just go with a multigate package like the 74HC(T)86 and use one of the other XOR gates as a buffer.You might be able to use a NAND gate instead but the same deal applies. And the other two extra gates can be used to generate pulses of only rising, or only falling.If you need it to work at >5V, then the old 4000 series CMOS will do. Either way the power consumption will be very low indeed - unless the switch is firing at kHz, the levels will be mostly spatic, so uA.

author: Psi
author_rank: Super Contributor
timestamp: July 20, 2023, 09:52:08 pm
content: If you want a RST to occur every time the switch state changes then what is the point having the MCU other input to read it? Are you saving the state to EEPROM between reboots or something?

author: Manul
author_rank: Super Contributor
timestamp: July 20, 2023, 09:57:23 pm
content: First of all, depending on the MCU, you might be able to initiate software reset - you already read the state of the switch. Secondly, it is worth a think if reset is really needed. It’s generally not the most power efficient or elegant way of handling things.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 20, 2023, 10:25:01 pm
content: Green is button input, blue is reset.The capacitor will make a momentary voltage doubler when releasing the button, probably the MCU ESD protection diode will be fine with this, it's just a 10nF capacitor with a 100K resistor in series, the discharge current will be very low, but you might also add a schottky diode like the 1N5819.Pressing the button will instantly reset the mcu, once the capacitor charges the reset pin will be released, the button state can be read regardless of the reset state

author: Psi
author_rank: Super Contributor
timestamp: July 20, 2023, 10:29:35 pm
content: Quote from: DavidAlfa on July 20, 2023, 10:25:01 pmHe wants it to cause a reset on button press and on button release.So it has to pulse low for bothSo far the easiest way I can think of to do it is to swap the push button for one that is SPDT and use a diode.But it seems to me like he is trying to do something the wrong way and there is a better solution

author: Moriambar
author_rank: Unknown
timestamp: July 21, 2023, 07:08:27 am
content: Ok I'll clarify, in order to have a better solution maybe.So basically this circuit has to be used in two modes, switchable via an spst switch (no pushbutton). In one "mode" a VR module is used and that has to be powered, otherwise a different thing has to be done.So what I did is use the switch to turn on the fet in order to power the VR module (I don't want it to interfere when it's not used). At the same time the sensing of the line is done during the "setup" method: this way I either setup the serial port and the VR module or the interrupts/other things.The fact is that resetting the mcu when switching grants me the ability to use the pins otherwise used as serial. I don't know whether there's another way...cheers

author: ledtester
author_rank: Super Contributor
timestamp: July 21, 2023, 07:44:23 am
content: Quote from: Moriambar on July 21, 2023, 07:08:27 amIf I understand what you're saying, on reset you are having your MCU configure its GPIO pins one way or another depending on whether it detects the VR unit is being powered or not.Which MCU are you using? You should be able to change the configuration of any GPIO pin at any point in time without having to reset the MCU.

author: Moriambar
author_rank: Unknown
timestamp: July 21, 2023, 07:49:20 am
content: Quote from: ledtester on July 21, 2023, 07:44:23 amIt's an attiny804. The fact is that I don't initialize the VR module and the serial if the VR is not necessary. Otherwise it will init the vr in any case, try and fail communicating with it, and start the serial... I don't think that is optimal

author: ledtester
author_rank: Super Contributor
timestamp: July 21, 2023, 08:08:38 am
content: Does the '804 have a way of determining if the VR unit is being powered - or is that the crux of the problem?One idea is to have power to the VR to also cause a GPIO line on the 804 to go high/low. For instance, a resistor could keep the GPIO line in one state in the absence of any power to the VR. Toggling the SPST switch applies power to the VR and also changes the state of the GPIO line (perhaps through the use of a transistor). Then the 804 could just monitor that GPIO line (for instance, by a pin change interrupt or just reading it every so often) to determine if it needs to initialize the VR.

author: Moriambar
author_rank: Unknown
timestamp: July 21, 2023, 08:19:02 am
content: Quote from: ledtester on July 21, 2023, 08:08:38 amoh yes, that is the "MCU" label in the schematicQuotethat is interesting and simple enough I think.I'll try it this evening, thanks

author: Psi
author_rank: Super Contributor
timestamp: July 22, 2023, 03:02:11 am
content: All ATTiny/ATmega can change their GPIO and specials purpose pins to any mode at any time and as often as you want.If you want some advanced notice that the switch is changing, you can achieve this by using a SPDT switch and monitoring both sides with interrupt lines on the MCU. The MCU can detect when the switch starts to move because it's a 'break before make' switch. One side disconnects, then there is some mechanical travel, and the other side connects.This way you know a few 10's of microseconds before the switch ends up in its resting position.Note that there is some issues with debounce when using switches and especially when using switches that trigger hardware interrupts. So you need some small caps to add hardware debounce to avoid massive number of interrupts as the switch contacts bounce. (if that is an issue in your application)

author: Moriambar
author_rank: Unknown
timestamp: July 22, 2023, 08:25:16 am
content: ledtester's idea worked fine and was quite easy to implement.Thanks y'all