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 signal to PF2

Hello! I use TM4C123G Evaluation Kit and I want to make a PWM to PF2, but I don't see where I go wrong :(

I don't see the signal on PF2. 

the code:

volatile unsigned int PWMora;
volatile unsigned int freki_1;

#define PWM_FREQUENCY 100


//*****************************************************************************
//
// PWM1_GEN_3
//
//*****************************************************************************
void
PWM1gen3IntHandler(void)
{
PWMGenIntClear( PWM1_BASE, PWM_GEN_3, PWM_INT_CNT_ZERO);

unsigned int duty;

duty = PWMPulseWidthGet(PWM1_BASE, PWM_OUT_6)+1;
if(duty==freki_1)duty=freki_1/2;
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, duty);

}


int
main(void)
{


//Sysclock
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

//***********************************************
//
//PWM
//
//***********************************************

//PWMclock
SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
//GPIO
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOPinConfigure(GPIO_PF2_M1PWM6);

PWMora = ROM_SysCtlClockGet() / 64;

freki_1 = (PWMora / PWM_FREQUENCY);

//Conf. PWM gen
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);

PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, freki_1);

PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, freki_1);

PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);

PWMGenEnable( PWM1_BASE, PWM_GEN_3);


//Interrupt enable
IntMasterEnable();
PWMIntEnable( PWM1_BASE, PWM_INT_GEN_3);
IntEnable(INT_PWM1_3);
PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_3, PWM_INT_CNT_ZERO);


// Loop forever

while(1)

{

}
}

parts from the startup:

...

extern void PWM1gen3IntHandler(void);

...

IntDefaultHandler,                   // GPIO Port Q7
IntDefaultHandler,                   // GPIO Port R
IntDefaultHandler,                   // GPIO Port S
IntDefaultHandler,                   // PWM 1 Generator 0
IntDefaultHandler,                   // PWM 1 Generator 1
IntDefaultHandler,                   // PWM 1 Generator 2
PWM1gen3IntHandler,            // PWM 1 Generator 3
IntDefaultHandler                    // PWM 1 Fault

...

  • Hello Joseph,

    Is the device going to the while(1) loop at the end of the code or is it getting into a Fault ISR (Since the enable for the clock GPIO is close to the configuration).

    The other thing is that the Pulse Width and the Frequency are the same value, which would mean that the signal may not toggle. Can you try using 50% as the Pulse Width value?

    Regards

    Amit

  • Thanks! I didn't notice, that part :D

    now its looks like this: 

    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, freki_1);

    PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, freki_1/2);

    and now it lands in my while loop, but still no pwm on the pin :(

  • Hello Joseph,

    I had written the attached code quite some time back for the LaunhPad. You may want to see if this helps. If not then may be the first thing to do is to check the RGB blinky program is working on the launchpad to ensure the pin is fine.

    #include "stdint.h"
    #include "stdbool.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/timer.h"
    #include "driverlib/pwm.c"
    #include "driverlib/pwm.h"
    #include "driverlib/pin_map.h"
    
    int main(void)
    {
    	unsigned long ulPeriod;
    
    	//Set the clock
    	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //for 80 MHz
    
    	//Configure PWM Clock to match system
    	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
    	// Enable the peripherals used by this program.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins
    	ulPeriod = 80000000 / 1000000; // PWM frequency
    
    	//Configure PF1,PF2,PF3 Pins as PWM
    
    	GPIOPinConfigure(GPIO_PF1_M1PWM5);
    	GPIOPinConfigure(GPIO_PF2_M1PWM6);
    	GPIOPinConfigure(GPIO_PF3_M1PWM7);
    	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    
    	//Configure PWM Options
    	//PWM_GEN_2 Covers M1PWM4 and M1PWM5
    	//PWM_GEN_3 Covers M1PWM6 and M1PWM7 See page 207 4/11/13 DriverLib doc
    	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    
    	//Set the Period (expressed in clock ticks)
    	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod);
    	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ulPeriod);
    
    	//Set PWM duty-50% (Period /2)
    	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ulPeriod/(100/30));
    	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ulPeriod/2);
    	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ulPeriod/2);
    
    	// Enable the PWM generator
    	PWMGenEnable(PWM1_BASE, PWM_GEN_2);
    	PWMGenEnable(PWM1_BASE, PWM_GEN_3);
    
    	// Turn on the Output pins
    	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT |PWM_OUT_6_BIT|PWM_OUT_7_BIT, true);
    
    	//Do nothing
    	while(1)
    	{
    
    	}
    }
    

    Regards

    Amit

  • Joseph Nice said:
    SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

    Have you checked your MCU"s recent errata?  I recall that (often) these devices behave badly w/"PWMDIV_64".

    In addition - it's most always easiest/safest to avoid interrupts when bringing up a peripheral for the first few times.  That PWM Generator should run quite happily w/out the complexity/dependence upon interrupts..

    Switch to a different PWMDIV & I bet a proper PWM signal will land - your doorstep...

  •  The sad part is that the problem is that I forgot to use Verify Download and Use flash loader option on Options > Debugger > Download 

    So joke on me :)

    Now its working and   without your same freq coment on your first post it still go wrong, so I give you the point. 

    Thank you all for the responses!