I try to drive DC motor with PWM. PB6 and PB7 connect to H-bridge L9110 and then to motor. Here is my initialization code(CCSv6):
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); SysCtlDelay(5); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlDelay(5); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlDelay(5); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6|GPIO_PIN_7); GPIOPinConfigure(GPIO_PB6_M0PWM0); GPIOPinConfigure(GPIO_PB7_M0PWM1); // configuring PB6 PB7 as PWM outputs SysCtlPWMClockSet(SYSCTL_PWMDIV_32); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 250); // 10khz freq PWMPulseWidthSet (PWM0_BASE, PWM_OUT_0, 50); // 50% duty cycle PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 0.1* 100, 0.1*100);
i wrote simple code in main to turn on and turn off motor:
while(1){ PWMGenEnable(PWM0_BASE, PWM_GEN_0); //enable generator PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true); SysCtlDelay(40000000); PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, false); // off SysCtlDelay(40000000); }
But motor start to go on this line of code (when i debug step by step in CCSv6)
GPIOPinConfigure(GPIO_PB6_M0PWM0); // writing to PCTL register
before PWM generator is configured and PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true/false) has no effect.
I try move GPIOPinConfigure(GPIO_PB6_M0PWM0) in different places but OutputState(true/false) has no effect.
Can anybody help with this issues? Thanks
P.S. try change PWM frequency or duty cycle - has no effect.
Sorry for a long post, want to notice all nuances.