This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

problem with PWM ON EK-TM4C123GXL BOARD

Other Parts Discussed in Thread: EK-TM4C123GXL, TM4C123GH6PM

I'm trying to use PWM module to drive on board RGB LED available on EK-TM4C123GXL board.

I'm using Keil MDK v5 as my IDE.

my code for PWM initialization is given below. 

-----------------------------------------------------------------------------------------------------------------------------------

#include "tm4c123gh6pm.h"

void Pwm1Init(void) 
{
	volatile unsigned long delay;
	SYSCTL_RCC_R &=  0xFFF1FFFF;   //PWM CLOCK = SYS CLOCK /2 
	delay = SYSCTL_RCC_R;          // 3 clock cycle delay
	SYSCTL_RCGC0_R = 0x00100000;  // enable run mode clock to PWM module
	delay = SYSCTL_RCC_R;          // 3 clock cycle delay
	SYSCTL_RCGC2_R = 0x00000020;     //  PORT F  clock enable
	delay = SYSCTL_RCGC0_R;          // 3 clock cycle delay      
	GPIO_PORTF_LOCK_R = 0x4C4F434B;   //  unlock PortF PF0  
        GPIO_PORTF_CR_R =   0x000000FF;    // allow changes to PF4-0  
	GPIO_PORTF_AMSEL_R = 0x00000000;
	GPIO_PORTF_AFSEL_R = 0x000000FF;  //SELECT ALT FUNCTION FOR PF1,PF2,PF3
	GPIO_PORTF_PCTL_R =  0x00001110;   // PWM AS ALT FUNCTION FOR PF1,PF2,PF3
	
	PWM1_CTL_R    = 0x0000000F;   // ENABLE PWM MASTER CONTROL CLOCK
	PWM1_3_CTL_R  = 0x00000001;
	PWM1_3_GENA_R = 0x0000004C;
	PWM1_3_GENB_R = 0x0000040C;
	PWM1_3_LOAD_R = 0x0000018F;   // 25 kHz PWM SIGNAL
	PWM1_3_CMPA_R = 0x0000012B;   // 50% DUTY CYCLE
	PWM1_3_CMPB_R = 0x00000063;   // 75% DUTY CYCLE
	
	PWM1_ENABLE_R = 0x000000FF;   // ENABLE OUTPUT ON PORT F
	
	
}

---------------------------------------------------------------------------------------------------------------------------

but the PWM output is not coming.

please inform what is the correction to this code to make it functional. 

 

 

  • Hello Chinmaya,

    The GPIO PORT F DEN register is not set.

    Regards

    Amit

  • But the datasheet "tm4c123gh6pm.pdf" says : PWM module output is analog output and Digital function should be disabled.

    I'm very confused. 

  • Amit,

    can you tell me the steps please.

    I followed the steps given in the pdf "tm4c123gh6pm.pdf". but it is not working. 

    thanks in advance..

  • Hello Chinmaya

    Where in the data sheet is that mentioned?

    Did you write the DEN register for the corresponding bits. Also the Port Control is also not correct for PWM-1. Please check the Signal Mux Table. Also why don't you use the API instead of using _R access. The code will more readable and in the long run help.

    Regards

    Amit

  • I tried using the function generated by Texas Instruments TIVA C Series PinMux Utility.

    the code generated by PinMux utility is given below

    ---------------------------------------------------------------------------------------------------

    //*****************************************************************************
    // Copyright (c) 2014 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    //
    // This file was automatically generated by the Tiva C Series PinMux Utility
    // Version: 1.0.4
    //
    //*****************************************************************************
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "PWM_LED.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/gpio.h"
    #include "tm4c123gh6pm.h"
    
    //*****************************************************************************
    void
    PortFunctionInit(void)
    {
        //
        // Enable Peripheral Clocks 
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        //
        // Enable pin PF0 for GPIOInput
        //
    
        //
        //First open the lock and select the bits we want to modify in the GPIO commit register.
        //
        HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
        HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;
    
        //
        //Now modify the configuration of the pins that we unlocked.
        //
        MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
    
        //
        // Enable pin PF2 for PWM1 M1PWM6
        //
        MAP_GPIOPinConfigure(GPIO_PF2_M1PWM6);
        MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
    
        //
        // Enable pin PF3 for PWM1 M1PWM7
        //
        MAP_GPIOPinConfigure(GPIO_PF3_M1PWM7);
        MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
    }

    -----------------------------------------------------------------------------------------------

    the compiler gives an error message as below:

    ------------------------------------------------------------------------------------------------------------------------

    PWM_LED.c(78): error:  #20: identifier "GPIO_PF2_M1PWM6" is undefined
          MAP_GPIOPinConfigure(GPIO_PF2_M1PWM6);
    PWM_LED.c(84): error:  #20: identifier "GPIO_PF3_M1PWM7" is undefined
          MAP_GPIOPinConfigure(GPIO_PF3_M1PWM7);
    PWM_LED.c: 1 warning, 2 errors

    ---------------------------------------------------------------------------------------------------------------------------

    what is the solution?

  • Hello Chinmaya

    Please add the --include option for PART_TM4C123GH6PM during compilation. There are few posts on E2E over the last 2 weeks where members have had this problem and the post graphically shows how to add include options.

    Regards

    Amit