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/TM4C123GH6PM: Noise when using PWM

Part Number: TM4C123GH6PM


Tool/software: Code Composer Studio

Hello All,

I'm using the QEI module for reading encoder and PWM gen 3 for genarating PWM for motor. Everything fine when i'm not activate the PWM module. When i active PWM module QEI module read wrong number.

I think i got mistake for configuring the PWM module.

void Config_PWM(void)
{
//Configure PWM clock to match system
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

//Enable the peripherals used by this program.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);//Tiva Launchpad has 2 modules (0 and 1) and


ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
ROM_GPIOPinConfigure(GPIO_PF3_M1PWM7);

//5ms
Period= (SysCtlClockGet()/20000)-1;
//Configure PWM Options
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, Period);

ROM_PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);

//Enable the PWM generator
ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_3);

}

 and using below function for update PID controler

void Process_PWM(float DutyCycle)
{
if(DutyCycle > 0)
{
//dir ==1 
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4, GPIO_PIN_4);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, (uint32_t)(DutyCycle*Period));
}
else
{
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4, ~(GPIO_PIN_4));
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, (uint32_t)(-DutyCycle*Period));
}
}

Best regards,

Ngoc Phu

  • For a very quick check - prevent your "else" clause from setting the PWM Pulse Width (duty cycle) to a negative number.
    The PWM Generators w/in these MCUs (often) experience difficulty when "extreme values" (very near 0 or 100% duty cycle) are loaded. Your potential load of a "negative number" jumps out as "highly risky" - and may quickly/easily be tested & confirmed...