This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Issues with PWM0 on TM4C123GH6PM Launchpad

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.

  • Hello Boris

    PWM Generator 0 has out bits corresponding to PWM_OUT_0_BIT and PWM_OUT_1_BIT. The PWM output PWM_OUT_6_BIT is not generated by Generator 0.

    I would recommend the pwm example in TivaWare to use a reference.

    Regards
    Amit
  • Thanks for answer Amit. Sorry fo long time answer

    Of course, my fail with output bits

    but this one can solve only half a problem. During initialization motor drives (lines

    GPIOPinConfigure(GPIO_PB6_M0PWM0);

    GPIOPinConfigure(GPIO_PB7_M0PWM1);

    on line -> PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);

    it rotates at half speed (looks like PWM Generator works)

    there -> PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, false);

    it drives at max speed (twice as before).  GPIOPinConfigure launch motors. I try some experiments, but still confused

    Regards

    Boris

    First time responce was not applied on forum so I try migrate to another port(port D, PWM1, Gen0). Same result.

  • SOrry,There is no pwm examples in Driverlib, or I'm blind. Can you help with this?
  • Hello Boris

    The directory to check is as follows

    D:\ti\TivaWare_C_Series-2.1.3.156\examples\peripherals\pwm

    There are example C files in the above folder.

    Regards
    Amit
  • Hello Boris

    Can you disconnect the motor to show how PWM output pins 6 and 7 are behaving with the code shown in the first post. As I said, Generator 0 cannot drive pins 6 and 7.

    Regards
    Amit
  • Hello Amit

    Now my code is:

    SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlDelay(5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
    SysCtlDelay(5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlDelay(5);
    
    GPIOPinConfigure(GPIO_PD0_M1PWM0);
    GPIOPinConfigure(GPIO_PD1_M1PWM1);  // configuring PD0 PD1 as PWM outputs
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    
    SysCtlPWMClockSet(SYSCTL_PWMDIV_32);
    PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 100); // 10khz freq 250 25khz-100
    PWMPulseWidthSet (PWM1_BASE, PWM_OUT_0, 50);
    PWMDeadBandEnable(PWM1_BASE, PWM_GEN_0, 0.1* 100, 0.1*100);
    PWMGenEnable(PWM1_BASE, PWM_GEN_0); //enable generator
    
    Ready(1); //LED on and off on launchpad (connected to portF), short delay
    	  while(1){
    	      
    	      PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
    	      SysCtlDelay(40000000);
    	      PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, false); // off
    	      SysCtlDelay(40000000);
    
    
    	  }

    Initialization According to Tivaware example/

    Same thing. Motor drives on GPIOPinConfigure(GPIO_PD0_M1PWM0);

    slows on PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);

    drives faster PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, false);.

    of course? if i disconnect motor, anything on this does not happen. Itry measure voltage with voltemeter on PD0 pin/ on initialization - 0 (when my motor drive), when true status

     PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true) 1.1V (because of duty cycle is half of period),  
    on PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, false) - 0V (but motor drive)
    I don't understand. Still confused

    Thanks for yoyr help
    Regards