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.

crazy PWM

Other Parts Discussed in Thread: DRV8825, DRV8844

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?

  • Luke,

    Which device and which software products are you using?

    Also, you indicate “when I use the ROV, it tells me that the PWM clock is _DIV_1 even though I've configured it to be 16.”  By ROV do you mean the SYS/BIOS Runtime Object Viewer?  If so, can you please clarify how you are doing that?

    Thanks,
    Scott

  • Sorry, I should have provided more background info.  I'm using an Lm3s9b96 with a few DRV8825's and DRV8844, and TI-RTOS 1.1.0.25.  This problem happens once in about 200 runs with no real pattern.

  • Luke,

    OK, thanks.

    Are you noticing any other issues when running the program?

    In ROV, if you click on the BIOS module, then on the “Scan for errors…” tab, do you see any errors reported?

    Also, can you clarify how you checked the PWM clock with ROV?  Was it actually ROV, or a debugger peripheral register or memory view?

    If there is nothing else amiss in the program, I think the best suggestion I have at this point is for you to post the questions to the Stellarisware forum (http://e2e.ti.com/support/microcontrollers/stellaris_arm/default.aspx)  There will probably be many more people familiar with the PWM code there.

    Scott

  • No, that is really the only major issue.  As I said, I have two motors, and it seems once in a while, they will just revert back to GPIO (alt function?).  Systematically removing the TI-RTOS GPIO.h calls (such as GPIO_write) and replacing them w/ Stellarisware GPIOPinWrite functions has helped increase the reliability, but I am still in the neighborhood of a 0.5% error.  Occasionally, interrupts get missed as well.

    I did scan for errors, to no avail.  I can see in the ROV, if I click the Boot module, I can see pwmClockDiv is set to PWMDIV_1.

     

    I will give that other thread a read.