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.

CCS/TM4C1294NCPDT: TM4C1294NCPDT

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

This is the driver for PWM.  I have found the error as below.

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "drivers/pinout.h"
#include "driverlib/rom_map.h"


//system clock variable
uint32_t g_ui32SysClock;

int main(void){

//1. set the clock to run off of crystal at 25Mhz
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN \
| SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

//2. Enable the PWM Module in the System Control using
//enable peripheral (port F)
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//2b. secret level; unlock port F0 so that we can use it!!! >=O
while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)));
HWREG(GPIO_PORTF_AHB_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_AHB_BASE+GPIO_O_CR) |= GPIO_PIN_0;

//configure pin as a PWM pin
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinConfigure(GPIO_PF0_M0PWM0);

//3. Set the pwm clock to the system clock/64
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_64);

//4. Configure the PWM generator
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, (PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC));

//5. Set the period for the generator
//set pwm to run at 100hz . (N = (1 / f) * SysClk) ; (1 / 100Hz) * (120MHz/64) = 18750 cycles
unsigned long period = 18750;
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, period);

//6. Enable the PWM outputs
// Enable the PWM1 Bit 0 (PF1) and Bit 1 (PF2) output signals.
PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);

//7. set the pulse width
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, (period/2));

//8. Enable the PWM Generator
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}

The errors are 

The errors are marked in this area of the program as shown below.

  • Hi azim,
    If I move the unsigned long period = 18750 right below the main() then it compiles ok.

    int main(void){

    unsigned long period = 18750;
  •  Further, This is my deadband PWM example code whare i get the error.

    //*****************************************************************************

    //

    // dead_band.c - Example demonstrating the dead-band generator.

    //

    // Copyright (c) 2010-2017 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 is part of revision 2.1.4.178 of the Tiva Firmware Development Package.

    //

    //*****************************************************************************

    #include <stdbool.h>

    #include <stdint.h>

    #include "inc/hw_memmap.h"

    #include "driverlib/gpio.h"

    #include "driverlib/pin_map.h"

    #include "driverlib/pwm.h"

    #include "driverlib/sysctl.h"

    #include "driverlib/uart.h"

    #include "utils/uartstdio.h"

    //*****************************************************************************

    //

    //! \addtogroup pwm_examples_list

    //! <h1>PWM dead-band (dead_band)</h1>

    //!

    //! This example shows how to setup the PWM0 block with a dead-band generation.

    //!

    //! This example uses the following peripherals and I/O signals.  You must

    //! review these and change as needed for your own board:

    //! - GPIO Port B peripheral (for PWM pins)

    //! - M0PWM0 - PB6

    //! - M0PWM1 - PB7

    //!

    //! The following UART signals are configured only for displaying console

    //! messages for this example.  These are not required for operation of the

    //! PWM.

    //! - UART0 peripheral

    //! - GPIO Port A peripheral (for UART0 pins)

    //! - UART0RX - PA0

    //! - UART0TX - PA1

    //!

    //! This example uses the following interrupt handlers.  To use this example

    //! in your own application you must add these interrupt handlers to your

    //! vector table.

    //! - None.

    //

    //*****************************************************************************

    //*****************************************************************************

    //

    // The variable g_ui32SysClock contains the system clock frequency

    //

    //*****************************************************************************

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

    uint32_t g_ui32SysClock;

    #endif

    //*****************************************************************************

    //

    // This function sets up UART0 to be used for a console to display information

    // as the example is running.

    //

    //*****************************************************************************

    void

    InitConsole(void)

    {

       //

       // Enable GPIO port A which is used for UART0 pins.

       // TODO: change this to whichever GPIO port you are using.

       //

       SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

       //

       // Configure the pin muxing for UART0 functions on port A0 and A1.

       // This step is not necessary if your part does not support pin muxing.

       // TODO: change this to select the port/pin you are using.

       //

       GPIOPinConfigure(GPIO_PA0_U0RX);

       GPIOPinConfigure(GPIO_PA1_U0TX);

       //

       // Enable UART0 so that we can configure the clock.

       //

       SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

       //

       // Use the internal 16MHz oscillator as the UART clock source.

       //

       UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

       //

       // Select the alternate (UART) function for these pins.

       // TODO: change this to select the port/pin you are using.

       //

       GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

       //

       // Initialize the UART for console I/O.

       //

       UARTStdioConfig(0, 115200, 16000000);

    }

    //*****************************************************************************

    //

    // Prints out 5x "." with a second delay after each print.  This function will

    // then backspace, clearing the previously printed dots, and then backspace

    // again so you can continuously printout on the same line.  The purpose of

    // this function is to indicate to the user that the program is running.

    //

    //*****************************************************************************

    void

    PrintRunningDots(void)

    {

       UARTprintf(". ");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

       UARTprintf(". ");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

       UARTprintf(". ");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

       UARTprintf(". ");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

       UARTprintf(". ");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

       UARTprintf("\b\b\b\b\b\b\b\b\b\b");

       UARTprintf("          ");

       UARTprintf("\b\b\b\b\b\b\b\b\b\b");

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       SysCtlDelay(g_ui32SysClock / 3);

    #else

       SysCtlDelay(SysCtlClockGet() / 3);

    #endif

    }

    //*****************************************************************************

    //

    // Configure the PWM0 block with dead-band generation.  The example configures

    // the PWM0 block to generate a 25% duty cycle signal on PD0 with dead-band

    // generation.  This will produce a complement of PD0 on PD1 (75% duty cycle).

    // The dead-band generator is set to have a 10us or 160 cycle delay

    // (160cycles / 16Mhz = 10us) on the rising and falling edges of the PD0 PWM

    // signal.

    //

    //*****************************************************************************

    int

    main(void)

    {

       //

       // Set the clocking to run directly from the external crystal/oscillator.

       // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the

       // crystal on your board.

       //

    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \

       defined(TARGET_IS_TM4C129_RA1) ||                                         \

       defined(TARGET_IS_TM4C129_RA2)

       g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |

                                           SYSCTL_OSC_MAIN |

                                           SYSCTL_USE_OSC), 25000000);

    #else

       SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |

                      SYSCTL_XTAL_16MHZ);

    #endif

       //

       // Set the PWM clock to the system clock.

       //

       SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

       //

       // Set up the serial console to use for displaying messages.  This is just

       // for this example program and is not needed for PWM operation.

       //

       InitConsole();

       //

       // Display the setup on the console.

       //

       UARTprintf("PWM ->\n");

       UARTprintf("  Module: PWM0\n");

       UARTprintf("  Pin(s): PD0 and PD1\n");

       UARTprintf("  Features: Dead-band Generation\n");

       UARTprintf("  Duty Cycle: 25%% on PD0 and 75%% on PD1\n");

       UARTprintf("  Dead-band Length: 160 cycles on rising and falling edges\n\n");

       UARTprintf("Generating PWM on PWM0 (PD0) -> ");

       //

       // The PWM peripheral must be enabled for use.

       //

       SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

       //

       // For this example PWM0 is used with PortB Pins 6 and 7.  The actual port

       // and pins used may be different on your part, consult the data sheet for

       // more information.  GPIO port B needs to be enabled so these pins can be

       // used.

       // TODO: change this to whichever GPIO port you are using.

       //

       SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

       SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

       //

       // Configure the GPIO pin muxing to select PWM functions for these pins.

       // This step selects which alternate function is available for these pins.

       // This is necessary if your part supports GPIO pin function muxing.

       // Consult the data sheet to see which functions are allocated per pin.

       // TODO: change this to select the port/pin you are using.

       //

       GPIOPinConfigure(GPIO_PF1_M0PWM1);

       GPIOPinConfigure(GPIO_PF2_M0PWM2);

       //

       // Configure the GPIO pad for PWM function on pins PB6 and PB7.  Consult

       // the data sheet to see which functions are allocated per pin.

       // TODO: change this to select the port/pin you are using.

       //

       GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);

       GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);

       //

       // Configure the PWM0 to count up/down without synchronization.

       // Note: Enabling the dead-band generator automatically couples the 2

       // outputs from the PWM block so we don't use the PWM synchronization.

       //

       PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |

                       PWM_GEN_MODE_NO_SYNC);

       //

       // Set the PWM period to 250Hz.  To calculate the appropriate parameter

       // use the following equation: N = (1 / f) * SysClk.  Where N is the

       // function parameter, f is the desired frequency, and SysClk is the

       // system clock frequency.

       // In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles.  Note that

       // the maximum period you can set is 2^16 - 1.

       // TODO: modify this calculation to use the clock frequency that you are

       // using.

       //

       PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 64000);

       //

       // Set PWM0 PD0 to a duty cycle of 25%.  You set the duty cycle as a

       // function of the period.  Since the period was set above, you can use the

       // PWMGenPeriodGet() function.  For this example the PWM will be high for

       // 25% of the time or 16000 clock cycles (64000 / 4).

       //

       PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,

                        PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 4);

       //

       // Enable the dead-band generation on the PWM0 output signal.  PWM bit 0

       // (PD0), will have a duty cycle of 25% (set above) and PWM bit 1 will have

       // a duty cycle of 75%.  These signals will have a 10us gap between the

       // rising and falling edges.  This means that before PWM bit 1 goes high,

       // PWM bit 0 has been low for at LEAST 160 cycles (or 10us) and the same

       // before PWM bit 0 goes high.  The dead-band generator lets you specify

       // the width of the "dead-band" delay, in PWM clock cycles, before the PWM

       // signal goes high and after the PWM signal falls.  For this example we

       // will use 160 cycles (or 10us) on both the rising and falling edges of

       // PD0.  Reference the datasheet for more information on dead-band

       // generation.

       //

       PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 160, 160);

       //

       // Enable the PWM0 Bit 0 (PD0) and Bit 1 (PD1) output signals.

       //

       PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);

       //

       // Enables the counter for a PWM generator block.

       //

       PWMGenEnable(PWM0_BASE, PWM_GEN_0);

       //

       // Loop forever while the PWM signals are generated.

       //

       while(1)

       {

           //

           // Print out indication on the console that the program is running.

           //

           PrintRunningDots();

       }

    }

  • May we note this (last) code posting as the most, "difficult & unfriendly for helper read/review EVER?"
    All of those "commented out" code lines "EXHAUST & DULL the interest" of your reader-helpers - do they not?    

    Have you not "traded" your "ease & speed" (in presentation) for "Helper Agony?"    (Ans: clearly YES!)

  • Hello azim,

    For the second error you report, it looks like you have two main() functions included in the same project. You can only have one main() function in a given project. Find which of the two you don't need, remove it, and then try again.