Get Started with SoC Blocks on MCUs
This example shows how to simulate and deploy a closed-loop feedback control algorithm on to a MCU using SoC Blockset.
SoC Blockset allows you to create a closed-loop model consisting of a plant, an algorithm running on a microcontroller and hardware peripherals interfacing microcontroller to the plant. You can easily create a high-fidelity simulation of the system by taking advantage of following capabilities:
Model ADC and PWM peripherals with accurate real-time behavior
Model interrupts as tasks including synchronization and scheduling
Model task latencies due to execution and sensor delays
This example shows how to use SoC Blockset to deploy a Simulink model of a closed-loop application on to the TI Delfino F28379D LaunchPad.
Supported hardware platforms:
TI Delfino F28379D LaunchPad
TI Delfino F2837xD based board
Model Using SoC Blockset
Open the closed-loop template model. This model shows a basic closed-loop control application with a low pass filter as a plant. The output of the plant is sampled by the ADC Interface generating an event on each conversion. The Task Manager executes an event-driven task called ADC upon reception of each ADC end-of-conversion event. The ADC Interrupt task contains the feedback control algorithm that executes asynchronously in response to each ADC conversion event. The control algorithm receives feedback through ADC Read and generates duty cycle values for PWM Write block. The PWM Interface block simulates PWM behavior including triggering an event to start the next ADC conversion.
Click 'Play' to simulate the model. Open the Simulation Data Inspector and view signals. Validate the models in simulation before trying deployment. The figure shows the controller response and switching PWMs generated from PWM Interface block. You can tune the PI controller parameters by adjusting the gain values in PID Controller block.
Deploy and Run SoC Model on MCU
You can create the first order plant model from the simulation using simple RC circuit. Assuming no loading at the output of the RC-circuit, you can use R = 10kOhm and C = 10uF. Connect the output of the selected EPWM1A, J4 pin 40 in F28379D launchpad with ADCINA0, J3 pin 30 as shown in the figure below.
You can directly deploy the model on to the TI Delfino F28379D LaunchPad by following the below step by step instructions and guidelines.
Open the SoC Builder tool from the System on Chip tab, by clicking Configure, Build, & Deploy.
Review Hardware Mapping in the next page. Observe ADCA1_isr is configured as event source for control task.
Review Map Peripherals in MCU Model in the next page. Configure peripherals with same value used for simulation.
Validate Model page ensures the models are error free. If model compilation step fails, try Update Model (Ctrl+D) from the Debug tab.
To monitor data from hardware, select Build and load for External mode in Select Build Action page. In the next page, click Load and Run. Open the Simulation Data Inspector and view signals from the hardware.
To profile task execution on the processor, open the controller reference model and select profiling information to Show in SDI. Select Build and load for External mode in Select Build Action page. In the next page, click Load and Run. Open the Simulation Data Inspector and view task profiling data from the hardware.