Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Sampling Analog Signals, control in C-script and use PWM out of RT Box as a gate driver

0 votes
519 views
Hi! I want to capture two analog signals, process the control in C-script, and use PWM out block to generate the PWM gate drive signals.

I set the PWM out block to Enable Synchronization with step model, which allows only a Coder discretization step size = 1/fsw.  My fsw=20kHz. Also, I have two analog inputs, with Vo and IL of a hardware H-bridge inverter. These analog signals don't have offset, as checked with an oscilloscope at the RTbox analog input. They go from -5V to 5V. In this case, the analog inputs present an increasingly offset as the values increase.

One solution I found is to Disable Synchronization with the step model and use a Coder discretization step size = 1/(10*fsw). In this case, the analog inputs do not present any offset and they become more faithful to reality.

My c-script block has the control on discrete time, considering the sampling frequency the same as the PWM frequency. It's the same as using an ePWM in a DSP and sampling in the minimum of the triangular waveform.

How will the RTbox implement my c-script control? Will it do it in a faster step? How this Enable Synchronization affects my control procedure?

Thank you so much!
asked Jun 2, 2022 by Gleisson (12 points)

1 Answer

0 votes

In this particular case I think part of the issue is the very high turn-on delay. With a switching period of 50 us the turn-on delay was set to 5usec or 1/10th the period. Perhaps this is a data entry error? Indeed this can influence the sampling behavior leading to a DC offset.  You are no longer sampling at the midpoint of the waveform, but offset by a factor introduced by the dead-time. The figure below illustrates the concept.

> How will the RTbox implement my c-script control? Will it do it in a faster step? How this Enable Synchronization affects my control procedure?

With the PWM synchronized to the model step, the C-Script will execute according to the sample time you specify. You will receive a warning if you have an invalid sample time. For a C-Script with a discrete periodic sample time, it will work so long as it is an integer multiple of the specified discretization step size. The PWM output will be updated at the next specified update period (carrier min, carrier max, carrier min/max) after the computations have completed within the model step.

Without synchronization, the model execution will drift relative to the PWM carrier.  You will end up with a variable delay between the model step and the next update period.  That is why for most rapid control prototyping applications synchronization is enabled.  Within the synchronized model, it is possible to further adjust the synchronization behavior by shifting the PWM carrier and ADC sampling time.

 

answered Jun 15, 2022 by Bryan Lieblick (1,905 points)
edited Jun 15, 2022 by Bryan Lieblick
...