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.

CCS/TMS320F28335: eQEP,CCS,F28335

Part Number: TMS320F28335
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

I am using  eQEP Speed and Position measurement example imported from C2000 Ware. I have configured ePWM to produce 13kHZ signal and index of 25HZ so that motor of 1500rpm can be controlled (virtually). It is written in the description of example that it measures low speed with capture unit and high speed by counting QEP input pulses.

The variable 'SPEEDRPM_FR'  stores high speed measurement but it is showing 1430 and then next instant it shows 23.

I want this variable to represent constant speed so thst I can use it in close loop speed control.

How I can do that? Please suggest.

void
POSSPEED_Init(void)
{
    #if (CPU_FRQ_150MHZ)
        EQep1Regs.QUPRD=1500000;  // Unit Timer for 100Hz at 150 MHz SYSCLKOUT
	#endif
    #if (CPU_FRQ_100MHZ)
        EQep1Regs.QUPRD=1000000;  // Unit Timer for 100Hz at 100 MHz SYSCLKOUT
	#endif

	EQep1Regs.QDECCTL.bit.QSRC=00;		// QEP quadrature count mode

	EQep1Regs.QEPCTL.bit.FREE_SOFT=2; //UNIT TIMER STOPS IMMEDIATELY AS EMULATION SUSPENDED
	
    //

    //
    EQep1Regs.QEPCTL.bit.PCRM=00;// PCRM=00 mode - QPOSCNT reset on index event
    
	EQep1Regs.QEPCTL.bit.UTE=1; 		// Unit Timeout Enable
	EQep1Regs.QEPCTL.bit.QCLM=1; 		// Latch on unit time out
	EQep1Regs.QPOSMAX=0x800;
	EQep1Regs.QEPCTL.bit.QPEN=1; 		// QEP enable

	EQep1Regs.QCAPCTL.bit.UPPS=6;   	// 1/64 for unit position
	EQep1Regs.QCAPCTL.bit.CCPS=7;		// 1/128 for CAP clock
	EQep1Regs.QCAPCTL.bit.CEN=1; 		// QEP Capture Enable
}

  • Hi Irshad,

    Can you share your ePWM initialization? Also did you change the below section within your ISR?

        //
        // Every 1000 interrupts(4000 QCLK counts or 1 rev.)
        //
        if (Interrupt_Count==1000)
        {
            EALLOW;
            
            //
            // Pulse Index signal  (1 pulse/rev.)
            //
            GpioDataRegs.GPASET.bit.GPIO4 = 1;
            for (i=0; i<700; i++)
            {
                
            }
            GpioDataRegs.GPACLEAR.bit.GPIO4 = 1;
            Interrupt_Count = 0;                   // Reset count
            EDIS;
        }

    Best,

    Kevin

  • Hi,

    Yeah I have changed Interrupt_Count to 512, since my encoder is of 512 Pulse/Revolution and Channel A and B gives 13000 pulses/sec.

    #define PWM_CLK   13e3
    #define SP        CPU_CLK/(2*PWM_CLK)
    #define TBCTLVAL  0x200E      // up-down count, timebase=SYSCLKOUT
    
    //
    // initEpwm - 
    //
    void
    initEpwm()
    {
       EPwm1Regs.TBSTS.all=0;
        EPwm1Regs.TBPHS.half.TBPHS =0;
        EPwm1Regs.TBCTR=0;
    
       EPwm1Regs.CMPCTL.all=0x50;     // immediate mode for CMPA and CMPB
       EPwm1Regs.CMPA.half.CMPA=SP/2;
       EPwm1Regs.CMPB=0;
    
    
        // CTR=CMPA when inc->EPWM1A=1, when dec->EPWM1A=0
        //
       EPwm1Regs.AQCTLA.all=0x60;
        
       EPwm1Regs.AQCTLB.all=0x09;     // CTR=PRD ->EPWM1B=1, CTR=0 ->EPWM1B=0
       EPwm1Regs.AQSFRC.all=0;
       EPwm1Regs.AQCSFRC.all=0;
    
       EPwm1Regs.TZSEL.all=0;
       EPwm1Regs.TZCTL.all=0;
        EPwm1Regs.TZEINT.all=0;
       EPwm1Regs.TZFLG.all=0;
       EPwm1Regs.TZCLR.all=0;
        EPwm1Regs.TZFRC.all=0;
    //
       EPwm1Regs.ETSEL.all=0x0A;      // Interrupt on PRD
        EPwm1Regs.ETPS.all=1;
       EPwm1Regs.ETFLG.all=0;
       EPwm1Regs.ETCLR.all=0;
        EPwm1Regs.ETFRC.all=0;
    //
        EPwm1Regs.PCCTL.all=0;
    
        EPwm1Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
       EPwm1Regs.TBPRD=SP;
    }

     

  • Hi Irshad,

    Have you made changes to the below config? I believe you'll need to properly configure the below for your simulated motor to see the expected results.

    //
    // Globals
    //
    POSSPEED qep_posspeed=POSSPEED_DEFAULTS;
    
    //
    // Defines for the default initializer for the POSSPEED Object.
    //
    #if (CPU_FRQ_150MHZ)
        #define POSSPEED_DEFAULTS {0x0, 0x0,0x0,0x0,0x0,16776,2,0,0x0,\
            94,0,6000,0,\
            0,0,0,\
            (void (*)(long))POSSPEED_Init,\
            (void (*)(long))POSSPEED_Calc }
    #endif

    Best,

    Kevin

  • Hi Kevin,

      Thanks for your continous support.

    I have already done all those changes.

    For my machine,

    mech_scaler=2048

    Speed Scaler=733

    Pole Pair=2

    Base speed=1500

    So, I have changed 16776 to 2048 , 94 to 733 and 6000 to 1500.

    Please suggest if any other improvements are needed.

    Regards,

    Irshad Karim

    typedef POSSPEED *POSSPEED_handle;
    
    //
    // Defines for the default initializer for the POSSPEED Object.
    //
    #if (CPU_FRQ_150MHZ)
        #define POSSPEED_DEFAULTS {0x0, 0x0,0x0,0x0,0x0,2048,2,0,0x0,\
            733,0,1500,0,\
            0,0,0,\
            (void (*)(long))POSSPEED_Init,\
            (void (*)(long))POSSPEED_Calc }
    #endif

  • Hi Irshad,

    Sorry for the delayed response. Have been preoccupied with other things.

    Have you used the excel doc in the example folder at all? might be worth looking at and plugging your numbers into to check. 'Example_posspeed.xls' located at the below:

    C:\ti\c2000\C2000Ware_3_01_00_00\device_support\f2833x\examples\eqep_pos_speed

    Best,

    Kevin