Introduction to ePWMs for C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 13 - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 12:05
Loaded: 1.37%
Stream Type LIVE
Remaining Time 12:05
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 12:05

    Introduction to ePWMs for C2000 MCUs | Getting Started with C2000 Microcontroller Blockset, Part 13

    From the series: Getting Started with C2000 Microcontroller Blockset

    Learn the fundamentals of pulse-width modulation techniques and the C28x ePWM module available in TI C2000™ MCUs and how you can work with them using C2000 Microcontroller Blockset.

    Published: 13 Jan 2025

    Do you know how the brightness of the display that you are watching, the amplification in any audio devices, the speed of the motor, and the temperature in heating systems such as the microwave oven are being controlled precisely using a microcontroller? This is all achieved with the help of a PWM signal generated from the microcontroller.

    So welcome to yet another video series on enhanced pulse width modulation. In this episode, let me dive into the essentials of PWM and demonstrate how to generate a PWM signal using the ePWM block from C2000 Microcontroller Blockset in Simulink and control the brightness of the onboard LED of F28739D LaunchPad.

    To begin, let's start with, what is a PWM? As the name suggests, the width of the pulse can be varied, keeping the time period constant. The technical term for varying any parameter is called modulation. And here, since the width of the pulse is varied, it is called pulse width modulation.

    Why is PWM signal necessary? To comprehend this, let's begin with the basic of a DC signal. A 0-volt DC signal represents the signal being completely off, while a 3-volt DC signal denotes that the signal being completely on.

    Supplying a constant 3-volt DC signal to a load delivers unchanging power. However, to precisely control the power delivered to the load, we can send the signal in the form of pulses instead of a continuous DC signal. This method enables us to regulate the power supply to the load.

    To delve deeper, there are two key parameters associated with the PWM signal. One is the frequency. And the other one is the duty cycle. First, let us see, what is a PWM frequency?

    PWM frequency means, in simple terms, it's how many times the signal switches from high to low, or vice versa, in 1 second, typically measured in hertz. A higher frequency means more switches per second, while a lower frequency means fewer switches per second. Here, the frequency is 5 kilohertz. It means the signal is switching from high to low 5,000 times in a second.

    The next parameter is the duty cycle. The duty cycle is the percentage of time the PWM signal is high compared to the total period of the signal. It is often represented as a percentage. For example, a 50% duty cycle means the signal is on for half of the time and off for the other half of the time during each period. Here, the signal is at 50% duty cycle, where the signal is on for the first 100 microseconds and off for the next 100 microseconds.

    By adjusting the duty cycle, we can control the power delivered to the load. Increasing the duty cycle increases the average voltage delivered to the load. You could see here, as I increase the duty cycle from 50% to 80%, the average voltage also increases from 1.5 volt to 2.5 volt, while decreasing the duty cycle has the opposite effect.

    With that said, now let's swiftly transition to Simulink to generate a PWM signal from our F28739D LaunchPad and control the brightness of the onboard LED. Let me create a new blank Simulink model. Let me configure this model for my hardware. Let me press Control-E to open the configuration parameters.

    And under Hardware Implementation tab, let me select TI Delfino F28739D LaunchPad. And click on OK. Once you have applied the configuration, a new Hardware tab appears in the Simulink Toolstrip, displaying the selected hardware. In our case, it's TI Delfino F28739D LaunchPad. Now let's start designing the model.

    Let's now add an ePWM block under F2873xD series of microcontroller. Double-clicking on the block opens the Block Parameters. As I have said previously, frequency and duty cycle are the basic parameter for any PWM signal.

    First, let's see how to configure for the PWM frequency. The PWM signal frequency configuration depends upon several factors, including ePWM clock frequency, timer period units, timer period value, counting mode, and prescaler.

    To set the ePWM clock frequency, go to the Configuration Parameters by pressing Control-E. Under Hardware Implementation and Target hardware resources, navigate to the ePWM tab to set the ePWM clock frequency. In this case, the ePWM's clock frequency is set to half of the SYSCLKOUT. SYSCLKOUT is nothing but the controller's clock frequency, which is at 200 megahertz. SYSCLKOUT/2 is 100 megahertz, which is the ePWM's clock frequency.

    Returning back to the Bock Parameters, now let's set the timer period units, which can either be in clock cycle or seconds. For this demonstration, the default setting of the clock cycle will be used. The next parameter is the timer period. This is calculated based on the counting mode and the prescaler settings.

    When the counting mode is set to Up-Down and the prescalers are set to 1, by clicking on the Help over here, the documentation of the ePWM block provides the corresponding formula under the timer period and Up-Down counting mode.

    For instance, to generate a 5-kilohertz PWM signal, which is equivalent to a time period of 0.2 millisecond, given the ePWM clock frequency of 100 megahertz, which is 10 nanoseconds, the TBPRD, which is Time-Based Period Register, value can be calculated using the formula, resulting in a value of 10,000. Entering this value in the Timer period parameter will produce a desired 5-kilohertz PWM signal.

    This timer period is a 16-bit value. And you can enter any value between 0 to 65,535, according to which the PWM's frequency can be controlled. Apart from this, prescalers also impact on the PWM frequency. By adjusting the prescaler, the PWM clock frequency can be further reduced, enabling the generation of a PWM signal at a lower frequency. So these are the essential configurations for PWM frequency adjustments.

    To set the duty cycle, let me switch to Counter Compare tab. And here, by default, the duty cycle is mentioned in clock cycles. Let me change it to percentages. And the initial value is set to 50 percentage.

    Instead of specifying the duty cycle over here, let me specify it via an input port. And as I click Apply, you'd be able to see the input port appearing on the ePWM block. And by default, ePWMA signal is enabled. And if you want, you can enable the ePWMB signal too.

    So these are the basic parameters that you need to set to generate any PWM signal. I am not explaining the parameters in detail, which I'd be doing in a separate video. Let me click on OK to apply the configuration.

    Now let me add a constant block. And name the signal as duty cycle. To make it interactive, let me add a slider from Simulink dashboard. And connect it to the constant block.

    Now, by dragging the slider, I'd be able to change the constant value, which is nothing but the duty cycle of the PWM signal. So I'd be able to control the duty cycle with the help of this slider. Let me click on Done Connecting. Let me double-click on the constant block. Set the sample time to 0.0001.

    The PWM signal is generated on pin 40 of the LaunchPad. To view the signal, I have fed the generated PWM signal to pin 35 of the LaunchPad through an external jumper cable, as shown here, and reading it via a digital input block. The pin 35 corresponds to GPIO5. Let me set the sample time to 0.1 microsecond.

    Let me add a digital output block and configure it for pin 31, which corresponds to the onboard blue LED. And let me connect the red PWM signal to the onboard blue LED so that I'd be able to control the brightness of the LED. But since the LED is connected in a pull-up fashion, let me add a NOT gate.

    Also, let me add another digital output block and connect it to a constant block. Let me have a constant value of 1. And let me configure this digital output block to pin 34, which corresponds to the onboard red LED. I am doing this in order to turn off the red LED so that when I change the brightness of the blue LED, it is perfectly visible.

    Now I have designed my model. And let me save the model for my reference. Once I have saved my model, let me run the model in the Monitor and Tune mode.

    You could see, as I increase the duty cycle from 0% to 10%, 40%, 65%, 80%, the width of the pulse increases, as well as the brightness of the LED also gradually increases. And when I set the duty cycle to 100%, the LED glows at its full brightness. As I start decreasing the duty cycle, the width of the pulse also decreases. And it also dims the brightness of the LED. And when I set it to 0, the LED completely turns off. So this is how the brightness of the LED can be controlled using a PWM signal.

    To wrap it up, in this video, we saw what is a PWM signal, why a PWM signal is used and its application, and also how to generate a PWM signal in C2000 Microcontroller Block set to control the brightness of the LED. In the next video, we will see the PWM's block parameter in detail. And thanks for watching this video.