Hi,
I'm having some difficulties with a project I am working on. I am moving a DC motor bi-directionally at varying PWM duty cycles. I move in one direction at roughly 50% and another at 25%. When I reach a sensor I set the duty cycle to zero and disable. Once in a while, I see that when I sensor gets made, the motor immediately starts moving at 100% (perhaps switch back to GPIO mode as opposed to PWM?)
Code to configure
// // Enable the PWM peripheral block. // SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // // Set the PWM Clock frequency // SysCtlPWMClockSet(SYSCTL_PWMDIV_16); // // Configure the PWM pins to be controlled by the PWM generators. // GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6); /* Takeup */ GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_2); /* Tamp */ GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinConfigure(GPIO_PA6_PWM0); /* Transfer VRef */ GPIOPinConfigure(GPIO_PF1_PWM1); /* Transfer VRef */ GPIOPinConfigure(GPIO_PA2_PWM4); /* Transfer VRef */ GPIOPinConfigure(GPIO_PE1_PWM5); /* Transfer VRef */ // // Initialize all of the PWM generators. // PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_STOP); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_STOP); PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_STOP); PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_STOP); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 100); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 100); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 100); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 100);
Here is the code I use when I start my motor
/* Set the duty cycles */ PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, sTamp.iForwardSpeed); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, sTamp.iReverseSpeed); PWMOutputState(PWM0_BASE, PWM_OUT_4_BIT | PWM_OUT_5_BIT, 1); PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_2_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, 0); /* Start the PWM generator. */ PWMGenEnable(PWM0_BASE, PWM_GEN_2);
And when I reach my switch I use
/* Stop the PWM generator. */ PWMGenDisable(PWM0_BASE, PWM_GEN_2); /* Set the duty cycles */ PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, 0); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, 0); PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT, 0);
One strange thing I notice, when I use the ROV, it tells me that the PWM clock is _DIV_1 even though I've configured it to be 16.
any thoughts?