# LTspice: simulating the bounce effect of a push button

I'm trying to reproduce in LTspice the switching response of a push button with bounce effect as shown on the second page of the SN015 Support Note by Würth Elektronik. Here is an excerpt:

What I have tried to do is use two voltage-controlled switches to toggle between transients and the low level, but there must be a better way to do it.

I've found the article below which is close to what I'd like to achieve, but it seems like the transients are regular and the logical level is low while, in the case of the push button, the bounce effect happens during a high-to-low transition.

LTspice: Using Time-Dependent Exponential Sources to Model Transients

• You can see my post here on how to use a PWL source to do this. If you need randomness, then it gets more complicated. forum.kicad.info/t/switch-potentiometer-simulator/15544/9 Commented Jan 6, 2023 at 20:37
• Create whatever signal you need, put it into a wav file, and play it back in LTSpIce as a source Commented Jan 7, 2023 at 0:19
• I would use a program like octave (sort of a free, largely command compatible version of Matlab) to do both. If you can't construct the signal from the command line, look up "datathief" Commented Jan 7, 2023 at 23:22
• I did something similar to @ScottSeidman 's suggestion in the linked answer below. It seems like it can be quite a powerful method to put in your toolbox. electronics.stackexchange.com/a/620082 Commented Jan 8, 2023 at 4:19
• @SteKulov. That looks even easier! Commented Jan 8, 2023 at 15:13

I'd suggest using a PWL voltage source. Convert that graph into a .txt file of time vs. voltage level, as accurate as needed. Then set the voltage source to use that PWL file as input. If you need an actual switch contact, feed this into a voltage-controlled switch.

• Thank you, that worked. I've used the spice directive PWL repeat forever (file=switch-response.txt) endrepeat to make the transition and bounce effect recurrent. Commented Jan 6, 2023 at 22:10
• Also note in addition to repeat, the command can also trigger on some condition, and scale (thanks Gabino.) Commented Jan 9, 2023 at 14:13

You can use the rand() function to generate a noise-like signal, that combined with time and a bit of math and logic operators can produce something like switch bounce when used to control a behavioral voltage source.

This example circuit generates some random pulses and then using ORs and ANDs and NOTs combines them with logic 1 signals based on the simulation time to give a 20 uS delay at the start, a 1 V signal for another 280 uS, and then the random pulses for another 200 uS.

Update: Here's a version that adds bounce on switch close and makes it easy to set the timings by right clicking the top .param statement and editing the values in the list, as well as having the BV control a switch component.

• Thanks. That is the perfect fix for my initial schematic. I did use rand() but missed the logical operations with time. I've just added a multiplication by 5 of the result to reach 5V. Now I realize that the signal is not always alternating between 0 and 5V so sampling the signal would probably be more accurate for the simulation. Commented Jan 7, 2023 at 20:25
• @noeld Just added an update. Commented Jan 7, 2023 at 20:27
• Thanks for your examples that were very helpful to me and that I reproduced to play with. They do reply to my question. I have accepted the answer about using the PWL voltage source because in the end this is the solution that allows the more accurate representation of the signal that I wanted to simulate. Commented Jan 7, 2023 at 20:58
• @noeld Yes of course, the PWL will let you make pretty much any waveform you want, so for accuracy you can't beat it. Now you have several more tools in your toolbox, and that's always a good thing :) Commented Jan 7, 2023 at 21:17
• every proposed solution here is great and each will be useful for different purposes whether I have a graph or an actual signal sample or a random signal. My toolbox is definitely packed with many more powerful tools and... knowledge! :) Commented Jan 8, 2023 at 20:40

The bounce effect is not random and its evolution can be represented with a decaying oscillation, both in amplitude and frequency. This implies no other mechanical perturbations; if there are, you'll need extra modelling (which I heavily doubt is present in many, if any models). I'm nowhere near my tools but, you can use your favourite RLC, driven by a VCCS (for example), and whose voltage then feeds a VCSW (set up with a negative hysteresis). The frequency will be a little bit more difficult to achieve but, it is possible by making the L or the C behavioural, controlled by a ramp (the integrated, or lowpass filtered pulse, for example). I doubt I'll be able to post a schematic anytime soon but, it should be fairly straightforward to build the schematic. I have and worked quite well.