# Create an arbitrary delay time using C-script

**URL:** <https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909>\
**Category:** PLECS\
**Tags:** create, c-script, arbitrary, delay\
**Created:** [November 28, 2020, 6:13pm UTC](https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909 "2020-11-28T18:13:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Ng](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Alex\_Ng](https://forum.plexim.com/u/Alex_Ng)\
**Post date:** [November 28, 2020, 6:13pm UTC](https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909/1 "2020-11-28T18:13:18Z")

</div>

Hi everyone, I have several questions:

(1) Here is a code to create a delay with one sampling period from the PLECS manual:

Output function code: OutputSignal(0, 0) = DiscState(0);

Update function code: DiscState(0) = InputSignal(0, 0);

```
      Now, I want to create a delay with "[b]n*Ts[/b]": Ts being the sampling period. How could I do that in PLECS C- script?

```

(2) There is a block “Pulse Delay” in the Library. However, the delay time needs to be input manually.

In my controller, the delay time should be from a PI controller. Is there any way to put the delay time from a controller to the “Pulse Delay” block?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Kris\_Eberle](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/kris_eberle/32/6_2.png) [@Kris\_Eberle](https://forum.plexim.com/u/Kris_Eberle)\
**Post date:** [December 17, 2020, 11:17pm UTC](https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909/2 "2020-12-17T23:17:16Z")

</div>

Hello,

The Pulse Delay block cannot accept a variable time delay input via its mask parameters or input ports, but if you look under the mask of its implementation you will see that it is based on a C-Script block. I would suggest you look at the Space Vector Modulator block to see how the C-Script block is used to calculate variable timing events internally. With the C-Script block, you _can_ use an external value, such as the output of your PI controller, as part of the algorithm. Good luck!

Kris

---

<div class="post-metadata">

**Author:** ![AskBrillz](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@AskBrillz](https://forum.plexim.com/u/AskBrillz)\
**Post date:** [December 26, 2020, 12:33pm UTC](https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909/3 "2020-12-26T12:33:07Z")

</div>

even i have that doubt of creating the delay hope some one answers its

---

<div class="post-metadata">

**Author:** ![Kris\_Eberle](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/kris_eberle/32/6_2.png) [@Kris\_Eberle](https://forum.plexim.com/u/Kris_Eberle)\
**Post date:** [January 5, 2021, 11:39am UTC](https://forum.plexim.com/t/create-an-arbitrary-delay-time-using-c-script/909/4 "2021-01-05T11:39:40Z")

</div>

Please see my comment above.
