# Simulink “ideal switch” block changes output unexpectedly

I am attempting to simulate a DC motor circuit on Simulink. I have built the block diagram mainly according to a tutorial, and am confused about an aspect of it. The main circuit has a DC power source in series with an "ideal switch" block (triggered by a stair generator), a resistor to limit the inrush current, and the separately excited/permanent magnet DC motor block. When I cut out the switch block and just have the power source in series with the resistor etc. the circuit behaves roughly as expected, but when the switch block is added in, the response suddenly has massive current spikes (~10^4A rather than ~40A), often followed by large negative currents. My best explanation for why these negative currents are happening is that for some reason the initial massive currents are spinning the motor up very fast which increases the motor back emf to much larger than the supply voltage, but I am at a loss to explain the initial high current.

In the tutorial there is a second resistor which goes from between the switch and normal resistor to ground. This seems to fix the problem caused by inserting the switch, but I don't understand why. The value of the resistor here does not affect the scope results unless it is above about 8500 ohms (but below this, it could be 10ohms or 8000ohms and still show the same results as no switch and no resistor), where it starts to behave more like it does without the second resistor there - like it's tending towards an open circuit.

Can anyone explain why adding in the switch causes such strange results? I've read the help section on the block but am not much the wiser, and the results are similar, but not identical if I use a breaker block rather than a switch. Further, why does the added resistor to ground then fix it?

Plot of the armature current without switch block in circuit

Plot of the armature current with switch block in circuit

*Edit: A block diagram of the system, StartingResistance3 is the current-limiting resistance, StartingResistance2 is the resistance going to ground that fixes the changes that come with the switch.

• Screenshot of model please – JonRB Jan 1 '18 at 18:36
• Thought as much... – JonRB Jan 1 '18 at 23:09