Jump to content
43oh

RAGHAVRAJAT

Members
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by RAGHAVRAJAT

  1. 
    //###########################################################################
    #include "DSP2833x_Device.h"
    
    // external function prototypes
    extern void InitSysCtrl(void);
    extern void InitCpuTimers(void);
    
    // Prototype statements for functions found within this file.
    void Gpio_select(void);
    void Setup_HS1(void);
    void Setup_HS2(void);
    void Setup_HS3(void);
    void Setup_HS4(void);
    void Setup_HS5(void);
    void Setup_HS6(void);
    
    // Global Variables
    int Hall_1_result, Hall_2_result, Hall_3_result, Hall_State, x=0 , P_State=0;
    
    #define Hall_1 GpioDataRegs.GPADAT.bit.GPIO24
    #define Hall_2 GpioDataRegs.GPADAT.bit.GPIO25
    #define Hall_3 GpioDataRegs.GPADAT.bit.GPIO26
    
    //###########################################################################
    //                      main code
    //###########################################################################
    void main(void)
    {
    
        InitSysCtrl();  // Basic Core Init from DSP2833x_SysCtrl.c
    
        Gpio_select();
    
    
        while(1)
        {
    
            if(Hall_1 ==1)     //eCAP1_Hall1
    
                Hall_1_result = 1;
            else Hall_1_result = 0;
    
            if (Hall_2 == 1)
                                  //eCAP2_Hall2
                Hall_2_result = 1;
            else Hall_2_result = 0;
    
            if (Hall_3 == 1)
                                  //eCAP3_Hall3
                Hall_3_result = 1;
            else Hall_3_result = 0;
    
            Hall_State = (4*Hall_3_result) + (2*Hall_2_result) + (1*Hall_1_result);
    
            if (Hall_State >=1 && Hall_State <=6)
            {
                P_State = Hall_State;
    
    
            switch (Hall_State)
            {
                case 1 :
                {
                    x = 1;
                    Setup_HS1();
                    break;
                }
    
                case 2 :
                {
                    x = 2;
                    Setup_HS2();
                    break;
                }
    
                case 3 :
                {
                    x = 3;
                    Setup_HS3();
                    break;
                }
    
                case 4 :
                {
                    x = 4;
                    Setup_HS4();
                    break;
                }
    
                case 5 :
                {
                    x = 5;
                    Setup_HS5();
                    break;
                }
    
                case 6 :
                {
                    x = 6;
                    Setup_HS6();
                    break;
                }
    
    
            }
    
        }
    
    
                            if (Hall_State == 0 || Hall_State == 7)
                        {
                            EPwm1Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM1A(S1)
                            EPwm1Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM1B(S4)
                            EPwm2Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM2A(S3)
                            EPwm2Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM2B(S6)
                            EPwm3Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM3A(S5)
                            EPwm3Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM3B(S2)
                        }
    
        }        // end of infinite loop
    }      // end of main
    
    void Gpio_select(void)
    {
        EALLOW;
        GpioCtrlRegs.GPAMUX1.all = 0;       // GPIO15 ... GPIO0 = General Puropse I/O
        GpioCtrlRegs.GPAMUX2.all = 0;       // GPIO31 ... GPIO16 = General Purpose I/O
        GpioCtrlRegs.GPBMUX1.all = 0;       // GPIO47 ... GPIO32 = General Purpose I/O
        GpioCtrlRegs.GPBMUX2.all = 0;       // GPIO63 ... GPIO48 = General Purpose I/O
        GpioCtrlRegs.GPCMUX1.all = 0;       // GPIO79 ... GPIO64 = General Purpose I/O
        GpioCtrlRegs.GPCMUX2.all = 0;       // GPIO87 ... GPIO80 = General Purpose I/O
    
        GpioCtrlRegs.GPAMUX1.bit.GPIO0= 1;  //ePWM1A active
        GpioCtrlRegs.GPAMUX1.bit.GPIO1= 1;  //ePWM1B active
        GpioCtrlRegs.GPAMUX1.bit.GPIO2= 1;  //ePWM2A active
        GpioCtrlRegs.GPAMUX1.bit.GPIO3= 1;  //ePWM2B active
        GpioCtrlRegs.GPAMUX1.bit.GPIO4= 1;  //ePWM3A active
        GpioCtrlRegs.GPAMUX1.bit.GPIO5= 1;  //ePWM3B active
    
        GpioCtrlRegs.GPADIR.all = 0;
        GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO24 = 0;  // gpio pin as input
        GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;  //gpio pins as input
        GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO26 = 0;  //gpio pins as input
    
        GpioCtrlRegs.GPBDIR.all = 0;
        GpioCtrlRegs.GPCDIR.all = 0;
        GpioCtrlRegs.GPAPUD.all = 0;
        GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0;
        GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0;
        GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0;
        EDIS;
    }
    
    void Setup_HS1(void)
    {
        EPwm1Regs.TZCTL.all =  0;           //ePWM on S1 (ePWM1A)
        EPwm1Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm1Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm1Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm1Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD/2;  //value of CMPA   (Duty Ratio)
        EPwm3Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM3B(S2)
        EPwm3Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM3A(S5)
        EPwm2Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM2B(S6)
        EPwm2Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM2A(S3)
        EPwm1Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM1B(S4)
    }
    
    void Setup_HS2(void)
    {
        EPwm3Regs.TZCTL.all =  0;           //ePWM on S5 (ePWM3A)
        EPwm3Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm3Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm3Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm3Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm3Regs.CMPA.half.CMPA = EPwm3Regs.TBPRD/2;  //value of CMPA   (Duty Ratio)
        EPwm2Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM2B(S6)
        EPwm1Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM1A(S1)
        EPwm3Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM3B(S2)
        EPwm2Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM2A(S3)
        EPwm1Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM1B(S4)
    }
    
    
    
    void Setup_HS3(void)
    {
        EPwm1Regs.TZCTL.all =  0;           //ePWM on S1 (ePWM1A)
        EPwm1Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm1Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm1Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm1Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD/2;  //value of CMPA   (Duty Ratio)
        EPwm2Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM2B(S6)
        EPwm3Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM3A(S5)
        EPwm3Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM3B(S2)
        EPwm2Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM2A(S3)
        EPwm1Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM1B(S4)
    }
    
    void Setup_HS4(void)
    {
        EPwm2Regs.TZCTL.all =  0;            //ePWM on S3 (ePWM2A)
        EPwm2Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm2Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm2Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm2Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm2Regs.CMPA.half.CMPA = EPwm2Regs.TBPRD/2;  //value of CMPA  (Duty Ratio)
        EPwm1Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM1B(S4)
        EPwm1Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM1A(S1)
        EPwm2Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM2B(S2)
        EPwm3Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM3A(S5)
        EPwm3Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM3B(S2)
    }
    
    void Setup_HS5(void)
    {
    
        EPwm2Regs.TZCTL.all =  0;           //ePWM on S3 (ePWM2A)
        EPwm2Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm2Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm2Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm2Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm2Regs.CMPA.half.CMPA = EPwm2Regs.TBPRD/2;  //value of CMPA  (Duty Ratio)
        EPwm3Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM3B(S2)
        EPwm1Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM1A(S1)
        EPwm1Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM1B(S4)
        EPwm3Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM3A(S5)
        EPwm2Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM2B(S6)
    
    
    }
    
    void Setup_HS6(void)
    {
        EPwm3Regs.TZCTL.all =  0;            //ePWM on S5 (ePWM3A)
        EPwm3Regs.TBCTL.bit.CLKDIV =  0;    // CLKDIV = 1
        EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1;  // HSPCLKDIV = 2
        EPwm3Regs.TBCTL.bit.CTRMODE = 2;    // up - down mode
        EPwm3Regs.AQCTLA.all = 0x0060;      // SET=CMPA CLEAR=CAD
        EPwm3Regs.TBPRD = 7500;             // 5KHz - PWM signal
        EPwm3Regs.CMPA.half.CMPA = EPwm3Regs.TBPRD/2;  //value of CMPA (Duty Ratio)
        EPwm1Regs.AQCSFRC.bit.CSFB = 2;     //force continuous high on output of ePWM1B(S4)
        EPwm1Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM1A(S1)
        EPwm2Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM2B(S2)
        EPwm2Regs.AQCSFRC.bit.CSFA = 1;     //force continuous low on output of ePWM2A(S3)
        EPwm3Regs.AQCSFRC.bit.CSFB = 1;     //force continuous low on output of ePWM3B(S2)
    }
    
    
    //===========================================================================
    // End of SourceCode.
    //===========================================================================

    Hi,

    I want to run a BLDC motor with the help of my DSP (TMS320F28335). While it is able to detect change in Hall State ( I confirmed it by rotating rotor with hand), as soon as Hall State is changing, corresponding gate driver signals are not developed. However if  I stop debugging in the IDE (CCS) and debug it again then corresponding correct pulses are produced. I am not getting how to develop gate driver signals continuously according to change in hall state. I am using following code-

     

    code.txt

×
×
  • Create New...