Adding MCU Peripheral Modeling in Motor Control Using SoC Blockset
Published: 5 Oct 2021
Hello, everyone. My name is Pradeep, I'm a Development Manager at MathWorks.
Are you facing challenges in designing your controller to accurately measure the phase currents on the hardware in motor control application? If yes, then in this video, I'm going to show you how you can use SoC Blockset set to identify and resolve controller issues in the simulation phase by adding MCU peripheral synchronization and system delays and then verify the tuned controller on the hardware.
SoC Blockset allows you to create a high fidelity simulation of the closed loop system by taking advantage of new capabilities in 20B release, like modeling of ADC and PWM peripherals with accurate, real-time behavior, modeling interrupts as tasks, including synchronization and scheduling, also provides complete MBD workflow for TI C2000 by enabling a single system model for simulation and targeting. And at the end, provides a guided deployment workflow using SoC builder app.
I'm using a C2000 Delfino MCU F28379D launchpad development kit to verify the behavior on the hardware.
Here, we see a Simulink model that represents the motor control closed loop application. This model simulates single CPU motor controller for a permanent magnet synchronous motor inverter system. Controller subsystem, highlighted in green color, senses the outputs from the plant using ADC interface block and actuates using PWM interface blocks that drives the inverter. Algorithm blocks from motor control Blockset are used in this example.
Task Manager block, highlighted in green, simulates the execution of software tasks as they would be expected to behave on a microcontroller. The ADC interface block, highlighted in green color, similar to the analog to digital conversion of a hardware board, along with start input event message and end of conversion output event message signals.
PWM interface block, highlighted in green color, simulates the PWM output of the hardware board along with an output triggering event, which can then be connected to the start port of the ADC interface block to synchronize ADC and PWM events in a closed loop system. As you can see, only two PWM triggering events are used, since duration sensing technique is used in the setup to measure the phase currents.
Now let's talk about typical design challenges associated with MCU peripherals and scheduling by incorporating sensor delays to achieve the desired controller response for the closed loop system. For example, ADC acquisition time impact on the controller response, synchronizing ADC and PWM peripherals to achieve current sensing at midpoint of PWM period, simulating the PWM at switching level with nanosecond deadtime value, single model for simulation and the deployment.
Now let's look at the first design challenge, effect of ADC acquisition time on controller response. To ensure complete ADC measurement, the minimum acquisition time must be selected to account for the combined effects of input circuit and the capacitor in the sample and whole circuit.
Now let's see the impact of low acquisition time on the controller response. On the ADC interface block, change the default acquisition time to 100 nanoseconds. Then, run the simulation and open the SDA for removing the phase currents and speed feedback. In this figure, you can see that the simulated speed feedback shows significant oscillations during open loop to closed loop transition, which in real world, will hurt the motor. This is due to a distortion in current waveforms.
The low acquisition time resulted in ADC measurements not reaching the true value. As a result, the controller reacts by generating a related reduced cycle, causing variations in current run by the motor.
To fix this issue, change the acquisition time to a larger value, say 320 nanoseconds. This value is the minimum ADC acquisition time recommended for TI Delfino 790 launchpad. Again, the simulation and view the results in SDA. In this figure, you can see the accurately sampled ADC values and the controller tracking the reference value as expected.
Now we have used the simulation models to adjust ADC parameter, let's proceed with programming the TI launchpad board to verify these settings with the hardware test. On the System on Chip tab, click Configure, Build & Deploy button to open the SoC builder tool. Follow the instructions on the SoC builder tool to run the model in external. Once the external mode simulation is completed, open SDA to view the results.
In this figure, you can see the data from hardware with accurately sampled ADC values and the controller tracking the reference value as expected.
Now let's talk about the second design challenge, that is, synchronization between PWM command and ADC conversion. In this figure, you can see the low side shunt resistors are acute in DRV8305 motor driver board. The current only flows through the shunt when the bottom switches are on and away from PWM computation noise.
So for correct operation, current sensing must occur during the midpoint of the PWM period when ADC is triggered. Specifically, the PWM counter must be at the maximum value when the bottom switches are active in the up-down counter mode. After ADC start off conversion is triggered, there will be a delay due to acquisition and conversion before end of conversion event gets triggered. The current sampling at a different instance results in a measured phase currents of 0.
Now let's see an error case were currently sampled at the wrong instance and observed that the controller responds by running the simulation. In the PWM interface block, set event trigger mode to end of PWM period. Again, run the simulation and view the results in SDA. In this figure, you can see that the phase A and phase B currents are approximately 0. This results in a loss of feedback and no actuation in the control loop. If the same test is done on hardware, you might end up damaging the in-motor circuit.
To fix this issue, change the event trigger mode to midpoint of PWM period, equivalent to the PWM internal counter being at a maximum in Up-Down counter mode. Now run the simulation again and view the results in SDA. In this figure, you can see that the ADC interrupt occurs during PWM for bottoms, which is on, and non-zero phase A and phase B currents.
Now we have used the simulation models to adjust PWM parameters, let's proceed with the programming the DA launchpad board to verify these settings with the hardware test. Before deploying the model, set the PWM event condition to counter equals to period on peripheral configuration app in the SoC builder tool. Follow the instructions on the SoC builder tool to run the model external mode and view the results in SDA.
In this figure, you can see that the data from simulation and hardware with correct ADC/PWM synchronization and the controller tracking the reference value as expected.
So to summarize, you can easily identify and fix the design problems in motor control application early in the development phase using new capabilities in SOC Blockset, like modeling of ADC and PWM peripherals, modeling of interrupts as tasks, complete MBD workflow for TA C2000 port.
Thank you so much for watching. To try the example, please visit the link mentioned in the video description.