Skip to content

Commit a2c1949

Browse files
committed
Switch added
1 parent 19b8938 commit a2c1949

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/Electrical/Analog/ideal_components.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,55 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref))
391391
v ~ i * R
392392
end
393393
end
394+
395+
"""
396+
Switch(; state_init = false, Gon = 1e5, τ = 1e-3)
397+
398+
An electrical switch that is controlled by a boolean input.
399+
400+
# States
401+
402+
- See [OnePort](@ref)
403+
- `state(t)`: Boolean input
404+
- `state_filtered(t)`: Filtered delay of state(t)
405+
- `G(t)`: Conductance
406+
407+
# Connectors
408+
409+
- `p` Positive pin
410+
- `n` Negative pin
411+
- `input` [RealInput](@ref) Input of type Bool. false: switch is open. true: switch is closed.
412+
413+
# Parameters:
414+
415+
- `state_init`: Initial switch state of type Bool. false: switch is open. true: switch is closed.
416+
- `Gon`: [`S`] Conductance when switch is closed.
417+
- `τ`: Parameter for filtered delay.
418+
"""
419+
420+
@mtkmodel Switch begin
421+
@extend v, i = oneport = OnePort()
422+
423+
@parameters begin
424+
state_init = false
425+
Gon = 1e5
426+
τ = 1e-3
427+
end
428+
429+
@components begin
430+
input = RealInput()
431+
end
432+
433+
@variables begin
434+
state(t)::Bool
435+
state_filtered(t) = Real(state_init)
436+
G(t)
437+
end
438+
439+
@equations begin
440+
state ~ input.u
441+
D(state_filtered) ~ (state - state_filtered)/τ
442+
G ~ state_filtered*Gon
443+
i ~ G*v
444+
end
445+
end

0 commit comments

Comments
 (0)