Add relay contact switching delay with hard step resistance#289
Add relay contact switching delay with hard step resistance#289esaruoho wants to merge 3 commits intopfalstad:devfrom
Conversation
|
The smooth interpolation does not reflect real relay contact behaviour. If one relay controls a second relay and the first relay is de-energized, I expect (without extra circuitry over the coil of the second relay) a large voltage spike on the coil of the second relay. Measuring with HK19F-24V relays, coil self-inductance 7H and coil resistance 2880 ohm, 6 sm switch time, I measured spikes well over 500 V. |
|
@MatNieuw Thank you for this excellent feedback! You're absolutely right on both counts. Voltage spikes: Real relay contacts have a delay (armature travel time) followed by an abrupt open/close. The smooth resistance interpolation was suppressing the very inductive voltage spikes that make relay behavior interesting and important to simulate correctly. With your HK19F-24V example (7H coil, 2880 ohm, 6ms switch time), the >500V spikes are exactly what should happen when the contact resistance jumps from near-zero to megaohms — not a gentle ramp that lets the inductor current decay gradually. Simulation performance: You're also right that the smooth ramp was calling I've updated the PR to use a hard step:
This should now produce the realistic inductive spikes you'd expect. |
|
I don't see PR289 anymore, but you described solution is not complete
in all ways.
If a relay (basically a current controlled switch) gets its voltage,
the current starts rising somewhat delayed due to the self-inductance
(which is very much less on 5V relays than on 24 V relays). This is
easily seen on the scope.
As soon as the current reaches the threshold, the relay arm starts
moving from the NC to the NO contact (for a form C relay). The total
time until it reaches the other contact is the relay settle time
(inclusive contact bounce, but lets disregard that).
However, if the relays is disconnected from its driving source,
the current (and magnetic field) starts collapsing, the arm
starts moving much quicker, and after a (usually shorter time) reaches
the NC contact. This behaviour is important, because it means that at
the same time you can disconnect relay A from a bus, and connect relay
B, because A will have left the bus way before B reaches it.
The higher the (reverse) peak voltage, the quicker the magnetic field
will collapse, but that does not need simulation.
As an example, I have measured for HK19F relays an "on current" of 6.3
mA, and an off current of around 0.8 mA.
The current (version 3.1.4) relays don´t do this difference in on/off
timing, I found a reasonable compromise to set relay switching time to
2.5 ms. This gives exactly 6 ms "on time" inclusive current build-up in
the coil. And the release is quick enough.
|
|
@MatNieuw Thank you for the detailed analysis of asymmetric relay timing! You're right that the previous update was incomplete. What the model already handles:
What is new in this update -- separate Release Time:
For your HK19F relay example (6.3 mA on / 0.8 mA off), you could set:
This would give realistic break-before-make behavior where relay A releases well before relay B engages. |
|
Looks very good. I'll test it after Paul has merged this PR. |
|
unclear to me if there's a travel time now in which neither the NO nor the NC contact are closed (let aside contact bouncing). I'd think this should exactly be the switching time |
|
Travel time is specified from when the nominal voltage is applied until the NO contact is closed inclusive bounce, therefore it includes the time to build up the current/magnetic field, not just the actual travel time between NC and NO. |
|
@MatNieuw The travel time in the sim model starts when coil current trips the threshold. This is correct for a sim, if your relay data sheets specs cite some other composite value, you need to do the math on your own. |
Relay contacts (RelayContactElm) now interpolate resistance smoothly over the switching time instead of snapping instantly between r_on and r_off. The coil (RelayCoilElm) computes a fractional d_position that ramps linearly during state transitions, and passes it to linked contacts via setPosition(). Each contact derives its own fractional position (accounting for normally-closed inversion) and uses: resistance = r_on + (r_off - r_on) * d_position This gives a smooth visual and electrical transition matching the built-in relay behavior. Latching relay direction and motor protection switch instant-switching are handled correctly. Addresses sharpie7#983. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ation Based on community feedback from @MatNieuw: real relay contacts have a delay (armature travel time) followed by an abrupt open/close, not a smooth resistance ramp. The smooth interpolation was suppressing realistic inductive voltage spikes (e.g. >500V when de-energizing a relay coil with 7H inductance) and adding unnecessary per-tick computation during the delay period. The switching time delay is preserved (states 1 and 3 still wait for the configured time before changing switchPosition), but d_position is now binary (0 or 1) and resistance snaps between r_on and r_off. setSwitchPositions() is only called when the position actually changes. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Real relays release faster than they engage because the spring force assists the armature return. Add a configurable Release Time parameter (shown for Normal and Latching relay types) so users can model this asymmetry. When Release Time is 0 (default), it falls back to the Switching Time for backwards compatibility. Based on feedback from @MatNieuw with measured HK19F relay behavior. Co-Authored-By: Claude Opus 4.6 <[email protected]>
f2c6ddd to
907576a
Compare
Summary
d_positionis now binary (0 or 1), snapping to the new value only when the delay expires andswitchPositionactually changes. This models real relay behavior: armature travel time followed by an abrupt contact state change.r_on(closed) orr_off(open), never intermediate. The hard step produces realistic inductive voltage spikes when relay contacts open (e.g. >500V with 7H coil inductance), matching measured behavior with real relays.setSwitchPositions()is now only called when the position actually changes, not on every tick during the delay period, improving simulation performance.Rationale (based on community feedback): Real relay contacts have a delay (armature/contact travel time) followed by a hard step in contact resistance. Smooth interpolation was suppressing realistic inductive voltage spikes and adding unnecessary computation. Real relays also release faster than they engage due to spring-assisted armature return; the separate Release Time parameter models this asymmetry. See feedback from @MatNieuw.
Addresses sharpie7#983.
Test plan