# Is there a variable delay block?

**URL:** <https://forum.plexim.com/t/is-there-a-variable-delay-block/455>\
**Category:** PLECS\
**Tags:** variable-delay, changeable-variable\
**Created:** [July 23, 2018, 7:13pm UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455 "2018-07-23T19:13:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwamyotte](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@mwamyotte](https://forum.plexim.com/u/mwamyotte)\
**Post date:** [July 23, 2018, 7:13pm UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455/1 "2018-07-23T19:13:41Z")

</div>

Hello,

I am trying to implement a controller where I am looking to have a variable delay. Is there a way to implement this in PLECS? There is a Simulink block which offers the delay time as a second input, but I cannot find this option in PLECS.

Thanks,

Matt

---

<div class="post-metadata">

**Author:** ![nikilito](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@nikilito](https://forum.plexim.com/u/nikilito)\
**Post date:** [July 24, 2018, 5:10am UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455/2 "2018-07-24T05:10:50Z")

</div>

Hi.

I was trying to solve the same problem for another reason, but there isn’t such block in the library.

What you can do is see how the Simulink block is built and replicate it in Plecs.

Otherwise, you should write a C-Script to implement what you need…

---

<div class="post-metadata">

**Author:** ![Beat\_Arnet](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/beat_arnet/32/9_2.png) [@Beat\_Arnet](https://forum.plexim.com/u/Beat_Arnet)\
**Post date:** [July 25, 2018, 8:41am UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455/3 "2018-07-25T08:41:32Z")

</div>

Can you tell us a bit more about what this variable delay is needed for? Is it for realizing a pulse-width modulation scheme?

---

<div class="post-metadata">

**Author:** ![mwamyotte](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@mwamyotte](https://forum.plexim.com/u/mwamyotte)\
**Post date:** [July 25, 2018, 1:36pm UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455/4 "2018-07-25T13:36:53Z")

</div>

Hi Beat,

I am implementing a constant on-time critical conduction mode PFC. In order to ensure the bus voltage is maintained for different input voltages, the constant on-time must be controlled. Please refer to the figure for the implementation using an SR flip-flop.

I have managed a workaround by building my controller in Simulink (which has a variable delay block), but if there is a solution in PLECS that would be great.

Thanks,

Matt

 ![CrCM Control.PNG](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/1X/fe1758197778a33fc62d57f9329b60d3d79d28c9.png)

---

<div class="post-metadata">

**Author:** ![Beat\_Arnet](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/beat_arnet/32/9_2.png) [@Beat\_Arnet](https://forum.plexim.com/u/Beat_Arnet)\
**Post date:** [July 26, 2018, 7:58am UTC](https://forum.plexim.com/t/is-there-a-variable-delay-block/455/5 "2018-07-26T07:58:04Z")

</div>

Hi Matt,

Our State Machine component is likely a good choice for this. With PLECS 4.1, we introduced an AFTER keyword to trigger delay-based transitions. Take a look at the “Buck Converter with Constant On-Time Control” model, included with the PLECS demo library.

Beat
