Arduino Simulink Tutorial 3 – PWM

How to send PWM pulses to Arduino PWM pin using Simulink

In this Arduino Simulink tutorial 3 we show how to send PWM pulses to Arduino PWM pin using Simulink. PWM stands for Pulse Width Modulation and PWM pulses are those which have varying pulse width. A controlled PWM pulse with user defined specific width is used for control of power electronics such as motors. A pulse with higher pulse width has higher power and thus more power is applied to the desired system.

Before moving on with this 3rd Arduino Simulink tutorial you might want to see earlier tutorials:

To send varying PWM pulses with varying width we can use the sine wave generator in Simulink. A sine wave generator from the simulink/sources library is used. This sinusoid signal generator generates sine values from 0 to 255. At each sample point, the value increases from 0 upto 255 down again to 0 and so on. This creates sine wave wave. These 0 to 255 values can be applied to the PWM block of the Simulink Support for Arduino Hardware library. This is as shown below.

sending PWM signal from Simulink to Arduino PWM pin

But since sine wave block generates values both negative and positive while the PWM block accepts only 0 to 255 values we have to adjust the amplitude of the sine wave. The amplitude should therefore be 255/2 and the offset should be 255/2. See the configuration below.

Also make the sample time 0.01 second.

Next we have to configure the simulink simulation setting so that simulink recognizes the Arduino board(in this case the UNO), the run time to inf and deployment as External. This is explained in the first tutorial, see Arduino Simulink Tutorial 1 – LED blinking.

Once you have configured the simulink model to work with Arduino, the next step is to set up the hardware. Connect a LED to the 5th pin on the Arduino board and ground it via 220Ohm resistor. Such set-up is shown below.

Now connect your Arduino USB to the computer.

Click on Run to start the simulation and you should see that the LED will glow brighter and brighter until it reaches maximum brightness and then dim back slowly. This is due to the fact that sine wave as PWM pulses was sent to the LED.

So this completes the tutorial on how to work with the PWM Arduino Simulink block.

See also other Arduino tutorials:

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *

Arduino Simulink Tutorial 2 – Reading Switch Simulink Model

Arduino Simulink Tutorial 2 – Reading Switch

how to fix out of memory error in matlab simulink

How to fix out of memory error in matlab