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.

EK-TM4C123GXL LaunchPad M1PWM6 and M1PWM7 problem

Hi, I'm using CCSv6 and wrote some codes based on the Launchpad Workshop Lab 15.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"

#define PWM_FREQUENCY 200

int main(void) {

	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile int32_t i32DutyCycle = 500;

	// Run at 40 MHz
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	// Set PWM clock at 40e6/64 = 625 kHz
	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	// Enable M1PWMx
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

	// Enable port F for PF4 (SW1), PF0 (SW2), PF2 (M1PWM6), PF3 (M1PWM7)
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	// Set PF2 and PF3 as PWM output pins
	ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_3);

	// Configure PF2 as M1PWM6, and PF3 as M1PWM7
	ROM_GPIOPinConfigure(GPIO_PF2_M1PWM6|GPIO_PF3_M1PWM7);

	// Unlock the GPIO commit control register (for PF0)
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;

	// Set PF4 (SW1) and PF0 (SW2) as input pulled-up
	ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
	ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

	ui32PWMClock = ROM_SysCtlClockGet() / 64;
	// Load = 625000/20 - 1 = 31249 ticks
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

	// Configure M1PWM6 and M1PWM7 as a down-counter (count to zero)
	ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);

	// Set the pulse-width (# of clock ticks)
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui32Load*i32DutyCycle/1000);
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui32Load - ui32Load*i32DutyCycle/1000);
	// Enable the outputs
	ROM_PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT|PWM_OUT_7_BIT, true);
	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_3);

	while(1)
	{
		if(ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4) == 0x00)
		{
			i32DutyCycle --;
			if (i32DutyCycle < 0)
			{
				i32DutyCycle = 0;
			}
		}

		if(ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 0x00)
		{
			i32DutyCycle ++;
			if (i32DutyCycle > 999)
			{
				i32DutyCycle = 999;
			}
		}

		ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui32Load*i32DutyCycle/1000);
		ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui32Load - ui32Load*i32DutyCycle/1000);
		ROM_SysCtlDelay(20e3);
	}
}

The first problem is that only the green LED on PF3 works. The blue LED on PF2 never lit up.

Also, when I use "non-ROM" functions, such as changing ROM_SysCtlClockGet() to SysCtlClockGet(), there will be a compilation failure.

**** Build of configuration Debug for project PWM_test ****

"c:\\ti\\ccsv6\\utils\\bin\\gmake" -k all 
'Building file: ../main.c'
'Invoking: ARM Compiler'
"c:/ti/ccsv6/tools/compiler/arm_5.1.6/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 --abi=eabi -me --include_path="c:/ti/ccsv6/tools/compiler/arm_5.1.6/include" --include_path="C:/ti/TivaWare_C_Series-2.1.0.12573" -g --define=PART_TM4C123GH6PM --define=TARGET_IS_BLIZZARD_RB1 --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
'Finished building: ../main.c'
' '
'Building target: PWM_test.out'
'Invoking: ARM Linker'
"c:/ti/ccsv6/tools/compiler/arm_5.1.6/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 --abi=eabi -me -g --define=PART_TM4C123GH6PM --define=TARGET_IS_BLIZZARD_RB1 --display_error_number --diag_warning=225 --diag_wrap=off -z -m"PWM_test.map" --heap_size=0 --stack_size=512 -i"c:/ti/ccsv6/tools/compiler/arm_5.1.6/lib" -i"c:/ti/ccsv6/tools/compiler/arm_5.1.6/include" --reread_libs --warn_sections --display_error_number --diag_wrap=off --xml_link_info="PWM_test_linkInfo.xml" --rom_model -o "PWM_test.out"  "./tm4c123gh6pm_startup_ccs.obj" "./main.obj" "../tm4c123gh6pm.cmd" -l"libc.a" 
<Linking>

 undefined      first referenced
  symbol            in file     
 ---------      ----------------
 SysCtlClockGet ./main.obj      

error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking; "PWM_test.out" not built

>> Compilation failure
gmake: *** [PWM_test.out] Error 1
gmake: Target `all' not remade because of errors.

**** Build Finished ****

The same issue also occurs while using the very same code provided by the Workshop.

Can anyone help me?

  • Hello Ming

    The first issue is to be solved as below

    ROM_GPIOPinConfigure(GPIO_PF2_M1PWM6|GPIO_PF3_M1PWM7);

    replace as

    ROM_GPIOPinConfigure(GPIO_PF2_M1PWM6);

    ROM_GPIOPinConfigure(GPIO_PF3_M1PWM7);

    Regarding the second problem, the issue is that the driverlib has not been added during linker phase

    To do so,

    Right Click your project -> Show Build Settings -> Build -> ARM Linker -> File Search Path.

    There add the path to the driverlib.lib file which should be as below

    "C:\ti\TivaWare_C_Series-2.1.0.12573\driverlib\ccs\Debug\driverlib.lib"

    Regards

    Amit

  • Thank you Amit, these problems are solved. But there are still some other problems...

    During debug mode, if I click the "Suspend" button there will be a error message.

    Also, the "Type" and "Value" in the Expression window appears wired...

    Do these two problems relate to each other?

    In addition, what is the minimum valid value of ui32Width for the function PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut, uint32_t ui32Width) ?

    While I set ui32Width to zero, I expect the LEDs will dim down. But instead the LED always stays bright.

    Am I doing something wrong?

  • Hello Ming,

    Since you are calling ROM API's, the code will branch to ROM (indicated by 0x0100.0000 address space). Since it is a linked code for which there is no obj to refer to, you would see the first message "No source available 0x1001024".

    The second one is because the variables are in lock to the function main. Hence when the function changes, the scope of the these variables are lost.

    For the last issue, you would need to go through the API in the pwm.c to see how the value translated to duty cycle and how the LED is connected, common anode or common cathode configuration.

    Regards

    Amit