I have the MD10C DC Motor that I am trying to drive by TM4C129. Below Code
The motor has two direction, A and B. Using below code, the motor only moves in 'A' direction. No matter whether I toggle the GPIO_PIN_4 or not, in
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_4, ~GPIO_PIN_4);
it only moves in 'A' direction. In fact, if I comment out the GPIOPinWrite call, even then it moves to 'A' direction and never towards 'B'. What am I missing? Is the pin setup sequence right?
#define RAMP 0.35
Motor::Motor() {
period = 65000; //20ms (16Mhz / 64pwm_divider / 50)
duty = period; //default is off (PWM counts down)
oldval = 0;
motorDIR =-1;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
//Configure PWM Clock divide system clock by 64
SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
//Configure PK5 as PWM signal to motor driver
GPIOPinConfigure(GPIO_PK5_M0PWM7);
GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_5);
// Set PK4 as output, SW controlled. for direction
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_4, 0);
// configure PWM
PWMGenConfigure(PWM0_BASE, PWM_GEN_3,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//Set the Period (expressed in clock ticks)
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, period);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, duty);
PWMGenEnable(PWM0_BASE, PWM_GEN_3);
PWMOutputInvert(PWM0_BASE, PWM_OUT_7_BIT, 1);
// Turn on the Output pins
PWMOutputState(PWM0_BASE, PWM_OUT_7_BIT, true);
//
}
void Motor::update(double value) {
oldval=value;
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_4, ~GPIO_PIN_4);
duty = (uint32_t) (period - (fabs(oldval) * period));
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, duty);
}