pfalstad / circuitjs1

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

op amp freaking out in differentiator #82

Open dragoncoder047 opened 3 months ago

dragoncoder047 commented 3 months ago

image

Standard differentiator circuit, just different values than the example. Scope is of the op amp output. When I toggle the logic input, I expect a sharp pulse in the opposite direction from the op amp and then silence. Instead it freaks out.

Interesting to note that when I bring up the example (5k resistor, 2µ cap) and change the triangle wave to square wave, it does not freak out like this. When I change it to 1k and pulse wave, it freaks out when it's 5V and ok when it's 0V

pfalstad commented 3 months ago

Hmm, that's weird. If you make the timestep smaller (like 3u) it fixes it. Or adjust the values.

Do you have "trapezoidal approximation" unchecked? You could check that, and it fixes it for me. That's weird, because usually trapezoidal is less stable.

dragoncoder047 commented 3 months ago

I left everything besides the component values the default. So trapezoidal was checked on the capacitor.

If it has anything to do with it, here's my chrome://version:

122.0.6261.89 (Official Build) Built on Raspbian , running on Raspbian 11 (32-bit)

Perhaps it's 32-bit vs. 64-bit floating point error.

pfalstad commented 3 months ago

I thought javascript floating point always used double precision. Otherwise lots of examples would not work, I think.

dragoncoder047 commented 3 months ago

As a reference, I made the same circuit, set time step to 3µs, and it still freaked out.

Other machine chrome://version:

114.0.5735.119 (Official Build) (64-bit)