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.

TMS320F28379D: BLDC motor

Part Number: TMS320F28379D
Other Parts Discussed in Thread: DRV8305, CONTROLSUITE,

Hello,

I am working on BLDC hall sensor based motor. when i am trying to rotate the motor with 30% to 65% dutycycle it rotate fine. but i want to improve this duty cycle range like 10% to 90%(high speed to low speed) .

My question is: Does delay make any difference or affect the motor? in my code i am using 1ms delay after reading hall sensor. i am using DRV8305 and code composer studio. 

                      Also when i put initEPWM() function + delay 1 msec in for loop that time only it worked fine.

main()

{

for(;;)

{

initpwm();

if (hall sensorA=0 && hall sensorB=1 && hall sensorC=0)

{

pwm1&PWM4 generate;

2,3,5,6  PWM disable;

}

else if (hall sensorA=0 && hall sensorB=1 && hall sensorC=0)........

{

....

}

//similarly for other 5 commutation

delay_us(1000);

}

}

Other parameter is: PWM frequency 1khz

                              Deadnad 490 nsec

AQCTL  CAU =set

AQCTL CAD =clear

Can anybody suggest me where i am wrong?

  • The delay time should be related to the hall sensor input signals. In most cases, the motor should make commutation immediately when a new hall pattern signal is sampled.

    You may take a look at the link below and find an example project in the controlSUITE for hall sensored based BLDC control.

    [FAQ] Trapezoidal Control of BLDC Motors Using Hall Effect Sensors on C2000 Controller

    https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/864875

    ControlSUITE

    C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v2.1\HVBLDC_Sensored

    https://www.ti.com/tool/controlsuite

  • Thank you for your Reply.

    I implemented hallGPio.h according to my board  and it solved my de bouncing problem. But not able to achieve more dutycycle range.

    in that library of BLDCPWM macro, they use Dutyfunction and IQ to set dutycycle. When i tried to implement this way, motor is not rotating at all!!!

    #define BLDCPWM_MACRO(v)\
        /* Convert "Period" (Q15) modulation function to Q0 */\
        Tmp = (int32)v.PeriodMax*(int32)v.MfuncPeriod;  /* Q15 = Q0xQ15 */\
        Period = (int16)(Tmp>>15);                      /* Q15 -> Q0 (Period) */\
        \
        /* Check PwmActive setting */\
        if (v.PwmActive==1) /* PWM active high */\
        {\
            GPR0_BLDC_PWM = 0x7FFF - v.DutyFunc; \
            CMPB_SMPL_POINT = 0x7FFF - (v.DutyFunc >> 1); /* Sample in center of PWM pulse using CMPB */\
        }\
        else if (v.PwmActive==0) /* PWM active low */\
        {\
            GPR0_BLDC_PWM = v.DutyFunc;\
            CMPB_SMPL_POINT = v.DutyFunc >> 1; /* Sample in center of PWM pulse using CMPB */\
        }\
        \
        /* Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0 */\
        Tmp = (int32)Period*(int32)GPR0_BLDC_PWM; /* Q15 = Q0xQ15 */\
        Tmp2 = (int32)Period*(int32)CMPB_SMPL_POINT;  /* Q15 = Q0xQ15 */\
        EPwm1Regs.CMPB = (int16)(Tmp2>>15); /* Sample in center of PWM pulse using CMPB */\
        \
        /* State s1: current flows to motor windings from phase A->B, de-energized phase = C */\
        if (v.CmtnPointer==0)\
        {\
            EPwm1Regs.AQCSFRC.bit.CSFB = 0;         /* Forcing disabled on output B of EPWM1 */\
            EPwm1Regs.AQCTLB.bit.CAU = 2;           /* Set high when CTR = CMPA on UP-count */\
            EPwm1Regs.AQCTLB.bit.ZRO = 1;           /* Set low when CTR = Zero */\
            EPwm1Regs.CMPA.half.CMPA = (int16)(Tmp>>15);  /* PWM signal on output B of EPWM1 (Q15 -> Q0) */\
            EPwm1Regs.AQCSFRC.bit.CSFA = 2;         /* Forcing a continuous High on output A of EPWM1 */\
            \
            EPwm2Regs.AQCSFRC.bit.CSFA = 1;         /* Forcing a continuous Low on output A of EPWM2 */\
            EPwm2Regs.AQCSFRC.bit.CSFB = 2;         /* Forcing a continuous High on output B of EPWM2 */\
            \
            EPwm3Regs.AQCSFRC.bit.CSFA = 1;         /* Forcing a continuous Low on output A of EPWM3 */\
            EPwm3Regs.AQCSFRC.bit.CSFB = 1;         /* Forcing a continuous Low on output B of EPWM3 */\
        }\      

    can you help me to understand how did they change speed by changing dutycycle.      

                                           

  • Please follow the application note to connect the hall sensor and motor wires in a right sequence. Running the motor in build level 2,3 to verify if the hall sensor signals are detected correctly.

  • Thank you for quick reply. I checked connection and verified it, no issue with that.

    1.In that motor driver code state machine has been used. for tms320f28379D not able to implement those thing. should i change cputimer freq and delay time. what should be the value for that? my hall sensor timing to stabilize is around 8 microsec.

    2.When i tried to rotate the motor with less than 65% duty cycle voltage is dropping from 24v to 8v. what could be reason for that?

  • Hi Vasanth,

    Other parameter is: PWM frequency 1khz

    Drops from 24v down to 8v, might the inverter NFETs be switching current in the unsafe area <65% duty? Maybe try 12-20KHz PWM frequency see if it helps.

  • What example project are you using as the reference? Do you change the configuration codes in the project for tms320f28379D? Which build level are you working on?

  • yes, i tried it. but with other frequency motor is not running at all!! but changed current limit from 1A to 1.5 A makes motor to rotate smoothly.

  • Thank you for your reply.

    I am using following  reference code:

    C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v2.1\HVBLDC_Sensored

    I started with level 2.  what frequency and Dutycycle they are using not able to understand.

  • but with other frequency motor is not running at all!!

    PWM frequency 1KHz modulation is typically unsafe but 1.5A it may not have an immediate noticed issue. Perhaps very minimal duty cycle at 1KHz?

  • As GI mentioned, the frequency is too low  for running the motor with hall sensor, you may try to use a PWM frequency with 10~20kHz.

    You may try to run the level 1 and level 2 to check if the PWM output and the ADC sampling are correct, to verify the codes you changed are right for this kits.

    Don't try to add the dc bus voltage and run the motor before you verify the PWM outputs on the hardware kit.

  • I changed my pwm frequency 1khz to 12khz, motor running with very slow speed even at 50% dutycycle!!

    parameter: DRV8305

    Here is the code:

    //
    // Included Files
    //
    #include "F28x_Project.h"
    //#include "Example_posspeed.h"
    
    //#define u 1;
    //#define v 0;
    
    __interrupt void cpu_timer0_isr(void);
    
    //
    // Globals
    //
    
    #define EPWM1_MAX_DB   0x01
    #define EPWM2_MAX_DB   0x01
    #define EPWM3_MAX_DB   0x01
    
    #define val  600
    #define ISRFRQ  100
    #define ISRTIME  100
    
    //
    // Globals
    //
    
    //POSSPEED qep_posspeed = POSSPEED_DEFAULTS;
    Uint16 InterruptCount = 0;
    //Uint16 u;
    int cnttt;
    int pin;
    unsigned int pos16bval;
    unsigned int temp1;
    float angle;
    float var;
    int mechthe;
    volatile long i;
    Uint16 A = 0;
    //unsigned int x1;
    //unsigned int x2;
    float x1;
    float x2;
    float diff;
    float speed;
    float speed_1;
    //unsigned int diff;
    //unsigned int speed;
    Uint16 GPIO_54;
    Uint16 GPIO_55;
    Uint16 GPIO_57;
    
    Uint16 CmtnTrigHall = 0; // Output: Commutation trigger for Mod6cnt input (0 or 0x7FFF)
    Uint16 CapCounter = 0; // Variable: Running count of detected edges on ECAP1,2,3
    Uint16 DebounceCount = 0;   // Variable: Counter/debounce delay current value
    Uint16 DebounceAmount = 10; // Parameter: Counter delay amount to validate/debounce GPIO readings
    Uint16 HallGpio = 0;        // Variable: Most recent logic level on ECAP/GPIO
    Uint16 HallGpioBuffer = 0; // Variable: Buffer of last logic level on ECAP/GPIO while being debounced
    Uint16 HallGpioAccepted = 0; // Variable: Debounced logic level on ECAP/GPIO
    Uint16 EdgeDebounced = 0; // Variable: Trigger from Debounce function to Hall_Drv, if = 0x7FFF edge is debounced
    Uint16 HallMap[6] = { 0, 0, 0, 0, 0, 0 }; // Variable: ECAP/GPIO logic levels for HallMapPointer = 0-5
    Uint16 CapFlag = 0; // Variable: ECAP flags, indicating which ECAP detected the edge
    Uint16 StallCount = 0xFFFF; // Variable: If motor stalls, this counter overflow triggers
    //           commutation to start rotation. Rotation is defined as
    //           an edge detection of a hall signal.
    Uint16 HallMapPointer = 0; // Input/Output (see note below): During hall map creation, this variable points to the
    //            current commutation state.  After map creation, it
    //            points to the next commutation state.
    int16 Revolutions = -10; // Parameter: Running counter, with a revolution defined as 1-cycle
    //            of the 6 hall states
    Uint16 CmtnPointer = 0;
    //
    Uint16 Hall_SeqArray[50];
    // Function Prototypes
    //
    //void initEpwm();
    //__interrupt void prdTick(void);
    
    void InitEPwmExample();
    
    void HALL3_CREATE_MAP( void);
    void HALL3_NEXT_STATE_MACRO();
    void HALL3_DETERMINE_STATE_MACRO();
    void HALL3_READ_MACRO();
    void HALL3_DEBOUNCE_MACRO();
    
    void comm(void);
    //
    // Main
    //
    void main(void)
    {
       // static int idx = 0;
    
    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xD_SysCtrl.c file.
    //
        InitSysCtrl();
    
    //
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xD_Gpio.c file and
    // illustrates how to set the GPIO to its default state.
    //
    
        InitGpio();
    
        GPIO_SetupPinMux(34, GPIO_MUX_CPU1, 1);
        GPIO_SetupPinOptions(34, GPIO_OUTPUT, GPIO_PUSHPULL);
        GPIO_SetupPinMux(54, GPIO_MUX_CPU1, 5);
        GPIO_SetupPinOptions(54, GPIO_INPUT, GPIO_PUSHPULL);
    
        GPIO_SetupPinMux(55, GPIO_MUX_CPU1, 5);
        GPIO_SetupPinOptions(55, GPIO_INPUT, GPIO_PUSHPULL);
    
        GPIO_SetupPinMux(57, GPIO_MUX_CPU1, 5);
        GPIO_SetupPinOptions(57, GPIO_INPUT, GPIO_PUSHPULL);
    
        EALLOW;
        GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
        EDIS;
    
    
    // For this case only init GPIO for eQEP1 and ePWM1
    // This function is found in F2837xD_EQep.c
    //
    
        CpuSysRegs.PCLKCR2.bit.EPWM1 = 1;
        CpuSysRegs.PCLKCR2.bit.EPWM2 = 1;
        CpuSysRegs.PCLKCR2.bit.EPWM3 = 1;
    
        InitEQep1Gpio();
        InitEPwm1Gpio();
        InitEPwm2Gpio();
        InitEPwm3Gpio();
    //
    // Step 3. Clear all __interrupts and initialize PIE vector table:
    // Disable CPU __interrupts
    //
        DINT;
    
    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE __interrupts disabled and flags
    // are cleared.
    // This function is found in the F2837xD_PieCtrl.c file.
    //
        InitPieCtrl();
    
    //
    // Disable CPU __interrupts and clear all CPU __interrupt flags:
    //
        IER = 0x0000;
        IFR = 0x0000;
    
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the __interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2837xD_DefaultIsr.c.
    // This function is found in F2837xD_PieVect.c.
    //
        InitPieVectTable();
    
    //
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    //
    
        EALLOW;  // This is needed to write to EALLOW protected registers
        PieVectTable.TIMER0_INT = &cpu_timer0_isr;
    
        //  PieVectTable.TIMER1_INT = &cpu_timer1_isr;
        //  PieVectTable.TIMER2_INT = &cpu_timer2_isr;
        EDIS;
    
        InitCpuTimers();
    
        ConfigCpuTimer(&CpuTimer0, ISRFRQ, ISRTIME); // 50000 =50ms , 100000=100ms, 10000=10ms
    
        CpuTimer0Regs.TCR.all = 0x4001;
        //  Step 5. User specific code, enable __interrupts:
        // Enable CPU INT1 which is connected to CPU-Timer 0:
        //
        //IER |= M_INT3;
        IER |= M_INT1;
    
        //
        // Enable TINT0 in the PIE: Group 3 __interrupt 1
        //
        // PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
        PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    //
    // Enable global Interrupts and higher priority real-time debug events:
    //
        EINT;
        // Enable Global __interrupt INTM
        ERTM;
        // Enable Global realtime __interrupt DBGM
    
        // qep_posspeed.init(&qep_posspeed);
        //POSSPEED_Init();
       // InitECapture();
    
        DebounceAmount = 0;
        Revolutions = -3;
        HALL3_DETERMINE_STATE_MACRO();
    
        HallGpioBuffer = HallGpio; /* Init with current ECAP/GPIO logic levels*/
        HallGpioAccepted = HallGpio; /* Init with current ECAP/GPIO logic levels*/
        // GpioDataRegs.GPADAT.bit.GPIO0=u;
        EALLOW;
        CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
        EDIS;
    
        InitEPwmExample();
    
        EALLOW;
        CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
        EDIS;
        for (;;)
        {
    
    
        }
    
    }
    
    __interrupt void cpu_timer0_isr(void)
    {
        GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
    
        HALL3_READ_MACRO();
    
        if (HallGpioAccepted == 5)
    
        {
            CmtnPointer = 0;
        }
    
        else if (HallGpioAccepted == 1)
        {
            CmtnPointer = 1;
        }
    
        else if (HallGpioAccepted == 3)
        {
            CmtnPointer = 2;
        }
    
        else if (HallGpioAccepted == 2)
        {
            CmtnPointer = 3;
        }
    
        else if (HallGpioAccepted == 6)
        {
            CmtnPointer = 4;
        }
    
        else if (HallGpioAccepted == 4)
        {
            CmtnPointer = 5;
        }
        comm();
    
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    
    }
    
    
    // InitEPwm1Example - Initialize EPWM1 configuration
    //
    void InitEPwmExample()
    {
        EPwm1Regs.TBPRD = 1200;                        // Set timer period
        EPwm2Regs.TBPRD = 1200;                        // Set timer period
        EPwm3Regs.TBPRD = 1200;                        // Set timer period
    
        EPwm1Regs.TBPHS.bit.TBPHS = 0x0000;            // Phase is 0
        EPwm2Regs.TBPHS.bit.TBPHS = 0x0000;            // Phase is 0
        EPwm3Regs.TBPHS.bit.TBPHS = 0x0000;            // Phase is 0
    
        EPwm1Regs.TBCTR = 0x0000;                      // Clear counter
        EPwm2Regs.TBCTR = 0x0000;                      // Clear counter
        EPwm3Regs.TBCTR = 0x0000;                      // Clear counter
    
        //
        // Setup TBCLK
        //
        EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
        EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;       // Clock ratio to SYSCLKOUT
        EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV2;          // Slow so we can observe on
        EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
        EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
        EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;       // Clock ratio to SYSCLKOUT
        EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV2;          // Slow so we can observe on
        EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
        EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
        EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;       // Clock ratio to SYSCLKOUT
        EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV2;          // Slow so we can observe on
                                                       // the scope
    
        EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;    // Load registers every ZERO
        EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;
        EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
        EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
        EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;    // Load registers every ZERO
        EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;
        EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
        EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
        EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;    // Load registers every ZERO
        EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;
        EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
        EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
        //    //
        // Setup compare
        //
        EPwm1Regs.CMPA.bit.CMPA = val;
        EPwm1Regs.CMPB.bit.CMPB = val;
        EPwm2Regs.CMPA.bit.CMPA = val;
        EPwm2Regs.CMPB.bit.CMPB = val;
        EPwm3Regs.CMPA.bit.CMPA = val;
        EPwm3Regs.CMPB.bit.CMPB = val;
    }
    
    void comm()
    {
        static Uint16 CmtnPointer_Prev = 0x0;
        static  int idx=0;
    //    Uint16 HallGpioBitA, HallGpioBitB, HallGpioBitC;
    //
    //    HallGpioBitA = GPIO_ReadPin(54);
    //    HallGpioBitB = GPIO_ReadPin(55);
    //    HallGpioBitC = GPIO_ReadPin(57);
    //
    //    HallGpio = (HallGpioBitA << 2) + (HallGpioBitB << 1) + HallGpioBitC;
    
        if(CmtnPointer != CmtnPointer_Prev)
        {
            Hall_SeqArray[idx] = HallGpioAccepted;
    
            if (idx <= 49)
            {
                idx = idx + 1;
            }
            else
            {
                idx = 0;
            }
    
        if (CmtnPointer == 0)
        {
            /*    InitEPwm1Example();         //1&6
             // InitEPwm2Example();
             InitEPwm3Example();*/
    
            EPwm1Regs.AQCSFRC.bit.CSFB = 1;         //2
            EPwm3Regs.AQCSFRC.bit.CSFA = 1;         //5
    
            EPwm2Regs.AQCSFRC.bit.CSFB = 1;         //4
            EPwm2Regs.AQCSFRC.bit.CSFA = 1;         //3
    
            EPwm1Regs.AQCSFRC.bit.CSFA = 0;         //1
            EPwm3Regs.AQCSFRC.bit.CSFB = 0;         //6
    
    
            EPwm1Regs.AQCTLA.bit.CAU = 2; /* Set high when CTR = CMPA on UP-count             */
            EPwm1Regs.AQCTLA.bit.ZRO = 1;
            EPwm3Regs.AQCTLB.bit.CBU = 2; /* Set high when CTR = CMPA on UP-count             */
            EPwm3Regs.AQCTLB.bit.ZRO = 1;
    
        }
    
       if (CmtnPointer == 1)
        {
            /*  // InitEPwm1Example();         //1&4
             InitEPwm2Example();
             InitEPwm3Example();*/
    
           EPwm2Regs.AQCSFRC.bit.CSFB = 1;       //4
           EPwm3Regs.AQCSFRC.bit.CSFA = 1;       //5
    
           EPwm1Regs.AQCSFRC.bit.CSFB = 1;       //2
           EPwm1Regs.AQCSFRC.bit.CSFA = 1;       //1
    
           EPwm3Regs.AQCSFRC.bit.CSFB = 0;       //6
           EPwm2Regs.AQCSFRC.bit.CSFA = 0;       //3
    
           EPwm2Regs.AQCTLA.bit.CAU = 2;         //3
           EPwm2Regs.AQCTLA.bit.ZRO = 1;
           EPwm3Regs.AQCTLB.bit.CBU = 2;         //6
           EPwm3Regs.AQCTLB.bit.ZRO = 1;
        }
    
       if (CmtnPointer == 2)
        {
           EPwm2Regs.AQCSFRC.bit.CSFA = 1;       //3
           EPwm3Regs.AQCSFRC.bit.CSFB = 1;       //6
    
           EPwm1Regs.AQCSFRC.bit.CSFB = 1;       //2
           EPwm1Regs.AQCSFRC.bit.CSFA = 1;       //1
    
           EPwm3Regs.AQCSFRC.bit.CSFA = 0;       //5
           EPwm2Regs.AQCSFRC.bit.CSFB = 0;       //4
    
           EPwm2Regs.AQCTLB.bit.CBU = 2;         //4
           EPwm2Regs.AQCTLB.bit.ZRO = 1;
           EPwm3Regs.AQCTLA.bit.CAU = 2;         //5
           EPwm3Regs.AQCTLA.bit.ZRO = 1;
        }
    
    if (CmtnPointer == 3)
        {
        EPwm1Regs.AQCSFRC.bit.CSFB = 1;         //2
        EPwm2Regs.AQCSFRC.bit.CSFA = 1;         //3
    
        EPwm3Regs.AQCSFRC.bit.CSFB = 1;         //6
        EPwm3Regs.AQCSFRC.bit.CSFA = 1;         //5
    
        EPwm1Regs.AQCSFRC.bit.CSFA = 0;         //1
        EPwm2Regs.AQCSFRC.bit.CSFB = 0;         //4
    
        EPwm1Regs.AQCTLA.bit.CAU = 2; /* Set high when CTR = CMPA on UP-count             */\
        EPwm1Regs.AQCTLA.bit.ZRO = 1;
        EPwm2Regs.AQCTLB.bit.CBU = 2; /* Set high when CTR = CMPA on UP-count             */\
        EPwm2Regs.AQCTLB.bit.ZRO = 1;
        }
    
    
    
     if (CmtnPointer == 4)
        {
         EPwm1Regs.AQCSFRC.bit.CSFA = 1;      //1
         EPwm2Regs.AQCSFRC.bit.CSFB = 1;      //4
    
         EPwm3Regs.AQCSFRC.bit.CSFB = 1;      //5
         EPwm3Regs.AQCSFRC.bit.CSFA = 1;      //6
    
         EPwm1Regs.AQCSFRC.bit.CSFB = 0;      //2
         EPwm2Regs.AQCSFRC.bit.CSFA = 0;      //3
    
         EPwm2Regs.AQCTLA.bit.CAU = 2;         //3
         EPwm2Regs.AQCTLA.bit.ZRO = 1;
         EPwm1Regs.AQCTLB.bit.CBU = 2;         //2
         EPwm1Regs.AQCTLB.bit.ZRO = 1;
        }
    
    
    
     if (CmtnPointer == 5)
        {
         EPwm1Regs.AQCSFRC.bit.CSFA = 1;         //1
         EPwm3Regs.AQCSFRC.bit.CSFB = 1;         //6
    
         EPwm2Regs.AQCSFRC.bit.CSFB = 1;         //4
         EPwm2Regs.AQCSFRC.bit.CSFA = 1;         //3
    
         EPwm1Regs.AQCSFRC.bit.CSFB = 0;         //2
         EPwm3Regs.AQCSFRC.bit.CSFA = 0;         //5
    
         EPwm3Regs.AQCTLA.bit.CAU = 2;         //5
         EPwm3Regs.AQCTLA.bit.ZRO = 1;
         EPwm1Regs.AQCTLB.bit.CBU = 2;         //2
         EPwm1Regs.AQCTLB.bit.ZRO = 1;
    
        }
        }
    
        CmtnPointer_Prev = CmtnPointer;
    
    }
    
    void HALL3_DETERMINE_STATE_MACRO()
    {
        //Uint32 temp;
        Uint16 HallGpioBitA, HallGpioBitB, HallGpioBitC;
    
        HallGpioBitA = GPIO_ReadPin(54);
        HallGpioBitB = GPIO_ReadPin(55);
        HallGpioBitC = GPIO_ReadPin(57);
    
        HallGpio = (HallGpioBitA << 2) + (HallGpioBitB << 1) + HallGpioBitC;
    
    }
    void HALL3_READ_MACRO()
    {
        CmtnTrigHall = 0; /* Reset trigger, it only handshakes with calling program.*/
        if (EdgeDebounced == 0) /* Debounce current position. */
        {
            HALL3_DEBOUNCE_MACRO();
            CmtnTrigHall = EdgeDebounced; /* Set Commutation trigger here*/
        }
        else
        { /* If current position is debounced, find match in table */
            HALL3_NEXT_STATE_MACRO(); /* and return pointer to current state.  Ptr to be incremented*/
        } /* by MOD6CNT after RET.*/
    //
        EdgeDebounced = 0; /* Reset trigger*/
    }
    
    void HALL3_DEBOUNCE_MACRO()
    /* read HallGpio*/
    {
        HALL3_DETERMINE_STATE_MACRO();
    
        if (HallGpio == HallGpioAccepted) /* GPIO_UNCHANGED: Current GPIO reading == debounced ..*/
        /*..GPIO reading, no change in state (no edge yet)  */
        {
            if (Revolutions <= 0) /* Only create hall map during initial Revolutions*/
            {
                HALL3_CREATE_MAP( );
            }
            StallCount -= 1; /* Decrement stall counter*/
            if (StallCount == 0)
            {
                EdgeDebounced = 0x7FFF; /* 0x7FFF If motor has stalled, then user trigger to commutate*/\
    
                StallCount = 0xFFFF; /* Reset counter to starting value*/
            }
    
            DebounceCount = 0;
        }
        else /* GPIO_CHANGED: Motor might have moved to a new position.*/
        {
            if (HallGpio == HallGpioBuffer) /* Current GPIO reading == previous GPIO reading?*/
            {
                if (DebounceCount >= DebounceAmount) /* If equal, is current GPIO reading debounced?*/
                {
                    HallGpioAccepted = HallGpioBuffer; /* Current GPIO reading is now debounced*/
                    EdgeDebounced = 0x7FFF; /*Edge/position debounced, trigger commutation*/\
    
                    StallCount = 0xFFFF; /* On new edge, reset stall counter*/
                    CapCounter += 1; /* Increment running edge detection counter*/
    
                    DebounceCount = 0; /* Reset debounce counter*/
    
                    if (HallMapPointer == 0)
                        Revolutions += 1; /* Increment on every rev (HallMapPointer = 0)*/
                }
                else
                    /* DEBOUNCE_MORE*/
                    DebounceCount += 1; /* Increment debounce counter*/
            }
            else /* NEW_READING*/
            {
                HallGpioBuffer = HallGpio; /* Save new reading and reset debounce counter*/
                DebounceCount = 0;
            }
        }
    }
    
    void HALL3_NEXT_STATE_MACRO()
    {
    
        if (Revolutions > 0) /* Only run function after map has been created.*/
        {
            int16 i, HallPointer;
            for (i = 0; i <= 5; i++) /* Search for a match of current debounced GPIO position*/
            { /* and the table entries.*/
                if (HallMap[i] == HallGpioAccepted) /* Match_Found*/
                {
                    HallPointer = i;
                }
            }
    
            HallMapPointer = HallPointer; /* On match, save pointer position. Pointer will be incremented */
        } /* by 1 since MOD6CNT will receive a positive trigger*/
    }
    void  HALL3_CREATE_MAP(void)
    {
    
        HallMap[HallMapPointer] = HallGpioAccepted; /* Save debounced GPIO to table.*/
    //return HallGpioAccepted ;
    }
    
    

  • Check if the hall sensor and motor wires connection orders are correct, and the dc bus voltage is enough for your motor.

  • Just wanted to check in and see if there is any update from your side, I haven’t heard from you for a week, so I’m assuming you were able to resolve your issue. Please let me know if you have any questions. We would like to close this thread if no any further questions. Thanks.

  • No,  problem not resolved. I checked  connection. no issue with that. Should i try SPI interfacing of DRV8305 with lunchpad? does it solve my problem?

  • As mentioned above, please run the project in build level 1 and 2 first to verify the PWM output and ADC sensing signals, and then run the motor with open loop to verify the hall sensors and commutation as the described in the application note for this example.

    Yes, you must configure the DRV8305 control registers if you want to run the motor with current closed-loop using the current feedback signals.

  • okay i'll try that way again. Thank you for your response.

  • Let's know if you have any update and further questions. Let's close this thread first. Thanks!