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