How to send PWM signal from Simulink to Arduino | applied electronics engineering

Latest

How to send PWM signal from Simulink to Arduino

By Applied Electronics - Sunday, February 26, 2017 No Comments
As you know Simulink can be used as Arduino development environment to test hardware and software(algorithms). One of Arduino usage is the ability to send PWM signals to control actuators with varying power. There are several ways to create PWM signal in Simulink and send them to Arduino. One of the easiest way is to use the Repeating Sequence block. This block is available in the Simulink/ Sources library. We can set the time scale and the magnitude of the pulses using this block.

Shown in the figure below is how to connect Repeating Sequence block to the PWM block for Arduino Simulink co-simulation.

How to send PWM signal from Simulink to Arduino
The Repeating Sequence block is set as follows.


The PWM block is found in the Simulink Support for Arduino Hardware/ Common library as shown.


Once you have made the simulink model above, the next step is to set up the hardware. Connect a LED to Arduino PWM pin 5 and ground the other side of the LED to ground using 220Ohm resistor. See the following figure.

How to send PWM signal from Simulink to Arduino

Now configure Simulink to work with Arduino- which board to use, the run time, the com port and so on. How to configure simulink is explained in details in the tutorial Arduino Simulink Digital Input example.

Once you have configured the simulink to work with Arduino, you are ready for simulation. Just click the Run button and you should see that after the codes are compiled and burned into the Arduino Microcontroller the LED will glow bright and dim according the the magnitude of PWM sent from the simulink.

So in this way you can send PWM signal from Simulink to Arduino. Another example of sending PWM signal using simulink to Arduino was shown in the tutorial Send pulses from Simulink to the Arduino PWM pins. There we have just used the Pulse Generator block for purpose of illustration only because Pulse Generator actually does not produce real PWM signal. It was illustrated for the purpose of testing the PWM block and the hardware.

There are also other ways of sending PWM signal from Simulink to Arduino such as using user defined function and also sine wave generator.

No Comment to " How to send PWM signal from Simulink to Arduino "