One-shot pulse on button press and on release?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
georgehawkins
 
Posts: 24
Joined: Wed Jun 12, 2013 12:12 pm

One-shot pulse on button press and on release?

Post by georgehawkins »

I have a simple switch, i.e. a classic SPST, and it spends a lot of time either pressed or released.

I have an MCU that can be woken from a deep sleep state by a pulse on one of its pins.

I want to generate a wakeup pulse when my switch changes state from released to pressed and also from pressed to released.

Looking around the web I've found lots of examples of using things like a 555 to generate a single pulse when a tactile button is pressed.

In these examples it's generally assumed the button will almost immediately be released and no one is that interested in the release part.

This is not the case for my switch - it stays a long time in both the open and closed state and I'm interested in the transition in both directions between these states.

When no state changes are occurring my MCU is in deep sleep and it consumes around 30uA so the whole thing would be rather pointless if the pulse generator logic involved a continuous noticeable current draw e.g. of a few mA.

Can anyone suggest a power efficient way to produce such a one shot-pulse generator that produces a pulse both when a switch is opened and also when it is closed?

Thanks for reading and thanks for your suggestions :)

/George

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: One-shot pulse on button press and on release?

Post by zener »

What MCU is this? I am assuming you have an edge triggered interrupt that detects either a positive going edge or a negative going edge. So that means you do not need a full pulse. What that means is half the battle is over, your MCU should be able to detect either the press or the release. As for the other direction, can you set up another pin as another edge triggered interrupt with the opposite polarity?

User avatar
georgehawkins
 
Posts: 24
Joined: Wed Jun 12, 2013 12:12 pm

Re: One-shot pulse on button press and on release?

Post by georgehawkins »

Thanks for your help. The MCU is an STM32F205 that's part of an Electric Imp.

Unfortunately the wakeup on the Electric Imp seems to be level rather than edge triggered.

The processor comes out of standby mode when pin 1 of the Imp is high (and cannot go back into standby mode while the pin remains high).

If I look at the STM32F205 datasheet the behavior of the Imp seems at odds with the details described for the WKUP pin of the MCU but I do not know how the Imp is wired internally, i.e. whether the wakeup pin on the Imp module is wired directly to the WKUP pin of the MCU or whether there is intermediary logic.

At any rate with testing level triggering is what I see (and others).

So I really do need a pulse - if I connect my switch directly to the wakeup pin then when the switch is closed the device is woken and cannot go back into standby while the switch remains closed. My switch - a simple SPST - is not a tactile button and switches state only occasionally and stays in its new state, i.e. open or closed, for substantial periods of time. I want to wake on the transitions from open to closed and also from closed to open.

I was thinking maybe I could use a dual monostable multivibrator. I found these devices as a result of a lot of Googling rather than because I already knew about them. It looks like I could wire the one switch to both of the monostable vibrators in a given IC and configure one of the vibrators to generate a pulse on a rising edge and the other to generate a pulse on a falling edge.

However there seem to be so many variants of the dual monostable multivibrator IC from various manufacturers that I can't determine which is considered the industry bog-standard, i.e. best for hobbyists, and more importantly I find it hard to determine from the data sheets:
  • How much power the IC consumes - fairly important considering the whole point is to save power - the Imp uses 30uA in standby and 30mA when doing light work so if the dual monostable multivibrator consumed much more than the Imp in standby mode it would be pointless.
  • While a monostable multivibrator should generate a one-shot fixed length pulse if a given input pin goes high, it's unclear what the behavior is if that pin remains high indefinitely - I'm hoping nothing but I'm not sure.
E.g. here is one such chip - the CD74HC221E from TI.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: One-shot pulse on button press and on release?

Post by zener »

This differentiator should meet your requirements. Using a 100K resistor should activate the input for about 5mS. You would need a double throw switch however. Sorry for the blurry picture...
Attachments
imp.JPG
imp.JPG (411.43 KiB) Viewed 1061 times

User avatar
georgehawkins
 
Posts: 24
Joined: Wed Jun 12, 2013 12:12 pm

Re: One-shot pulse on button press and on release?

Post by georgehawkins »

Unfortunately my switch is a SPST and I can't change it :(

I've looked at how to get an SPST to look like a SPDT to the rest of the circuit - most suggestions involve a relay but I presume a relay would introduce too much power consumption in itself to make this a possible solution in this setup where low power is key.

User avatar
Renate
 
Posts: 291
Joined: Tue Nov 13, 2012 3:21 pm

Re: One-shot pulse on button press and on release?

Post by Renate »

You could use an XOR as a differentiator.
I think that you want to build in a bit of noise immunity to the input though.
Then you might want to use a Schmitt trigger for input and that would leave you with two IC packages.

Here's a way with a single IC and a good deal of noise immunity.
C1 & R2 are input filtering
C2 & R4 are for the contact closure pulse.
C3 & R3 are for the contact release pulse.
R1 is the input pullup and the value could be increased if you want to save every microamp.
pulse.png
pulse.png (3.27 KiB) Viewed 1038 times

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: One-shot pulse on button press and on release?

Post by zener »

That should work, and the quiescent current will be low, about a micro-amp or less. If your switch has a positive common (pin 2 as shown in the schematic) then you would change R1 to a pull down. I don't know the pulse width you will get but it should be long enough. You could always increase the resistors (R3 and R4) (or reduce the capacitors) if you wanted a longer pulse.

User avatar
georgehawkins
 
Posts: 24
Joined: Wed Jun 12, 2013 12:12 pm

Re: One-shot pulse on button press and on release?

Post by georgehawkins »

Thanks Renate - I've ordered the parts and will give this a try :)

I see Digikey gives the quiescent current for 4093B ICs as around 2uA.

I've also ordered an ATtiny85 - it seems terrible to use an MCU for this kind of task. But it's hard to argue with the form factor and price. And the deep sleep current for the ATtiny85 is a tiny 0.1uA.

Will compare your solution and a programmed one using an ATtiny85 and see how things work out :)

User avatar
lyndon
 
Posts: 281
Joined: Tue Mar 29, 2011 5:28 pm

Re: One-shot pulse on button press and on release?

Post by lyndon »

georgehawkins wrote:I've also ordered an ATtiny85 - it seems terrible to use an MCU for this kind of task.
We need to get over thinking that "a whole MCU" is too much for any task. I designed a PC board with the tiny85's cousin: a tiny13. It does nothing more than wait for a double click of a pushbutton and output a single click. The person I built it for was thrilled because it solved a problem he had.

Like you discovered, the chip is inexpensive and barely uses any power in deep sleep mode. It's perfect for this kind of task. As long as it meets cost targets and does what you need, use it!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: One-shot pulse on button press and on release?

Post by adafruit_support_mike »

There are arguments to be made either way.

Microcontrollers make it possible to do things that would be bulky or convoluted with discrete hardware.. there's no denying that. The trouble is that microcontrollers provide an opaque abstraction of a problem, both conceptually and at the hardware level.

All software is a logical model of the physical world. People used to build analogue computers using circuits whose behavior mapped well to the phenomena they wanted to observe/predict, but then it because easy to calculate arbitrary functions digitally. Then, as one computing expert put it, "we became so fascinated by the model of the model we forgot we were building models in the first place."

And of course, from the hardware point of view a microcontroller looks the same no matter what code it's running. You can't deduce a microcontroller circuit's function by inspection, and programmers don't have to show their work. All the design assumptions, intermediate values, and state variables are hidden inside the package.

Put it all together and you have a skill set that doesn't provide much insight for any other kind of circuit design. From there it's only a short stroll to "if all you have is a hammer" territory.

Don't get me wrong.. I buy microcontrollers by the hundred and think the ATtiny10 makes a great multiphase non-overlapping clock. I also know how to build the same clock from a 74HC14 and a couple of AND/NOR gates though. The discrete version costs about half as much as the microcontroller, but takes about a square inch of PCB space. The microcontroller costs more, but is about 1/50th the size.

YMMV, but I find that working with non-microcontroller designs gives me more programming insight than vice versa.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”