# Simple implementation of a variable peak sawtooth generator?

**URL:** <https://forum.plexim.com/t/simple-implementation-of-a-variable-peak-sawtooth-generator/1302>\
**Category:** PLECS\
**Tags:** control, controller, compensator, sawtooth, pulse-generator\
**Created:** [December 21, 2023, 3:11pm UTC](https://forum.plexim.com/t/simple-implementation-of-a-variable-peak-sawtooth-generator/1302 "2023-12-21T15:11:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mostafa\_Amer](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mostafa\_Amer](https://forum.plexim.com/u/Mostafa_Amer)\
**Post date:** [December 21, 2023, 3:11pm UTC](https://forum.plexim.com/t/simple-implementation-of-a-variable-peak-sawtooth-generator/1302/1 "2023-12-21T15:11:47Z")

</div>

I want to implement a fixed-frequency sawtooth generator with a peak voltage (Vpk) that I can control using an external variable (Vx). I created a simple circuit using a voltage controlled current source, a capacitor, and a reset switch like the figure below. However, this circuit increase the single simulation time from 0.2 second to 2.7 second. The time factor is important for me because I am doing thousands of simulation runs (optimization loop).

Is there a simpler and faster way to implement this variable-peak sawtooth generator (ideal ways are ok)?

Thanks

 ![373](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/1X/65a40c52343c203de86fc5ea7188afe8e49985c7.jpeg)

[BuckClosedLoop\_PI\_FF.plecs](https://forum.plexim.com/uploads/short-url/zzAYuSkyaVamLTAKaUAyc7MqvMD.plecs) (35.9 KB)

---

<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:** [December 22, 2023, 10:52am UTC](https://forum.plexim.com/t/simple-implementation-of-a-variable-peak-sawtooth-generator/1302/2 "2023-12-22T10:52:46Z")

</div>

You can use a Triangular Wave Generator with a ramp between 0-1. Then multiply the output Vx. Placing a zero-order hold after Vx ensures the ramp peak is only updated on the carrier minimum. See the attached model.

 ![61](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/1X/528f8378b7e396b74642d7d0a6546d8a33f84ebc.jpeg)

[VariablePeakSawtooth.plecs](https://forum.plexim.com/uploads/short-url/aH5fBkht03GUeTqalWsWxYwRb17.plecs) (7.19 KB)
