pfalstad / circuitjs1

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

Pulse voltage stuck at 15.9154943092 duty cycle (square duty works) #95

Open signaldust opened 2 months ago

signaldust commented 2 months ago

For some reason, with the version at https://www.falstad.com/circuit/circuitjs.html when I draw a new voltage source (both one- and two-terminal versions seem to be affected) and change it to pulse mode, the duty cycle appears to default to 15.9154943092 and even though it can be changed in the dialog and using a slider, this doesn't seem to have any effect on simulation (ie. 15.9154943092 is still used).

Latest Chrome, macOS.

Loading an older circuit (the most recent I have has timestamp Jul 5 at which point there wasn't any issue) with pulsed source with duty cycle sliders appears to work just fine until the source is changed to some other waveform and then back to pulse, at which point it again sets duty cycle to 15.9154943092 and stops responding to changes. Copy-pasting an existing working pulse-source also doesn't break it, so it appears the issue is somehow linked to the waveform selection dialog.

signaldust commented 2 months ago

Looking at Chrome's dev-tools, there doesn't seem to be anything useful in console (ie. no errors); the only issue it complains is about component edit box form field elements not having id/name attributes, but I think that's probably not relevant, 'cos it happens even with component dialogs that work perfectly fine.

I also tried in Safari, with the same results, so doesn't appear to be Chrome-specific

pfalstad commented 2 months ago

It works for me.. I created a one-terminal voltage source, changed the waveform to pulse, changed the duty cycle to 50% and it works. A slider also works.

The weird default value for duty cycle is 100/(2*pi). It originally wasn't possible to change the pulse waveform duty cycle so it didn't matter that it wasn't an integer.

signaldust commented 2 months ago

Interesting, I just tried on another system running Windows and on an Android phone.. and I'm getting the same (broken) results on both. Tried clearing all side data too, no change. Not sure how to test the version directly from github though.

This used to work just fine for me as well just a month or so ago I think, I wonder if anything has actually changed since then?

signaldust commented 2 months ago

Ok, I figured out what is going on.

There is both a "square wave" and "pulse" in the waveform drop-down.

Choosing "square wave" works perfectly fine and allows changing the pulse width just fine (looks like that's what I was using in earlier circuits). Choosing "pulse" gives a duty cycle of 15.9, no matter what the duty cycle is actually set to. I guess the "pulse" choice is really a left-over and not really even needed anymore (except to support legacy files?) with duty cycle adjustable squares?