Hello,
I am trying to implement a motor regulation application with the evaluation kit TM4C1294XL. It seems that there is an issue by using the combination of PWM and QEI. Separately, both moduls are working fine. So I am able to generate a PWM signal with a given dutycycle. Furthermore it is possible to read and calculate the velocity and RPM by using the QEI.
I calculate the current rpm and fit the pi regulation algorithm. This algorithm returns the a new dutycycle. As soon as I fit the new calculated dutycycle to the ROM_PWMPulseWidthSet function it seems that the period time of the PWM signal changes to the selected measure time of the qei modul which I configured with the function ROM_QEIVelocityConfigure
Do you have any idea how I could solve the problem? .. it seems that the qei blocks the pwm modul. could it be the reason?
Here the init code blocks and main routine:
// Enable QEI Peripherals ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); //PL1; PL2 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0); //Set Pins to be PHA0 and PHB0 ROM_GPIOPinConfigure(GPIO_PL1_PHA0); ROM_GPIOPinConfigure(GPIO_PL2_PHB0); //Set GPIO pins for QEI. ROM_GPIOPinTypeQEI(GPIO_PORTL_BASE, GPIO_PIN_1 | GPIO_PIN_2); //DISable peripheral and int before configuration ROM_QEIDisable(QEI0_BASE); ROM_QEIIntDisable(QEI0_BASE, QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX); // Configure quadrature encoder, use an arbitrary top limit of 2000 ROM_QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 479);//QEI_CONFIG_CLOCK_DIR // Enable the quadrature encoder. ROM_QEIEnable(QEI0_BASE); //Set position to a middle value so we can see if things are working ROM_QEIPositionSet(QEI0_BASE, 0); ROM_QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 120000000); //1000ms measure time ROM_QEIVelocityEnable(QEI0_BASE);
// enable necessary peripherals ROM_SysCtlPeripheralEnable(L298N_PWM_CONFIG0); ROM_SysCtlPeripheralEnable(L298N_PWM_CONFIG1); ROM_SysCtlPeripheralEnable(L298N_GPIO_CONFIG0); ROM_SysCtlPeripheralEnable(L298N_GPIO_CONFIG1); // setup digital output signals for direction pins ROM_GPIOPinTypeGPIOOutput(L298N_IN1); // IN1 ROM_GPIOPinTypeGPIOOutput(L298N_IN2); // IN2 // set pwm clock ROM_PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_8); // 15 MHz pwm_clock = (system_clock / 8); ROM_GPIOPinConfigure(L298N_ENA_TYPE); ROM_GPIOPinTypePWM(L298N_ENA); // set pwm mode ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // set pwm period time //period_time_ticks = ((system_clock / 64) / PWM_FREQUENCY)-1; period_time_ticks = (pwm_clock / PWM_FREQUENCY); ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, period_time_ticks); // enable pwm output ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true); // start pwm generator (timers) ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
while(1) { regulation.setParameters(Kp, Ki, Kd); // run motor motordriver.run(FORWARD, duty); // measure RPM rpm_sensor.calculateRPM(); rpm_x = rpm_sensor.getRPM(); // update motor regulation algorithm duty = regulation.PI_Regulation(rpm_w, rpm_x); ROM_SysCtlDelay(g_ui32SysClock/3 /100); // 10ms if(a==1) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); a=2; } else if(a==2) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1); a=1; } }
Many thanks in advanced!
Best regards