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

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!

Please see this detailed forum response 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.

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.