TM4C123GH6PM | pwm | pulse width modulation | pulse width modulation program | pwm program | Pulses

Pulse Width Modulation using TM4C Launch Pad

Program

#include<stdint.h>

#include<stdbool.h>
#include"inc/hw_memmap.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
#include"driverlib/pwm.h"
#include"driverlib/pin_map.h"
//MAIN FUNCTION
int main(void)
{
int i=0;
volatile uint8_t ui8Adjust;//VARIABLE FOR PWM_WIDTH SET AS % FROM 0 TO 100
//CLOCK SETTINGS - SET SYSTEM CLOCK TO 40MHz
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|
SYSCTL_XTAL_16MHZ);
//SET PWM CLOCK AS SYSTEM CLOCK DIVIDED BY 64
SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
//PERIPHERAL CONFIGURATION
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //PWM PERIPHERAL ENABLE
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //GPIO FOR PWM1
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1); //GPIO PF1 FOR PWM1
GPIOPinConfigure(GPIO_PF1_M1PWM5); //PD0 AS M1PWM5
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
//SET PWM GENERATOR WITH MODEOF OPERATION AS COUNTING
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2,100); //SET PERIOD OF PWM GENERATOR
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true); //ENABLE BIT5 OUTPUT
PWMGenEnable(PWM1_BASE, PWM_GEN_2); //ENABLE PWM_GEN_2 GENERATOR
while(1)
{
// PWM_WIDTH CHANGE FROM 0% - 100% IN STEPS OF 10%
for(i=1;i<11;i++)
{
ui8Adjust = i*10; //Step size of 10%
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust); //SET THE PULSE WIDTH
SysCtlDelay(4000000); //DELAY OF 300MILLISECONDS
}
}
}


Procedure

1. Create a new folder on desktop location.

2. Open ccstudio on desktop.

3. Browse the workspace location

    Click on browseàdesktopàselect created folderàok button.

4. ccstudio wizard is opened

     Click on projectànew ccs projectàtarget [select Tiva c series].

5. Select microcontroller “Tiva TM4C123GH6PM”, click on connection and select “Stellaris in-circuit debug interface”.                                     

6. Name the project in project name bar and click on finish button.

7. Click on restore button on left side and then enter the programà save button.

8. Now unfold the project and right click on project and select properties.

9. Select include optionsàaddàbrowseàmy computeràlocal disc càtià
    Tivaware_c_series_2.1.2.111
àok. Now directory path is added to project then click on ok button.   

10. Select projectà Right click on project à add files à select local disc cà  select tià Tivaware_c_series_2.1.2.111 àselect driverlib à ccs à debug àdriverlib.lib à open button.

11. Select copy files and click ok button. Now driver library file is added to the project.                                                                                                                                    

12. To build the project click on Build button.

13. After building the project is finished. Connect TM4C launch pad to pc using USB cable.

14. Before debugging set the launch pad in debug mode by pushing wake up pin and click on debug button in ccstudio.

15. Click on resume button and the output is displayed.






TM4C123GH6PM Overall Documentation in video description

Video 👇









Comments