# Output of C-Script to comand a switch

**URL:** <https://forum.plexim.com/t/output-of-c-script-to-comand-a-switch/784>\
**Category:** PLECS\
**Tags:** signal, c-script, rectifier, input-signal, precharge\
**Created:** [June 16, 2020, 12:38pm UTC](https://forum.plexim.com/t/output-of-c-script-to-comand-a-switch/784 "2020-06-16T12:38:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matias\_L](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@Matias\_L](https://forum.plexim.com/u/Matias_L)\
**Post date:** [June 16, 2020, 12:38pm UTC](https://forum.plexim.com/t/output-of-c-script-to-comand-a-switch/784/1 "2020-06-16T12:38:16Z")

</div>

Hi everyone!

I’m having a problem with my simulation:

I’m using a C-script to make the discrete control of my converter, everyone works fine until now,

I’m trying to make the inicialization routine, (context: is an active rectifier with a LCL filter, i need make the precharge of the DC-Link, connecting a resistor in the beginning of the circuit (1 per line) when i make the precharge, then, when the capacitor is charged, i need to bypass this 3 resistor), but it does’n work as i want. Now, i’m getting the on-off signal of the switch to activate/desactivate the resistor to make the precharge, but some pulses in the output (should stay calm on 750V) cause problems in the modulation, i don’t know why this appears. i think can be because of the way what i make the on-off of the switch (just an IF in the c-script, if the value of the output is less than 520V, connect the resistor, else, disconnect). The sample of the C-script is 50khz.  
Anyone have an idea of what happen? Or, another way to make the precharge?

Thanks!!

PD: attach the schematic and photo of results of the problem.

 ![schematic.png](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/1X/e9f1a096d11846849b633748bfa43b56cc7b1d1c.png)

 ![precarga_c-c.png](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/1X/96a392e3922a14c7cf8ec2953d044f86a2ccb9de.png)

---

<div class="post-metadata">

**Author:** ![Bryan\_Lieblick](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/bryan_lieblick/32/10_2.png) [@Bryan\_Lieblick](https://forum.plexim.com/u/Bryan_Lieblick)\
**Post date:** [June 17, 2020, 10:35am UTC](https://forum.plexim.com/t/output-of-c-script-to-comand-a-switch/784/2 "2020-06-17T10:35:24Z")

</div>

Hi Matias, this sounds more like a control design issue than something with PLECS.

If you’re seeing the pre-charge switch toggling, then you’re likely on the right track with your pre-charge logic being too simple.

Normally the converter controller would use a finite state-machine to distinguish between different modes. For example there are distinct startup, operating, faulted, and restoration states. The pre-charge resistors would carry current only during certain states, and with enough specificity to prevent toggling and equipment damage.

---

<div class="post-metadata">

**Author:** ![Matias\_L](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@Matias\_L](https://forum.plexim.com/u/Matias_L)\
**Post date:** [June 17, 2020, 1:57pm UTC](https://forum.plexim.com/t/output-of-c-script-to-comand-a-switch/784/3 "2020-06-17T13:57:50Z")

</div>

Hi Bryan.

This problem just appears when i make the precharge, if i don’t use the precharge-stage (initial condition in the capacitor), i haven’t problem with the controller, so, i agree with the problem is beacause the control stage of the precharge.

I agree too with using a finite state-machine, but, at this moment of the proyect, i just haven’t designed it yet.
