# How can I implement PWM edge detection using a C-Script for the RT-Box?

**URL:** <https://forum.plexim.com/t/how-can-i-implement-pwm-edge-detection-using-a-c-script-for-the-rt-box/1400>\
**Category:** RT Box\
**Tags:** currenttime, c-script, pwm, rt-box, absolute-time\
**Created:** [October 4, 2024, 8:29am UTC](https://forum.plexim.com/t/how-can-i-implement-pwm-edge-detection-using-a-c-script-for-the-rt-box/1400 "2024-10-04T08:29:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Ali](https://forum.plexim.com/u/Ali)\
**Post date:** [October 4, 2024, 8:29am UTC](https://forum.plexim.com/t/how-can-i-implement-pwm-edge-detection-using-a-c-script-for-the-rt-box/1400/1 "2024-10-04T08:29:07Z")

</div>

Hi everyone,

I’m encountering an issue while trying to build my PLECS model into the RT-Box. The error message I receive is as follows:

"The following components use the value of absolute time. This may cause overflow problems when a program runs for an indefinite time:

Loss\_calc/C-Script"In my model, I use a C-Script block to extract the duty cycle of a PWM signal, specifically to measure the pulse width of the PWM signal. To detect the rising and falling edges, I rely on the CurrentTime macro within the C-Script. The C-Script block is also attached.

The error suggests that using absolute time could cause overflow problems. I need to keep track of the PWM signal’s edges without running into this overflow issue.

What would be the best approach to implement this functionality in a way that avoids the overflow problem when building the model for the RT-Box? Is there an alternative method to achieve the same result, or adjustments I need to make within the C-Script?

Thanks in advance for your support!

---

<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:** [October 7, 2024, 10:06am UTC](https://forum.plexim.com/t/how-can-i-implement-pwm-edge-detection-using-a-c-script-for-the-rt-box/1400/2 "2024-10-07T10:06:18Z")

</div>

Please see [this detailed forum response](https://forum.plexim.com/7974/error-with-the-clock-block-while-using-c2000-package-support) for a detailed explanation of why it is not recommend to use absolute times in real-time simulation. Since you are measuring PWM signal edges, you can use a resetting accumulator to measure the interval between edges.

---

<div class="post-metadata">

**Author:** ![Ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@Ali](https://forum.plexim.com/u/Ali)\
**Post date:** [October 8, 2024, 4:07am UTC](https://forum.plexim.com/t/how-can-i-implement-pwm-edge-detection-using-a-c-script-for-the-rt-box/1400/3 "2024-10-08T04:07:37Z")

</div>

Thanks Bryan,

But the problem is that I am using CurrentTime macro for determining the PWM signal edges. And I guess the CurrentTime macro in my C-Script causes the error of absolute time.
