In this post, we’ll examine how the TMS320F28335 microcontroller generates PWM signals. PWM signals are widely employed in many different applications, such as LED dimmers, power electronics, and motor control. You may enable advanced control and modulation in your projects by learning how to generate PWM signals with precise frequency and duty cycle control.

Overview of PWM Signals

PWM control regulates the average power given to a load by changing the duty cycle of a square wave signal. The effective voltage provided to the load can be changed by varying the signal’s on and off times. Applications like motor speed control, LED dimming, and power converters benefit greatly from this technology.

Overview of TMS320F28335 Microcontroller

The TMS320F28335 is a high-performance 32-bit microcontroller based on the C2000™ real-time control architecture from Texas Instruments. It is specifically designed for applications that require precise control and high performance, such as industrial automation, power electronics, motor control, and digital power conversion.

Here’s an overview of the key features and capabilities of the TMS320F28335 microcontroller:

CPU32-bit C28x core operating at up to 150 MHz
Memory512 KB Flash memory, 68 KB RAM
Analog-to-Digital Converter (ADC)12-bit ADC with up to 16 channels
Pulse Width Modulation (PWM)Advanced PWM modules for precise PWM signal generation
Communication InterfacesUART, SPI, I2C, and CAN
Enhanced Control PeripheralsDedicated ePWM modules for motor control and power electronics
Timers and InterruptsMultiple timers and interrupt sources
Development Tools and SoftwareCode Composer Studio™ IDE, TMS320x2833x header files and libraries

Hardware components and connections

The TMS320F28335 microcontroller’s PWM control registers and GPIO (General Purpose Input/Output) pins must be set up in order to produce a PWM signal. A detailed explanation of how to do this is provided below.

State Diagram of the PWM Control System

PWM Control Register Configuration

Configuring GPIO Pins

Here’s an example of configuring GPIO_0 and GPIO_1 pins as PWM pins

In this example, we assume that GPIO_0 and GPIO_1 pins are available on GPIO Port A (GPA). Here’s a step-by-step breakdown of the code.

Configure GPIO_0 as a PWM pin:

  • GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0x1; // sets the GPIO_0 pin to select the PWM functionality.
  • GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // sets the GPIO_0 pin as an output.

Configure GPIO_1 as a PWM pin:

  • GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0x1; //sets the GPIO_1 pin to select the PWM functionality.
  • GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //sets the GPIO_1 pin as an output.

Configuration of the PWM Module

The PWM modules on the TMS320F28335 microcontroller each have a unique set of control registers. The following registers must be set up in order to produce a PWM signal:

Determines the PWM signal’s period is the Period Register (PRD). It determines the PWM output’s frequency.

You can use the following formula to determine the value for EPwm1Regs.TBPRD to obtain a particular PWM frequency, such as 15 kHz, using a PWM clock frequency of 150 MHz:

TBPRD = TBCLK / (2 * PWM Frequency)

In your case, the PWM frequency is 15 kHz and the PWM clock frequency (TBCLK) is 150 MHz. Applying the formula:

TBPRD = 150,000,000 / (2 * 15,000)

TBPRD = 150,000,000 / 30,000

TBPRD = 5000.

Therefore, you would set EPwm1Regs.TBPRD to 5000 to get a PWM frequency of 15 kHz with a PWM clock frequency of 150 MHz.

The relationship between the PWM time and the PWM frequency serves as the basis for the TBPRD formula. The PWM clock frequency (fCLK) is twice the PWM frequency (fPWM), and the PWM period (TPWM) is the reciprocal of the PWM frequency (fPWM). We can therefore represent TBPRD as TPWM / (2 * TBCLK) by rearranging the equations.

Set the Duty Cycle

The PWM signal’s duty cycle can be set after the GPIO pins and PWM control registers have been configured. Usually, to accomplish this, the compare value in the CMPA register is updated. The PWM output’s state changes depending on the compare value.

The comparison value in this instance is set to 2500. The precise interpretation of this value depends on the PWM module’s particular configuration and intended use. We can, however, presume that it designates a certain time period during the PWM period.

Usually, the compare value is chosen to produce a particular PWM signal duty cycle. The duty cycle is the percentage of the time when the PWM output is high (on) in comparison to the entire time. The required duty cycle and the period value are frequently used to determine the comparison value.

For example:

if you have a period (TBPRD) of 5000 and want a duty cycle of 50%, you can calculate the compare value as follows:

Duty cycle = (Compare value / Period) * 100

50% = (Compare value / 5000) * 100

Solving for the compare value:

Compare value = (50 / 100) * 5000 = 2500

In this case, setting EPwm1Regs.CMPA.half.CMPA = 2500; which means you are setting a duty cycle of 50% for the PWM signal.

Controls The Counting Mode:

The “Count up-down” function of a PWM module refers to the direction of the counter that produces the PWM signal. It decides whether the counter counts down from the period value to zero and then repeats (TBPRD) or counts up from the period value to zero (TBPRD).

Access the PWM module’s control register by choosing it. For instance, if you were configuring EPwm1, you would access EPwm1Regs.TBCTL, the control register.

Locate the bit that governs the “Count up-down” or counting mode. Usually, this bit’s name is CTRMODE.

To make the “Count up-down” capability available, set the bit to the proper value. Depending on the particular microcontroller and its register configuration, the value could be different. In most cases, a number of 0 denotes “Count up” mode while a value of 1 denotes “Count up-down” mode.

By writing the modified value to the control register, you can save the modifications.

The “Count up-down” functionality allows the PWM module to produce a symmetric PWM waveform by counting up from zero to the period value and then counting down from the period value back to zero. To create symmetrical modulation or bidirectional control, this mode is frequently utilised.

 EPwm1Regs.CMPA.half.CMPA 	= 2500;     		// Set compare A value

Action-Qualifier Control

The actions done on the PWM outputs based on compare events are configured using the Action-Qualifier Control Register (AQCTL) in a PWM module. It enables you to specify certain responses to various situations, such as when a counter is increasing or decreasing or when a set of requirements is satisfied.

The actions for various PWM outputs are often controlled by a number of bit fields that make up the AQCTL register. The PWM module being utilised and the microcontroller model can affect the precise setup and number of bit fields.

Let’s take an example of the TMS320F28335 microcontroller, which has an AQCTL register with two main bit fields: ZRO (Action on Zero) and PRD (Action on Period).

In this example, we are configuring the AQCTLA register for the EPwm1 module.

EPwm1Regs.AQCTLA.bit.CAU = 0x2; // Set PWM1A on event A, up count
EPwm1Regs.AQCTLA.bit.CAD = 0x1; //Clear PWM1A on event A, down count
  • ZRO (Action on Zero): When the counter approaches zero, this bit field determines the outcome to a PWM output.
    • The action “Clear” is represented by the value 0x2 for ZRO (EPwm1Regs.AQCTLA.bit.ZRO = 0x2;). This indicates that the PWM output A (EPWM1A pin) will be cleared when the counter approaches zero.
  • When the counter hits the period (TBPRD) value, the action that is taken on a PWM output is specified by the bit field known as PRD (Action on Period).
    • The action “Set” is represented by the value 0x1 for PRD (EPwm1Regs.AQCTLA.bit.PRD = 0x1;). This indicates that the PWM output A (EPWM1A pin) will be set when the counter reaches the period value.

Source Code

 * AUTHOR: Admin

#include "DSP28x_Project.h"
void Init_Gpio(void);
void Init_PWM(void);
void main(void)




void Init_Gpio(void)
    GpioCtrlRegs.GPAMUX1.bit.GPIO0	= 1;
    GpioCtrlRegs.GPADIR.bit.GPIO0	= 1;
    GpioCtrlRegs.GPAPUD.bit.GPIO0	= 1;


void Init_PWM(void)

    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;

    EPwm1Regs.TBPRD 			= 5000;      		// Set timer period 801 TBCLKs
    EPwm1Regs.TBPHS.half.TBPHS 	= 0x0000;      		// Phase is 0
    EPwm1Regs.TBCTR 			= 0x0000;           // Clear counter

    EPwm1Regs.CMPA.half.CMPA 	= 2500;     		// Set compare A value

    EPwm1Regs.TBCTL.bit.CTRMODE = 0x2; 				// Count up-down
    EPwm1Regs.TBCTL.bit.PHSEN 	= 0;        		// Disable phase loading
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;       		// Clock ratio to SYSCLKOUT
    EPwm1Regs.TBCTL.bit.CLKDIV 	= 0;

    EPwm1Regs.AQCTLA.bit.CAU 	= 0x2;     			// Set PWM1A on event A, up count
    EPwm1Regs.AQCTLA.bit.CAD 	= 0x1;   			//Clear PWM1A on event A, down count

    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;

By Admin

Leave a Reply

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

%d bloggers like this: