On the RT Box, if I use PWM Out (Variable) with Update = Immediately. And the controller runs with Ts, and the RT Box screen shows 30% CPU utilization.
Does this mean that the control computation finish at approximately 0.3Ts after each PWM period starts?
Does this imply that the duty cycle is updated immediately at the computation finish time, i.e. 0.3Ts after each PWM period starts?
Does this mean that in a PWM period, the first 30% is actually the old duty cycle, and the last 70% is the new duty cycle just calculated?
The term “Immediately” should be interpreted as “immediately when a PWM block receives the new duty cycle, independently from it’s current carrier phase.” The exact time when the PWM block receives the new duty cycle depends on a number of settings.
Normally, the PWM blocks run independently from the the CPU. They may even have completely unrelated periods. If you want the PWM to be synchronized with the CPU, the option “Synchronization with model step” in the PWM block needs to be checked. Obviously, the CPU step size must match the PWM period in this case. Since you mention that you use the Variable PWM out unit, the option to change the carrier frequency dynamically is limited to integer multiples in this case.
The next option that influences the update time is the “Simulation mode” in the Coder options for the RT Box target. With the default “HIL” settings, the new PWM duty cycles are transferred to the PWM blocks at the beginning of the next CPU step. This makes the update time deterministic with respect to the beginning of the CPU step (and the PWM period if the PWM is synchronized). It is not dependent on the CPU utilization. The transfer to the PWM blocks needs some time, so the actual update happens a few hundred nanoseconds after the start of the CPU step.
If the “Simulation mode” is set to “RCP”, the data is sent to the PWM blocks as soon as the CPU has finished its computation. This comes closest to the scenario you have described (assuming, again, that the PWM is synchronized to the CPU). Again, there’s an additional latency of a few hundred nanoseconds. The length of the CPU computation is not deterministic, so neither is the exact time of the PWM update. The utilization you see in the display is always the maximum computation time over the update period. Note that it’s not possible to use multitasking in RCP mode.
Thank you very much for your help.
I’m familiar with DSP and recently needed to use PLECS RT Box with an interface board to drive a real power converter. I’d like to confirm the following:
Figure 1 shows the DSP-based implementation.
Figure 2 shows what I observe in the PLECS software simulation.
When using the RT Box for RCP, does the real system behave like Figure 2 as well? I’m asking because the RT Box still requires a nonzero computation time to calculate the duty cycle, and I’m not sure whether the duty-cycle update occurs exactly as depicted in the software simulation.
Figure 1 basically shows what happens if “Simulation mode” is set to HIL.
Figure 2 basically shows what happens if “Simulation mode” is set to RCP. Obviously, in Figure 2, you need to take the computation time and the data transfer latency into account. The update will only happen after the calculation, so somewhere within the first step.
Both scenarios will only make sense if the PWM is synchronized with the CPU step and the CPU step size is identical to the PWM period.
The sampling of Analog inputs always happens before the CPU step starts. The timing can be influenced by the setting “Analog input sampling” in the target settings in the Coder options dialog and the Trigger settings in the Analog In block.
Thank you very much for your help.
Finally, I’d like to confirm: when you say “CPU step size,” do you mean “Coder - Coder options (Ctrl+Alt+B) - Scheduling - Discretization step size(s)”?
Yes, when using single-tasking (which is the only option in RCP mode).
