# How to achieve a variable frequency AC voltage source

**URL:** <https://forum.plexim.com/t/how-to-achieve-a-variable-frequency-ac-voltage-source/901>\
**Category:** PLECS\
**Tags:** source, c-script\
**Created:** [November 19, 2020, 10:04pm UTC](https://forum.plexim.com/t/how-to-achieve-a-variable-frequency-ac-voltage-source/901 "2020-11-19T22:04:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shichenseu](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@shichenseu](https://forum.plexim.com/u/shichenseu)\
**Post date:** [November 19, 2020, 10:04pm UTC](https://forum.plexim.com/t/how-to-achieve-a-variable-frequency-ac-voltage-source/901/1 "2020-11-19T22:04:16Z")

</div>

I want to achieve a variable frequency AC voltage source with the frequency variation of ± 0.5Hz frequency, but there is no block for me to realize that. Should I use C-script or this function cannot be achieved in plecs?

---

<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:** [November 20, 2020, 10:14am UTC](https://forum.plexim.com/t/how-to-achieve-a-variable-frequency-ac-voltage-source/901/2 "2020-11-20T10:14:13Z")

</div>

Do you have a predefined set of voltage source data? Or how do you want to change the frequency? Is the frequency variation random or follows a pattern?

---

<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:** [November 20, 2020, 10:14am UTC](https://forum.plexim.com/t/how-to-achieve-a-variable-frequency-ac-voltage-source/901/3 "2020-11-20T10:14:38Z")

</div>

You can use a Trigonometric Function and a Voltage Source (Controlled) component to create a voltage source of arbitrary phase and frequency.

For the time/angle input, you can use a Clock component for offline simulations and for real-time simulations you’ll want to use a wrapping integrator. There is an example of a C-Script based wrapping integrator in the C-Script documentation in the PLECS Manual (see: Event Handling - Wrapping Integrator) and variations in several of the demo models (Look in the PLL’s of the STATCOM Cascaded H-Bridge Converter, Three-Phase Grid-Connected PV Inverter, and Z-Source Inverter, among others).
