Main Content

Microcontroller with GPIO, ADC and DAC Connections

This example shows how to model the interface between a microcontroller unit (MCU) and a physical system. Here the microcontroller's GPIO, ADC and DAC connections are used to control a DC motor and connected load with limited angle travel. Load angle measurement is via a potentiometer sensor. This measurement is calibrated by initially ramping the rotor position until the photodiode detects the zero-angle light pulse from the LED. Once calibrated the MCU commands a 0.1Hz 45 degree amplitude sinusoid.

Model

Controller Subsystem

GPIO 1 Subsystem

Motor Driver Subsystem

Photodiode Subsystem

Potentiometer Subsystem

Simulation Results from Simscape Logging

The plot below shows the performance of the motor control system. At the start of simulation, the controller spins the motor until it finds a known position of the motor shaft (0 degrees). After that, the controller tracks the reference signal.

Results from Real-Time Simulation

This example has been tested on a Speedgoat Performance real-time target machine with an Intel® 3.5 GHz i7 multi-core CPU. This model can run in real time with a step size of 300 microseconds.