sharpie7 / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
2.29k stars 633 forks source link

Bouncy Switch feature request #838

Open ericfont opened 1 year ago

ericfont commented 1 year ago

Circuitjs currently only implements ideal switches, which transition immediately between connected and disconnected. However, I would like a feature request to simulate a bouncy switch in circuitjs.

I tried making a circuit using the available tools here that simulates a 1 millisecond period of noise after the switch is clicked on:

circuit-20230126-1707

What looks like an inverter is a buffer delay with a fixed delay of 1 millisecond. The switch is connected to input "C" (for "Closed") of a custom logic chip, with the delayed version connected to input "D" (for "Delayed"), and a noise signal into input "N". That custom logic chip has the following input-output definition:

00?=0
010=0
011=1
11?=1
100=0
101=1

That custom logic chip definition basically says:

The scope shows what looks like a bouncy switch that has a 1 millisecond period of noise after the switch is clicked on. However, there are some limitations of using this custom logic chip to simulate a bouncy switch which would be nice for a feature request:

  1. A real bouncy switch would have a random time range for bouncing, not a fixed duration, maybe which can be set between a minimum bouncing time and a maximum bouncing time, before it settles.
  2. While the custom logic chip has the concept of high impedance output with the symbol _, it doesn't seem to allow the concept of a closed connection (a short circuit). I can only copy a logical 1 or logical 0 voltage to the output, but that doesn't actually simulate a closed connection. If I'm just dealing with logical inputs, this is fine, but if the inputs are connected to an actual circuit, then simply copying a logical voltage to the output doesn't properly simulate the effects of connecting a circuit together.
  3. A real bouncy switch actually has some random resistances while the switch is making contact. In my attempt at simulating the bouncy switch, I'm just copying a logical value of a noise voltage over, but in reality I should be simulating a random resistance between input and output.
  4. Would be nice for the switch graphics to be animated like a bouncy switch, randomly making or breaking contacts.
  5. Would be nice to easily extend to multiple poles in addition to just SPST.

(And of course there are more minor details involved in a bouncy switch, but probably too much for circuitjs to worry about.)

Anyway, just wanted to make a feature request for a bouncy switch. If it is too much effort or out of the scope of circuitjs then that is of course understandable. As always thanks for such a powerful and simple simulation tool.