PIC reset and I/O on the same push-button?
I am trying to design a little circuit to control a light.
It is supposed to be a one-push-button affair, with a long push for something and a short push for something else.
One crucial thing is, that if the programme goes bananas, the push-button must also reset the microcontroller – a PIC12F629.
Luckily, the processor is not too busy, just clocking around a state machine on the button pushes, so I am proposing the following circuit:
My cunning plan is, that operating the push-button resets the processor via a capacitor, and holds the other input pin low.
On reset, the outputs annoyingly automatically go high-z, but are immediately sets back to their pre-reset state by the programme, which then starts a 20ms software timer for de-bounce.
Any bounce at this point will just – I hope – give multiple resets and mean the outputs go hi-z and get restored a bunch of times.
If the input is high, it was a too-short invalid push.
If the push-button is still low, it is a valid push and a 200ms timer is started.
If the input is still low, it is a long push
If it is high, it was a short push
In either case the state can be changed appropriately.
The extra transistor is there because I want long wires to the push-button, so some spike protection is needed, and low-value resistors will add some EMI protection.
The diode stops the /MCLR getting greater than 0.6V above the supply rail.
This would be too much for most PIC pins, which are limited to +0.3V.
/MCLR is permitted to rise to 13.5V to initiate programming, but doesn’t initiate programming until it reaches rail+3.5V, so it is both safe and won’t enter programming mode.
The circuit relies on the internal 50-400µA ‘weak pull-ups’ provided inside the chip. I am thinking a collector resistor to the rail might be a good idea.
/MCLR is not allowed to have negative spikes exceeding 80mA for fear of latch-up in the chip, so the recommended 50-100Ω series resistor will also get added.
Is there a better way to do this?
If you respond below, our spam-blocking system may throw away your comment.
Better email email@example.com with ‘Reset’ in the title.
No email addresses are collected for marketing (or any other) purposes from responses to this blog. I will keep it that way for as long as possible.