pfalstad / circuitjs1

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

Odd behaviour of Schmitt trigger slew rate #104

Open gsuberland opened 2 months ago

gsuberland commented 2 months ago

The Schmitt trigger has a slew rate property that can be specified in V/ns. However, the actual slew rate seems to be dependent on what is connected to the gate, and even when other Schmitt triggers get connected or disconnected to things. I have noticed this in multiple scenarios.

Here's an example circuit: https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjOCmC0YEwjmAdAVgJwGZ0A4DscmYADAGxgAs8IqxNIFmNMYYAUGDgtBRTosX7RMOCgP51MyJilKkQUzE0UhibAEogefcVr504g1YgHEz5+nSto2Ad3DEKBo60zzDEtgCdwYN7td3VHk6EjM2AHNffzhg6PcCYzUkJmFDXWg4RI9jBABjABsAQwBbAAcACgqi6AAjAEoAehIAGgAdAGdoYmQzHHaOnr76uy0wUmchVgQctSjMuDFFugWluKtRtIMnLUx0uBxPey3EQ7H0GbO1Y7AL06m72c24RYzbmaM1MDwIUiWXCa6UIwdAgHCoBieKJ-RBxGFZBAbKLjAxxFGIRIbHw8fg5WDUWamTbvN6Ap7Y9F4ylXBzmOZjMlnWCAzCOJJsPJ6XFGHGw9yIFiI5BIVB7CiEOR4VDSzB4JhDYjseY6WLyXkI9k+cYZFWfVTIdg+A7c3GvQk9JWIM1xF5LTGqDlW-6mtb8uCCrQKszwVnYHDEPB4Yi4VD+0EKw1OgJkvUWyIMPZ8hMze30pRBeTpjGIh3fCBZnKMD4SKDQUHgyEOnzBSYMdDuWMG+MUetJlsJHNqTnt3Q91Umd2wbhexWEYh+gNBkNh-Xe7x1hv8ItA-WWoOukDr7Ps6FGfsTXGpjg-EAH3RbwlgEFgiE6NQ+HCJnJ4UgmpJNqIv3FxL-bjac39n1fJMZg9bpenMH1x1wSdg3BGcI3nQCjAvRtLXQF8kwwjsdzBf0k0OAwjzzPDa2wlcrzLG9K3vEByJyEgdnND8HCYtFHCIztHUY2seJA5gh1nMwXi4H5UCyPAcHQVBeAoEIIPYApwEXU9nRMSiJAgwxg0waVFloUhAzwB0lONXQCz3UspmQV9WXIQQ-HrGBjLUJSa10M8cgQDSxhsx8yBIHBHNIZyTLBJ8jEI3RvJgazbIChzsBC6AXMdfEU24aYFH2ATqB6KV4BwUgXkcF5cC4ITLXS7KViyrMsTGAkeSyjVrEVTYRDU4RRHAA4HWOTqMj2Ws1E0bQpjVfQGVyUw6ToCErH1VAOAq8bpu6sRmWMFRZEzaRlGkfrdh6rbhDZLa1AAexMGE6CcXBZ1uUV4AWiDioWgcFDYa75Fuhhg2M17RwhCAEEzb6aBkYx7tBIHzGw4JYk+0Uvuu1BjIgO7g1hoSzAR96FBMdGvqAA

Both Schmitt triggers here are configured as 1.66V lower threshold, 3.33V upper threshold, 3.3V/ns slew rate, 3.3V logic high, and 0V logic low, I would expect a 1ns rise time and 1ns fall time. When simulated with a timestep of 1ps, the rise time is actually about 100ps.

However, if I then reduce the slew rate to 0.33V/ns, i.e. 10x slower, the rise time becomes 10ns as expected.

What's really bizarre is if you disconnect the lower Schmitt trigger (select both the Schmitt trigger and the clock source, and drag them so they're not connected to the trace) both the lower and upper Schmitt triggers' rise times become 1ns as expected.

pfalstad commented 2 months ago

Yeah, the slew rate doesn't handle nonlinear circuits properly. If there's multiple iterations to solve a nonlinear circuit step, then the slew rate gets multiplied by the iteration count. The inverter used to have a similar bug.