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.

Control multi PWM signal

Hi

I'm using TM4C123G board to generate three pair of PWM signal to control 3 phase of BLDC motor.

The code i wrote is enable 3 pwm at the same time, and how to make pwm0 then 120 degree delay to pwm1 then 120 degree to pwm2.

like this, with dead-bane config.

Here is the code :

#include "include.h"
#include "inc/hw_gpio.h"
#include "driverlib/qei.h"
#include "driverlib/pwm.h"
#include "driverlib/fpu.h"
#include "driverlib/rom.h"

inline void ConfigSystem(void)
{
	// Config clock
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
}

void ConfigPWM(void)
{
	//Configures the rate of the clock provided to the PWM module
	//= System Clock / 1
	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	//Enable PWM0
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);


	//Enable GPIO B
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	//Enable GPIO D
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	//Configures PB6, PB7 for use by the PWM0 peripheral.
	ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7 | GPIO_PIN_6);
	ROM_GPIOPinConfigure(GPIO_PB7_M0PWM1);
	ROM_GPIOPinConfigure(GPIO_PB6_M0PWM0);

	//Configures PB4, PB5 for use by the PWM1 peripheral.
	ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5);
	ROM_GPIOPinConfigure(GPIO_PB4_M0PWM2);
	ROM_GPIOPinConfigure(GPIO_PB5_M0PWM3);

	//Configures PD0, PD1 for use by the PWM2 peripheral.
	ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	ROM_GPIOPinConfigure(GPIO_PD0_M0PWM6);
	ROM_GPIOPinConfigure(GPIO_PD1_M0PWM7);


	//Set the mode of operation for a PWM generator 0
	ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN |
                    PWM_GEN_MODE_NO_SYNC);
	//Set the mode of operation for a PWM generator 1
	ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN |
	                    PWM_GEN_MODE_NO_SYNC);
	//Set the mode of operation for a PWM generator 2
	ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN |
		                    PWM_GEN_MODE_NO_SYNC);


	//Sets the period of the specified PWM0 generator block - Chu ky = ROM_SysCtlClockGet() / DEFAULT
	ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ROM_SysCtlClockGet() / DEFAULT);
	//Sets the period of the specified PWM0 generator block - Chu ky = ROM_SysCtlClockGet() / DEFAULT
	ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ROM_SysCtlClockGet() / DEFAULT);
	//Sets the period of the specified PWM0 generator block - Chu ky = ROM_SysCtlClockGet() / DEFAULT
	ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, ROM_SysCtlClockGet() / DEFAULT);

	//Sets the pulse width for the specified PWM0 output
	//25%-75%
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,
    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	//Enable specified PWM0 output
	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
	//Select the inversion mode for the selected PWM0 outputs
	ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_0_BIT, false);
	ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_1_BIT, true);


	//Sets the pulse width for the specified PWM1 output
	//25%-75%
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,
	    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,
	    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	//Enable specified PWM0 output
		ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);
		ROM_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);
	//Select the inversion mode for the selected PWM0 outputs
		ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_2_BIT, false);
		ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_3_BIT, true);

	//Sets the pulse width for the specified PWM2 output
	//25%-75%
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6,
		    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7,
		    			(ROM_SysCtlClockGet() / DEFAULT) / 4);
	//Enable specified PWM0 output
	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);
	ROM_PWMOutputState(PWM0_BASE, PWM_OUT_7_BIT, true);
	//Select the inversion mode for the selected PWM0 outputs
	ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_6_BIT, false);
	ROM_PWMOutputInvert(PWM0_BASE, PWM_OUT_7_BIT, true);


	//Enable PWM generator 0
	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);

	//Enable PWM generator 1
	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);
	//Enable PWM generator 2
	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_3);
}

Thank you.

  • In BLDC Motor control it is normal/customary to derive your commutation signals via signal input from motor equipped Hall Sensors or detection & processing of the BEMF voltages.  Neither of these methods appear w/in your brief code extract.

    It is possible to generate your desired phase relationships minus such sensors - but w/out a proper means of synchronizing your phase drive to your motor - success is unlikely...

    W/in StellarisWare - a detailed BLDC project exists - which illustrates both Hall Sensor & BEMF motor "sync" techniques...  Suspect your effort will benefit from such examination...

  • Further point - outside your specific post - perhaps of value to you/others...

    For test purposes - w/out any BLDC Motor - we earlier devised a, "BLDC Simulator" which employed a basic 8 bit MCU.  This MCU was able to generate simulated, "Hall Signals" at either 60 or 120° spacing, at variable frequencies (as we'd expect from a BLDC motor) and further "detect" the PWM Outputs from a motor controller. Often this proved far faster, easier & safer than attaching to a "real" motor. 

    Creating the phase relationships was eased by the implementation of a variable frequency MCU clock - operating @ 6x (for 60° phase) or 3x (for 120° phase).  The simulated hall signals would appropriately toggle at the proper rate (1/6 the MCU clock for 60°, 1/3 for 120°). 

    The User Guide for the past RDK-BLDC Stellaris project provides a detailed, time-based drawing, showing the exact relationship between these Hall signals.

  • http://www.ti.com/tool/rdk-bldc

    All the document i need is on this link right ?

    I intend to use the sensorless technique to control the bldc.

  • Fear to ever say/use, "all needed." 

    Do look for the User Guide for vendor's BLDC-RDK - much info of value/interest lurks w/in...

    While you "intend" to use BEMF - most always faster/easier to build experience/confidence via Hall sensors - and later move to BEMF.  And - the monitoring of BEMF while under Hall control - should prove extremely useful...

  • i can't seem to find the BLDC project you speak of... is it included in the software package for the tm4c1294? I'm also trying to implement a PWM signal to control 3 phase of BLDC motor, but i am trying to use it in break mode regeneration. essentially i want to make a 3 phase generator using the tm4c1294 launchpad... should i be using a different launchpad?
  • Purely by (luck) did I find this post. If you wish to target me/my group specifically best to via "Conversations/Private Message."

    If you can find this vendor's MCU Software Download page - in the past there existed a "BLDC-RDK" project - which will prove immensely helpful.

    Your MCU is superior to the lesser M3 (RIP) and M4 (ditto) our small firm chose.

    That said - "starting w/that complex scheme" is far outside my preferred, "KISS First - ALWAYS!"

    As I first wrote - simple BLDC motor - standard hall sensors - then migration to BEMF - only after all of that's mastered would I venture as you suggest...

  • Hello cb1,

    The BDLC-RDK is being revived for TM4C12x family. Just thought it would be good to update the same on the forum

    Regards
    Amit
  • Amit Ashara said:
    The BDLC-RDK is being revived for TM4C12x family.

    Of course the "promotion of such" some way/how "escaped" poster & this humble reporter.

    Might you know - even better share - the expected date of this fine, "Revival?"  

    I'll supply cold drinks - rumor has it Blake/you will supply "hot dogs"...   (we understand that "Nathans" has a few remaining - even some (not fully digested)...)

  • Hello cb1

    The last time I put a date (TivaWare release), I ran into a lot of forum heat. Rather let this one mature close to the Release and then Promote

    Regards
    Amit
  • Hi Amit,

    As our firm sells to the US broadcast industry - the "hint" of (maybe) something to (someday) arrive is known as a, "tease."

    We'll keep our "Revival" cold drinks on ice.    (a lot of ice...)

  • Hello cb1

    Read you loud and clear

    Regards
    Amit