Skip to content

Optocoupler CTR, SRAM reset restore, voltage-limited current source, macOS paste#241

Open
esaruoho wants to merge 2 commits intopfalstad:v3-devfrom
esaruoho:v3-four-more-fixes
Open

Optocoupler CTR, SRAM reset restore, voltage-limited current source, macOS paste#241
esaruoho wants to merge 2 commits intopfalstad:v3-devfrom
esaruoho:v3-four-more-fixes

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 2, 2026

Summary

Rebased onto v3-dev (replaces #223 which targeted master).

  • Adds adjustable CTR (current transfer ratio) for OptocouplerElm
  • Adds "Restore Contents on Reset" option for SRAMElm (snapshots initial state)
  • Adds voltage-limited current source (FLAG_VOLTAGE_LIMIT on CurrentElm)
  • Fixes macOS Cmd+V paste in Electron app

Fixes #150, #184, #149, #138.

Changes from master version

  • Extended v3-dev's dumpXml()/undumpXml() in CurrentElm and SRAMElm to serialize new fields
  • SRAMElm integrated with v3-dev's parseContentsString() helper

Test plan

  • Place Optocoupler → edit → verify CTR adjustment works
  • Place SRAM → load data → enable Restore on Reset → reset → verify data restored
  • Place current source → enable voltage limiting → verify current reduces at voltage limit
  • In Electron on macOS → Cmd+V → verify paste works

🤖 Generated with Claude Code

esaruoho and others added 2 commits March 6, 2026 08:21
…urce, macOS paste fix

- Configurable optocoupler CTR (pfalstad#150): Add CTR % parameter to edit dialog,
  scale CCCS transfer expression by CTR multiplier. Default 100%.
- SRAM restore on reset (pfalstad#184): Add "Restore Contents on Reset" checkbox.
  Stores initial map snapshot, restores it on simulation reset.
- Voltage-limited current source (pfalstad#149): Add compliance voltage mode.
  When enabled, current source becomes open circuit beyond max voltage.
- macOS Electron paste fix (pfalstad#138): Replace Menu.setApplicationMenu(false)
  with proper Edit menu so Cmd+C/V/X/A work in text fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When loading SRAM contents from a binary file, the filename is now
captured and displayed next to the Load button as "Loaded: filename.bin".
This helps users with multiple SRAMs identify which file was loaded into
each one, addressing feedback from @MatNieuw on issue pfalstad#184.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@esaruoho esaruoho force-pushed the v3-four-more-fixes branch from 5d6f4bb to c4d25b8 Compare March 6, 2026 06:23
@esaruoho
Copy link
Copy Markdown
Author

@pfalstad any takes on this?

@pfalstad
Copy link
Copy Markdown
Owner

I tried to do the limited current source thing once and got constant convergence failures. Looks like your version has the same issue. Try opening all the switches. Also I wouldn't have a separate checkbox for the voltage limiting. I would just use a default of 0 meaning unlimited.

<cir f="1" ts="0.000005" ic="10.20027730826997" cb="50" pb="50" vr="5" mts="5e-11">
  <w x="112 32 208 32" f="2"/>
  <w x="208 32 304 32"/>
  <w x="304 32 400 32"/>
  <s x="208 32 208 112" p="1"/>
  <s x="304 32 304 112"/>
  <r x="208 112 208 176" r="100"/>
  <r x="304 112 304 176" r="400"/>
  <r x="400 112 400 176" r="4000"/>
  <w x="208 176 304 176"/>
  <w x="304 176 400 176"/>
  <w x="304 208 304 176"/>
  <w x="304 208 400 208"/>
  <w x="304 208 208 208"/>
  <s x="304 208 304 288"/>
  <r x="208 288 208 352" r="600"/>
  <r x="304 288 304 352" r="200"/>
  <s x="400 208 400 352"/>
  <w x="112 352 208 352"/>
  <w x="208 352 304 352"/>
  <w x="304 352 400 352"/>
  <i x="112 352 112 32" f="1" cu="0.01" mv="5"/>
  <g x="112 352 112 384"/>
  <w x="400 32 400 112"/>
  <w x="208 208 208 288"/>
  <o en="20" sp="32" f="x3" p="0">
    <p v="0" sc="20"/>
    <p v="3" sc="0.05"/>
  </o>
</cir>

@pfalstad
Copy link
Copy Markdown
Owner

the sram thing is good

@pfalstad
Copy link
Copy Markdown
Owner

The optocoupler thing looks good. I would maybe just rename "CTR (%)" to "CTR Scale" because it doesn't look like the CTR is exactly 100... At least in my test case it wasn't.

@pfalstad
Copy link
Copy Markdown
Owner

the mac thing is good

@MatNieuw
Copy link
Copy Markdown

An optocoupler's CTR depends also on the current. There is usually a peak CTR between 5 and 20 mA diode drive current, and the peak varies per type. In the datasheets it is given as a percentage (like 80%), or absolute value like 0.8 . I think being able to specify a peak CTR at a certain diode current would be nice. As an example, the CTR specs from a CYN80N.
CQY80N

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants