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/LAUNCHXL-F28377S: CS/LAUNCHXL-F28377S

Part Number: LAUNCHXL-F28377S
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Hi,

we are trying to run the code with qep model . However we are facing the issues of #10010 and #10234-D.  We seem to be unable to figure out where we are going wrong. We would be really obliged if someone could help us out with solving the issue.

The codes and the build console are enlisted below:

Build Console:

**** Build of configuration Debug for project PWM test ****

"C:\\ti\\ccsv7\\utils\\bin\\gmake" -k -j 2 all -O 
'Building file: ../PTC_test_twolevel.c'
'Invoking: C2000 Compiler'
"C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.1.LTS/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --fp_mode=relaxed --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.1.LTS/include" --include_path="C:/ti/controlSUITE/device_support/F2837xS/v190/F2837xS_common/include" --include_path="C:/ti/controlSUITE/device_support/F2837xS/v190/F2837xS_common/source" --include_path="C:/ti/controlSUITE/device_support/F2837xS/v190/F2837xS_headers/include" --include_path="C:/ti/controlSUITE/device_support/F2837xS/v190/F2837xS_headers/source" --advice:performance=all -g --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="PTC_test_twolevel.d"  "../PTC_test_twolevel.c"
"../PTC_test_twolevel.c", line 279: warning #179-D: variable "i" was declared but never referenced
"../PTC_test_twolevel.c", line 593: warning #179-D: variable "i_pred_alpha" was declared but never referenced
"../PTC_test_twolevel.c", line 593: warning #179-D: variable "i_pred_beta" was declared but never referenced
"../PTC_test_twolevel.c", line 594: warning #179-D: variable "T_pred" was declared but never referenced
"../PTC_test_twolevel.c", line 594: warning #179-D: variable "psi_pred_alpha_s" was declared but never referenced
"../PTC_test_twolevel.c", line 594: warning #179-D: variable "psi_pred_beta_s" was declared but never referenced
"../PTC_test_twolevel.c", line 594: warning #179-D: variable "psi_pred" was declared but never referenced
"../PTC_test_twolevel.c", line 595: warning #179-D: variable "k" was declared but never referenced
'Finished building: ../PTC_test_twolevel.c'
' '
'Building target: PWM test.out'
'Invoking: C2000 Linker'
"C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.1.LTS/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --fp_mode=relaxed --advice:performance=all -g --diag_warning=225 --diag_wrap=off --display_error_number -z -m"PWM test.map" --stack_size=0x200 --warn_sections -i"C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.1.LTS/lib" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.1.LTS/include" --reread_libs --diag_wrap=off --display_error_number --xml_link_info="PWM test_linkInfo.xml" --rom_model -o "PWM test.out" "./DCL_PI.obj" "./Example_posspeed.obj" "./F2837xS_Adc.obj" "./F2837xS_CodeStartBranch.obj" "./F2837xS_CpuTimers.obj" "./F2837xS_DefaultISR.obj" "./F2837xS_EPwm.obj" "./F2837xS_GlobalVariableDefs.obj" "./F2837xS_Gpio.obj" "./F2837xS_PieCtrl.obj" "./F2837xS_PieVect.obj" "./F2837xS_SysCtrl.obj" "./F2837xS_usDelay.obj" "./PTC_test_twolevel.obj" "../2837xS_Generic_RAM_lnk.cmd" "../F2837xS_Headers_nonBIOS.cmd"  -llibc.a 
<Linking>
warning #10247-D: creating output section "dclfuncs" without a SECTIONS specification

 undefined first referenced      
  symbol       in file           
 --------- ----------------      
 __IQ24div ./Example_posspeed.obj

error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking; "PWM test.out" not built

>> Compilation failure
makefile:155: recipe for target 'PWM test.out' failed
gmake[1]: *** [PWM test.out] Error 1
makefile:151: recipe for target 'all' failed
gmake: *** [all] Error 2

**** Build Finished ****

the main code is:

/*
 * PTC_test_twolevel.c
 *
 *  Created on: Apr 12, 2018
 *      Author: abedya
 */

#include "common.h"   // Device Headerfile and Examples Include File
#include "Example_posspeed.h"


//Uint16 Interrupt_Count = 0;

#define _LAUNCHXL_F28377S

// macros needed for v/f code
#define pi 3.1415927
#define vbyflimit 0.6
#define vbyftime 50
#define PRD 2500
#define f_rated 50.0
//#define freq_step 0.00003   // f_rated*timersampling*vbyflimit/vbyftime  here 50*0.8*50e-6/50sec
//#define countlimit 1000000   // vbyftime/timersampling  50/50e-6
//#define ma_step  0.0000006  // vbyflimit/countlimit

/*induction motor parameters*/
#define Rs 3.7
#define Rr 2.459
#define Ls 0.34634
#define Lr 0.34634
#define Lm 0.329
#define J 0.0106
#define B 0.01
#define T_nom 9.982
#define sf_nom 1.3426
#define Ts 0.00005
#define p 2 //pole pairs

//ADC offsets measured on 6/5/18
#define VDCOFFSET 0.005127//2055
#define IAOFFSET 0.004395//02054
#define IBOFFSET 0.010254//2063
#define ICOFFSET 0.008789//2053
#define OFFSET 2047


// Prototype statements for functions found within this file.
__interrupt void cpu_timer0_isr(void);
__interrupt void cpu_timer1_isr(void);
//__interrupt void cpu_timer2_isr(void);

/*Defining the PI regulator inputs*/
PI pi_speed = PI_DEFAULTS;
float T_ref=0;
float speed_ref=0;

POSSPEED qep_posspeed = POSSPEED_DEFAULTS;

/*Variables for generating v/f code*/
unsigned long int i=0;
float theta=0,freq=0;
//float freq_step=0,ma_step=0;
unsigned long int countlimit=0;
float ma_step,freq_step;
float mod_a,mod_b,mod_c,m_a=0;

//variables to store A/D conversion results
/*Uint16 AdcaResult0;
Uint16 AdcaResult1;
Uint16 AdcbResult0;
Uint16 AdcbResult1;
Uint16 AdcaResult2;*/
float V_dcm=0, I_am=0,I_bm=0, I_cm=0;
float V_dc=0, I_a=0,I_b=0, I_c=0;
float speed=0;
unsigned char j=1;


/*PTC terms declaration*/
float tr,sigma,kr,t_sigma,r_sigma,lambda;
float V_a=0, V_b=0,V_c=0;
float V_alpha1[8]={0.0, 0.6667, 0.3333, -0.3333, -0.6667, -0.3333, 0.3333, 0.0};
float V_beta1[8]={0.0, 0.0, 0.5774, 0.5774, 0.0, -0.5774, -0.5774, 0.0};
float G_opt = 100000,G;
float V_alpha, V_beta;
float psi_alpha_s, psi_beta_s,psi_alpha_r,psi_beta_r;
float i_meas_alpha, i_meas_beta;
unsigned char x_opt =0;
float w_meas;

/*Declaration of peripheral functions*/
void Gpio_select(void);
void setup_EPwm(void);
void ConfigureADC(void);
void SetupADCSoftware(void);
void runvbyf(void);

// Functions for PTC
void PTC(float T_ref, float w_meas, float sf, float i_meas_alpha, float i_meas_beta);
void pulsegeneration(unsigned char x);
void ReadADC(void);

void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.


    InitSysCtrl();
    //InitSysPll(XTAL_OSC,IMULT_40,FMULT_0,PLLCLK_BY_2);

// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
  //  InitGpio();
 //   GPIO_SetupPinMux(65, GPIO_MUX_CPU1, 0);
 //   GPIO_SetupPinOptions(65, GPIO_OUTPUT, GPIO_PUSHPULL);
    Gpio_select();

// 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 F2837xS_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 F2837xS_DefaultIsr.c.
// This function is found in F2837xS_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;    // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize the Device Peripheral. This function can be
    //         found in F2837xS_CpuTimers.c
    InitCpuTimers();   // For this example, only initialize the Cpu Timers

    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 200MHz CPU Freq, 1 second Period (in uSeconds)
    ConfigCpuTimer(&CpuTimer0, 200, 50);
    ConfigCpuTimer(&CpuTimer1, 200, 10);
    //ConfigCpuTimer(&CpuTimer2, 200, 1000000);

    // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
    // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in F2837xS_cputimervars.h), the
    // below settings must also be updated.
    CpuTimer0Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0
    CpuTimer1Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0
    //CpuTimer2Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0

    // Step 5. User specific code, enable interrupts:

    // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
    // which is connected to CPU-Timer 1, and CPU int 14, which is connected
    // to CPU-Timer 2:
    IER |= M_INT1;
    IER |= M_INT13;
    //IER |= M_INT14;

    // Enable TINT0 in the PIE: Group 1 interrupt 7
    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

    countlimit = (vbyftime/50)*1000000;
    freq_step = (f_rated*vbyflimit)/countlimit;
    ma_step = vbyflimit/countlimit;

    // EPWM initializations for Vbyf start
    setup_EPwm();


    //Configure the ADCs and power them up
        ConfigureADC();

    //Setup the ADCs for software conversions
       SetupADCSoftware();

       // Setting up PI controller values
       pi_speed.Kp = 60.0f; // set proportional gain to 20.0
       pi_speed.Ki = 0.02f;
       pi_speed.Umax = 10.0f; // upper output clamp limit = 10
       pi_speed.Umin = -10.0f;

       // PTC terms
       tr = Lr/Rr;
       kr = Lm/Lr;
       sigma = (1-((Lm*Lm)/(Ls*Lr)));
       r_sigma = Rs + ((kr*kr)*Rr);
       t_sigma = sigma*(Ls/r_sigma);
       lambda = T_nom/sf_nom;



// Step 6. IDLE loop. Just sit and loop forever (optional):
    while(1)
    {

    }
}

__interrupt void cpu_timer0_isr(void)
{
   CpuTimer0.InterruptCount++;

   ReadADC();
   runvbyf();


   speed_ref=100;
   speed=10;

   T_ref=DCL_runPI(&pi_speed,speed_ref,speed);


   i_meas_alpha = 0.66667*(I_a - I_b/2 - I_c/2);
   i_meas_beta = 0.57735*(I_b - I_c);

   if(GpioDataRegs.GPADAT.bit.GPIO12==1)
       V_a = V_dc/2;
   else //if(GpioDataRegs.GPADAT.bit.GPIO13==1)
       V_a = -V_dc/2;
   if(GpioDataRegs.GPADAT.bit.GPIO14==1)
          V_b = V_dc/2;
      else //if(GpioDataRegs.GPADAT.bit.GPIO15==1)
          V_b = -V_dc/2;
   if(GpioDataRegs.GPADAT.bit.GPIO16==1)
          V_c = V_dc/2;
      else //if(GpioDataRegs.GPADAT.bit.GPIO17==1)
          V_c = -V_dc/2;

   V_alpha = 0.66667*(V_a - V_b/2 - V_c/2);
      V_beta = 0.57735*(V_b - V_c);


   psi_alpha_s = psi_alpha_s + Ts*((V_alpha)-(i_meas_alpha*Rs));
   psi_alpha_s = 0.9989*psi_alpha_s;
   //psi_alpha_s = psi_alpha_s*pi;
   //psi_alpha_s = psi_alpha_s*100;
   psi_beta_s = psi_beta_s + Ts*((V_beta)-(i_meas_beta*Rs));
   psi_beta_s = 0.9989*psi_beta_s;
   //psi_beta_s = psi_beta_s*pi;
   //psi_beta_s = psi_beta_s*100;


   EPwm11Regs.CMPA.bit.CMPA = ((psi_alpha_s*0.5) + 0.5)*PRD/8;
   EPwm11Regs.CMPB.bit.CMPB =  ((psi_beta_s*0.5) + 0.5)*PRD/8;

   //GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1;

   // Acknowledge this interrupt to receive more interrupts from group 1
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

__interrupt void cpu_timer1_isr(void)
{
   CpuTimer1.InterruptCount++;


   Uint16 i;

      //
      // Position and Speed measurement
      //
      qep_posspeed.calc(&qep_posspeed);

      //
      // Control loop code for position control & Speed control
      //
    /* Interrupt_Count++;

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

*/
   // The CPU acknowledges the interrupt.

}
/*
__interrupt void cpu_timer2_isr(void)
{
   CpuTimer2.InterruptCount++;
   // The CPU acknowledges the interrupt.
}*/


void setup_EPwm(void)
{

// setting up TB clock and other settings EPwm7
        EPwm7Regs.TBCTL.bit.PHSEN = 0;
        EPwm7Regs.TBCTL.bit.CTRMODE = 2;
        //EPwm7Regs.TBCTL.bit.PRDLD = 1;
        EPwm7Regs.TBCTL.bit.SYNCOSEL = 0;
        //EPwm7Regs.TBCTL.bit.SWFSYNC = 0;
        EPwm7Regs.TBCTL.bit.HSPCLKDIV = 1; // means sysclk/2
        EPwm7Regs.TBCTL.bit.CLKDIV = 1;    // means sysclk/2
        //EPwm7Regs.TBCTL.bit.FREE_SOFT = 2;
        EPwm7Regs.TBCTL.bit.PHSDIR = 0;
        //EPwm7Regs.TBSTS.all=0;
        EPwm7Regs.TBPHS.all=0;
        EPwm7Regs.TBCTR = 0;

// actions AQCTLA - one pwm

        EPwm7Regs.AQCTLA.bit.CAU = AQ_SET;          // set PWMxA on event CMPA, up count
        EPwm7Regs.AQCTLA.bit.CAD = AQ_CLEAR;        // clear PWMxA on event CMPA, down count

// actions AQCTLB - other pwm

        EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWMxB on event CMPB, up count
        EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;         // set PWMxB on event CMPB, down count


// Compare values
       //EPwm7Regs.CMPA.bit.CMPA = mod_a;    // Set compare A value

        EPwm7Regs.TBPRD=PRD;    //loading the req. period value


// setting up TB clock and other settings EPwm8
        EPwm8Regs.TBCTL.bit.PHSEN = 0;
        EPwm8Regs.TBCTL.bit.CTRMODE = 2;
      //EPwm8Regs.TBCTL.bit.PRDLD = 1;
        EPwm8Regs.TBCTL.bit.SYNCOSEL = 0;
      //EPwm8Regs.TBCTL.bit.SWFSYNC = 0;
        EPwm8Regs.TBCTL.bit.HSPCLKDIV = 1; // means sysclk/2
        EPwm8Regs.TBCTL.bit.CLKDIV = 1;    // means sysclk/2
      //EPwm8Regs.TBCTL.bit.FREE_SOFT = 2;
       EPwm8Regs.TBCTL.bit.PHSDIR = 0;
      //EPwm8Regs.TBSTS.all=0;
        //EPwm8Regs.TBCTR = 0;
        EPwm8Regs.TBPHS.bit.TBPHS=0;


//actions AQCTLA - one pwm

        EPwm8Regs.AQCTLA.bit.CAU = AQ_SET;          // set PWMxA on event CMPA, up count
        EPwm8Regs.AQCTLA.bit.CAD = AQ_CLEAR;         // Clear PWMxA on event CMPA, down count

      //actions AQCTLB - other pwm

      EPwm8Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWMxB on event CMPB, up count
      EPwm8Regs.AQCTLB.bit.CBD = AQ_SET;          // Set PWMxB on event CMPB, down count

      // Compare values
      //EPwm8Regs.CMPA.bit.CMPA = 250;    // Set compare A value

        EPwm8Regs.TBPRD=PRD;    //loading the req. period value


// setting up TB clock and other settings EPwm9
        EPwm9Regs.TBCTL.bit.PHSEN = 0;
        EPwm9Regs.TBCTL.bit.CTRMODE = 2;
      //EPwm9Regs.TBCTL.bit.PRDLD = 1;
       EPwm9Regs.TBCTL.bit.SYNCOSEL = 0;
      //EPwm9Regs.TBCTL.bit.SWFSYNC = 0;
        EPwm9Regs.TBCTL.bit.HSPCLKDIV = 1; // means sysclk/2
        EPwm9Regs.TBCTL.bit.CLKDIV = 1;    // means sysclk/2
      //EPwm9Regs.TBCTL.bit.FREE_SOFT = 2;
        EPwm9Regs.TBCTL.bit.PHSDIR = 0;
      //EPwm9Regs.TBSTS.all=0;
        //EPwm9Regs.TBCTR = 0;
        EPwm9Regs.TBPHS.bit.TBPHS=0;


     //actions AQCTLA - one pwm

      EPwm9Regs.AQCTLA.bit.CAU = AQ_SET;          // set PWMxA on event CMPA, up count
      EPwm9Regs.AQCTLA.bit.CAD = AQ_CLEAR;          // Clear PWMxA on event CMPA, down count

      //actions AQCTLB - other pwm

      EPwm9Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWMxB on event CMPB, up count
      EPwm9Regs.AQCTLB.bit.CBD = AQ_SET;          // set PWMxB on event CMPB, down count

     // Compare values
      //EPwm9Regs.CMPA.bit.CMPA = 250;    // Set compare A value

        EPwm9Regs.TBPRD=PRD;    //loading the req. period value

        // setting up TB clock and other settings EPwm11
           EPwm11Regs.TBCTL.bit.PHSEN = 0;
           EPwm11Regs.TBCTL.bit.CTRMODE = 2;
         //EPwm11Regs.TBCTL.bit.PRDLD = 1;
           EPwm11Regs.TBCTL.bit.SYNCOSEL = 0;
         //EPwm11Regs.TBCTL.bit.SWFSYNC = 0;
           EPwm11Regs.TBCTL.bit.HSPCLKDIV = 1; // means sysclk/2
           EPwm11Regs.TBCTL.bit.CLKDIV = 1;    // means sysclk/2
         //EPwm11Regs.TBCTL.bit.FREE_SOFT = 2;
           EPwm11Regs.TBCTL.bit.PHSDIR = 0;
         //EPwm11Regs.TBSTS.all=0;
           EPwm11Regs.TBPHS.all=0;
           EPwm11Regs.TBCTR = 0;

        // actions AQCTLA - one pwm

           EPwm11Regs.AQCTLA.bit.CAU = AQ_SET;          // set PWMxA on event CMPA, up count
           EPwm11Regs.AQCTLA.bit.CAD = AQ_CLEAR;        // clear PWMxA on event CMPA, down count
        // actions AQCTLB - other pwm

           EPwm11Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWMxB on event CMPB, up count
           EPwm11Regs.AQCTLB.bit.CBD = AQ_SET;         // set PWMxB on event CMPB, down count

        // Compare values
         //EPwm11Regs.CMPA.bit.CMPA = mod_a;    // Set compare A value
           EPwm11Regs.TBPRD=PRD/8;    //loading the req. period value
}




void Gpio_select(void)
{
    EALLOW;


    GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;   // Enable pullup on GPIO12
    GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // GPIO12 = EPwm7A

    GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;   // Enable pullup on GPIO13
    GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // GPIO13 = EPwm7B

    GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;   // Enable pullup on GPIO14
    GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // GPIO14 = EPwm8A

    GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;   // Enable pullup on GPIO15
    GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // GPIO15 = EPwm8B

    GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;   // Enable pullup on GPIO16
    GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1;  // GPIO16 = EPwm9A
    GpioCtrlRegs.GPAGMUX2.bit.GPIO16 = 1;

    GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;   // Enable pullup on GPIO17;
    GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1;  // GPIO17 = EPwm9B
    GpioCtrlRegs.GPAGMUX2.bit.GPIO17 = 1;

    GpioCtrlRegs.GPAPUD.bit.GPIO20 = 0;   // Enable pullup on GPIO20
    GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1;  // GPIO20 = EPwm11A
    GpioCtrlRegs.GPAGMUX2.bit.GPIO20 = 1;


    GpioCtrlRegs.GPAPUD.bit.GPIO21 = 0;   // Enable pullup on GPIO21
    GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1;  // GPIO21 = EPwm11B
    GpioCtrlRegs.GPAGMUX2.bit.GPIO21 = 1;

    //GpioCtrlRegs.GPAMUX2.all = 0x00000000;  // All GPIO
    //GpioCtrlRegs.GPBMUX1.all = 0x00000000;  // All GPIO

    //GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF;   // All outputs
    //GpioCtrlRegs.GPBDIR.all = 0x00001FFF;   // All outputs

    EDIS;

}

//Write ADC configurations and power up the ADC for both ADC A and ADC B
void ConfigureADC(void)
{
    EALLOW;

    //write configurations
    AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

    //Set pulse positions to late
    AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
    AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;

    //power up the ADCs
    AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
    AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;

    //delay for 1ms to allow ADC time to power up
    DELAY_US(1000);

    EDIS;
}

void ReadADC(void)
{
     AdcaRegs.ADCSOCFRC1.all = 0x0007; //SOC0 - 2, SOC1-3 and SOC2-5
     AdcbRegs.ADCSOCFRC1.all = 0x0007; //SOC0, SOC1 and SOC2
     //store results

     if (AdcaResultRegs.ADCRESULT0 == 0)  V_dcm = 0.0;
         else if (AdcaResultRegs.ADCRESULT0 == 4095) V_dcm = 3.0;
         else    V_dcm = __divf32(3.0*((float)AdcaResultRegs.ADCRESULT0), 4096.0);

     //V_dcm = AdcaResultRegs.ADCRESULT0;  //A2 off set observed 2055
     //V_dc = ((V_dcm-(VDCOFFSET-OFFSET))*3.0)/4096.0;
     V_dcm = V_dcm-VDCOFFSET;
     V_dc = ((V_dcm-1.5)/0.15384)*200;
     //AdcaResult1 = AdcaResultRegs.ADCRESULT1;
     //AdcaResult2 = AdcaResultRegs.ADCRESULT2;
     //I_am = AdcbResultRegs.ADCRESULT0;   //B1 offset observed 2054

     if (AdcbResultRegs.ADCRESULT0 == 0)  I_am = 0.0;
     else if (AdcbResultRegs.ADCRESULT0 == 4095) I_am = 3.0;
     else    I_am = __divf32(3.0*((float)AdcbResultRegs.ADCRESULT0), 4096.0);
     I_am = I_am - IAOFFSET;
     I_a = ((I_am-1.5)/0.15384);

     //I_bm = AdcbResultRegs.ADCRESULT1;   //B4 offset observed 2063
     if (AdcbResultRegs.ADCRESULT1 == 0)  I_bm = 0.0;
     else if (AdcbResultRegs.ADCRESULT1 == 4095) I_bm = 3.0;
     else    I_bm = __divf32(3.0*((float)AdcbResultRegs.ADCRESULT1), 4096.0);
     I_bm = I_bm - IBOFFSET;
     I_b = ((I_bm-1.5)/0.15384);

     //I_cm = AdcbResultRegs.ADCRESULT2;   //B2 offset observed 2057
     if (AdcbResultRegs.ADCRESULT2 == 0)  I_cm = 0.0;
     else if (AdcbResultRegs.ADCRESULT2 == 4095) I_cm = 3.0;
     else    I_cm = __divf32(3.0*((float)AdcbResultRegs.ADCRESULT2), 4096.0);
     I_cm = I_cm - ICOFFSET;
     I_c = ((I_cm-1.5)/0.15384);
}

void SetupADCSoftware(void)
{
    Uint16 acqps;

    //determine minimum acquisition window (in SYSCLKS) based on resolution
    if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION){
        acqps = 14; //75ns
    }
    else { //resolution is 16-bit
        acqps = 63; //320ns
    }

//Select the channels to convert and end of conversion flag
    //ADCA
    EALLOW;
    AdcaRegs.ADCSOC0CTL.bit.CHSEL = 2;          //SOC0 will convert pin A2
    AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcaRegs.ADCSOC1CTL.bit.CHSEL = 3;          //SOC1 will convert pin A3
    AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcaRegs.ADCSOC2CTL.bit.CHSEL = 5;          //SOC1 will convert pin A5
    AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 2;      //end of SOC2 will set INT1 flag
    AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;        //enable INT1 flag
    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;      //make sure INT1 flag is cleared

    //ADCB
    AdcbRegs.ADCSOC0CTL.bit.CHSEL = 1;          //SOC0 will convert pin B1
    AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcbRegs.ADCSOC1CTL.bit.CHSEL = 4;          //SOC1 will convert pin B4
    AdcbRegs.ADCSOC1CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2;          //SOC1 will convert pin B2
    AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps;      //sample window is acqps + 1 SYSCLK cycles
    AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 2;      //end of SOC2 will set INT1 flag
    AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1;        //enable INT1 flag
    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;      //make sure INT1 flag is cleared

}


void PTC(float T_ref, float w_meas, float sf, float i_meas_alpha, float i_meas_beta)
{
float i_pred_alpha,i_pred_beta;
float T_pred,psi_pred_alpha_s, psi_pred_beta_s,psi_pred;
unsigned char k=0;

//stator and rotor flux estimation
//psi_alpha_s = psi_alpha_s + Ts*((V_dc*V_alpha1[x_opt])-i_meas_alpha*Rs);
//psi_beta_s = psi_beta_s + Ts*((V_dc*V_beta1[x_opt])-i_meas_beta*Rs);

psi_alpha_r = psi_alpha_s/kr + sigma*Lm*i_meas_alpha;
psi_beta_r = psi_beta_s/kr + sigma*Lm*i_meas_beta;



/*

if(k<=7)
{
    V_alpha = V_alpha1[k]*V_dc;
    V_beta = V_beta1[k]*V_dc;
// flux prediction
psi_pred_alpha_s = psi_alpha_s + Ts*(V_alpha - Rs*i_meas_alpha);
psi_pred_beta_s = psi_beta_s + Ts*(V_beta - Rs*i_meas_beta);

psi_pred = sqrt((psi_pred_alpha_s*psi_pred_alpha_s)+(psi_pred_beta_s*psi_pred_beta_s));

// current prediction
i_pred_alpha =(1-(Ts/t_sigma))*i_meas_alpha + (Ts/(t_sigma*r_sigma))*(V_alpha + kr*w_meas*psi_beta_r + (kr/tr)*psi_alpha_r);
i_pred_beta =(1-(Ts/t_sigma))*i_meas_beta + (Ts/(t_sigma*r_sigma))*(V_beta - kr*w_meas*psi_alpha_r + (kr/tr)*psi_beta_r);

// Torque prediction

T_pred = 1.5*p*(psi_pred_alpha_s*i_pred_beta - psi_pred_beta_s*i_pred_alpha);

// Objective function

G = (T_ref-T_pred) + lambda*(sf_nom - psi_pred);

if(G<G_opt)
{
    x_opt = k;
    G_opt = G;
}

k++;
}
else
{
    k=0;
}

pulsegeneration(x_opt);
*/
}

void pulsegeneration(unsigned char x)
{
    GpioCtrlRegs.GPAMUX1.all &= 0x00FFFFFF;  // disabling PWM on GPIO 12,13,14,15
    GpioCtrlRegs.GPAMUX2.all &= 0xFFFFFFF0;  // disabling PWM on GPIO 16,17
    GpioCtrlRegs.GPADIR.all |= 0x0003F000;   // GPIOs 12,13,14,15,16,17 configured as outputs

    switch(x)
    {
    case '0':
             GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
             GpioDataRegs.GPADAT.all |= 0x0002A000;
             break;
    case '1':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00029000;
              break;
    case '2':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00025000;
              break;
    case '3':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00026000;
              break;
    case '4':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00016000;
              break;
    case '5':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x0001A000;
              break;
    case '6':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00019000;
              break;
    case '7':
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x00015000;
              break;
    default:
              GpioDataRegs.GPADAT.all &= 0xFFFC0FFF;
              GpioDataRegs.GPADAT.all |= 0x000C0000;
              break;

    }

}

void runvbyf(void)
{
    float theta1,theta2;

       if (i<=countlimit)
       {
           freq += freq_step;
           theta += 2*pi*freq*0.00005;
           if (theta>= 2*pi)
               theta = 0.0;
           if(freq<=5.0)
           {
               m_a = 0.1;
           }
           else
           {
           m_a += ma_step;
           }

           i++;

       }
       else
       {
           //theta=0;

           i=countlimit+5;
           freq = vbyflimit*f_rated;
           theta += 2*pi*freq*0.00005;
           if (theta>= 2*pi)
               theta = 0.0;
           m_a = vbyflimit;


       }

       theta1 = theta + (2*pi/3);
       theta2 = theta + (4*pi/3);

       mod_a = (((sin(theta))*m_a*0.5) + 0.5)*PRD;
       mod_b = (((sin(theta1))*m_a*0.5) + 0.5)*PRD;
       mod_c = (((sin(theta2))*m_a*0.5) + 0.5)*PRD;

     //  Assign_PWM(uint8_t mod_a,mod_b, mod_c);


       //mod_a = 1250;
       EPwm7Regs.CMPA.bit.CMPA =  mod_a;
       EPwm7Regs.CMPB.bit.CMPB =  mod_a;
       EPwm8Regs.CMPA.bit.CMPA =  mod_b;
       EPwm8Regs.CMPB.bit.CMPB =  mod_b;
       EPwm9Regs.CMPA.bit.CMPA =  mod_c;
       EPwm9Regs.CMPB.bit.CMPB =  mod_c;

}
The EPWM setup.c file is:
//###########################################################################
//
// FILE:    Example_EpwmSetup.c
//
// TITLE:   Pos speed measurement using EQEP peripheral
//
// DESCRIPTION:
//
// This file contains source for the ePWM initialization for the
// pos/speed module
//
//###########################################################################
// $TI Release: F2837xS Support Library v210 $
// $Release Date: Tue Nov  1 15:35:23 CDT 2016 $
// $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
//             http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

//
// Included Files
//
#include "F28x_Project.h"
#include "Example_posspeed.h"

//
// Defines
//
#define TB_CLK    100e6
#define PWM_CLK   5e3              // 5kHz (300rpm) EPWM1 frequency
#define SP        TB_CLK/(2*PWM_CLK)
#define TBCTLVAL  0x200A           // up-down count, timebase=SYSCLKOUT

//
// initEpwm - Initialize EPWM1 configurations
//
void initEpwm()
{
    EPwm1Regs.TBSTS.all=0;
    EPwm1Regs.TBPHS.all =0;
    EPwm1Regs.TBCTR=0;

    EPwm1Regs.CMPCTL.all=0x50;     // immediate mode for CMPA and CMPB
    EPwm1Regs.CMPA.bit.CMPA=SP/2;
    EPwm1Regs.CMPB.all=0;

    EPwm1Regs.AQCTLA.all=0x60;     // CTR=CMPA when inc->EPWM1A=1,
                                   // when dec->EPWM1A=0
    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;
}

//
// End of file

//

The posspeed.c file is
//###########################################################################
//
// FILE:    Example_posspeed.c
//
// TITLE:   Pos/speed measurement using EQEP peripheral
//
// DESCRIPTION:
//
// This file includes the EQEP initialization and position and speed
// calculation functions called by Eqep_posspeed.c.  The position and speed
// calculation steps performed by POSSPEED_Calc() at  SYSCLKOUT =  200 MHz are
// described below:
//
// 1. This program calculates: **theta_mech**
//
//    theta_mech = QPOSCNT/mech_Scaler = QPOSCNT/4000, where 4000 is the number
//                 of counts in 1 revolution.
//                (4000/4 = 1000 line/rev. quadrature encoder)
//
// 2. This program calculates: **theta_elec**
//
//    theta_elec = (# pole pairs) * theta_mech = 2*QPOSCNT/4000
//
// 3. This program calculates: **SpeedRpm_fr**
//
//    SpeedRpm_fr = [(x2-x1)/4000]/T   - Equation 1
//    Note (x2-x1) = difference in number of QPOSCNT counts. Dividing (x2-x1)
//    by 4000 gives position relative to Index in one revolution.
// If base RPM  = 6000 rpm:   6000 rpm = [(x2-x1)/4000]/10ms   - Equation 2
//                                     = [(x2-x1)/4000]/(.01s*1 min/60 sec)
//                                     = [(x2-x1)/4000]/(1/6000) min
//                         max (x2-x1) = 4000 counts, or 1 revolution in 10 ms
//
//
// If both sides of Equation 2 are divided by 6000 rpm, then:
//                   1 = [(x2-x1)/4000] rev./[(1/6000) min * 6000rpm]
//                   Because (x2-x1) must be <4000 (max) for QPOSCNT increment,
//                   (x2-x1)/4000 < 1 for CW rotation
//                   And because (x2-x1) must be >-4000 for QPOSCNT decrement,
//                   (x2-x1)/4000>-1  for CCW rotation
//                   speed_fr = [(x2-x1)/4000]/[(1/6000) min * 6000rpm]
//                            = (x2-x1)/4000   - Equation 3
//
// To convert speed_fr to RPM, multiply Equation 3 by 6000 rpm
//                   SpeedRpm_fr = 6000rpm *(x2-x1)/4000  - Final Equation
//
// 2. **min rpm ** = selected at 10 rpm based on CCPS prescaler options
//    available (128 is greatest)
//
// 3. **SpeedRpm_pr**
//    SpeedRpm_pr = X/(t2-t1)  - Equation 4
//    where X = QCAPCTL [UPPS]/4000 rev. (position relative to Index in
//                                        1 revolution)
// If  max/base speed = 6000 rpm:
//               6000 = (32/4000)/[(t2-t1)/(200MHz/64)]
//           where 32 = QCAPCTL [UPPS] (Unit timeout - once every 32 edges)
//            32/4000 = position in 1 revolution (position as a fraction
//                                                of 1 revolution)
//   t2-t1/(200MHz/64), t2-t1= # of QCAPCLK cycles, and
//      QCAPCLK cycle = 1/(200MHz/64)
//                    = QCPRDLAT
//
// So:       6000 rpm = [32(200MHz/64)*60s/min]/[4000(t2-t1)]
//              t2-t1 = [32(200MHz/64)*60s/min]/(4000*6000rpm)  - Equation 5
//                    = 250 CAPCLK cycles = maximum (t2-t1) = SpeedScaler
//
// Divide both sides by (t2-t1), and:
//            1 = 32/(t2-t1) = [32(200MHz/64)*60 s/min]/(4000*6000rpm)]/(t2-t1)
//       Because (t2-t1) must be < 250 for QPOSCNT increment:
//               250/(t2-t1) < 1 for CW rotation
//       And because (t2-t1) must be >-250 for QPOSCNT decrement:
//                250/(t2-t1)> -1 for CCW rotation
//
//       eed_pr = 250/(t2-t1)
//             or [32(200MHz/64)*60 s/min]/(4000*6000rpm)]/(t2-t1) - Equation 6
//
// To convert speed_pr to RPM:
// Multiply Equation 6 by 6000rpm:
// SpeedRpm_fr  = 6000rpm * [32(200MHz/64)*60 s/min]/[4000*6000rpm*(t2-t1)]
//              = [32(200MHz/64)*60 s/min]/[4000*(t2-t1)]
//              or [(32/4000)rev * 60 s/min]/[(t2-t1)(QCPRDLAT)]-Final Equation
//
// More detailed calculation results can be found in the Example_freqcal.xls
// spreadsheet included in the example folder.
//
// This file contains source for the posspeed module
//
//###########################################################################
// $TI Release: F2837xS Support Library v210 $
// $Release Date: Tue Nov  1 15:35:23 CDT 2016 $
// $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
//             http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

//
// Included Files
//
#include "F28x_Project.h"
#include "Example_posspeed.h"

//
// POSSPEED_Init - Initialize EQEP1 configuration
//
void  POSSPEED_Init(void)
{
    EQep1Regs.QUPRD = 2000000;            // Unit Timer for 100Hz at 200 MHz
                                          // SYSCLKOUT
    EQep1Regs.QDECCTL.bit.QSRC = 00;      // QEP quadrature count mode
    EQep1Regs.QEPCTL.bit.FREE_SOFT = 2;
    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 = 0xffffffff;
    EQep1Regs.QEPCTL.bit.QPEN = 1;        // QEP enable
    EQep1Regs.QCAPCTL.bit.UPPS = 5;       // 1/32 for unit position
    EQep1Regs.QCAPCTL.bit.CCPS = 6;       // 1/64 for CAP clock
    EQep1Regs.QCAPCTL.bit.CEN = 1;        // QEP Capture Enable
}

//
// POSSPEED_Calc - Perform the position calculations
//
void POSSPEED_Calc(POSSPEED *p)
{
    long tmp;
    unsigned int pos16bval,temp1;
    _iq Tmp1,newp,oldp;

    //
    // Position calculation - mechanical and electrical motor angle
    //
    p->DirectionQep = EQep1Regs.QEPSTS.bit.QDF;  // Motor direction:
                                                 // 0=CCW/reverse, 1=CW/forward

    pos16bval = (unsigned int)EQep1Regs.QPOSCNT; // capture position once
                                                 // per QA/QB period
    p->theta_raw = pos16bval+ p->cal_angle;      // raw theta = current pos. +
                                                 // ang. offset from QA

    //
    // The following lines calculate
    // p->theta_mech ~= QPOSCNT/mech_scaler [current cnt/(total cnt in 1 rev.)]
    // where mech_scaler = 4000 cnts/revolution
    //
    tmp = (long)((long)p->theta_raw*(long)p->mech_scaler);   // Q0*Q26 = Q26
    tmp &= 0x03FFF000;
    p->theta_mech = (int)(tmp>>11);                          // Q26 -> Q15
    p->theta_mech &= 0x7FFF;

    //
    // The following lines calculate p->elec_mech
    //
    p->theta_elec = p->pole_pairs*p->theta_mech;             // Q0*Q15 = Q15
    p->theta_elec &= 0x7FFF;

    //
    // Check an index occurrence
    //
    if(EQep1Regs.QFLG.bit.IEL == 1)
    {
       p->index_sync_flag = 0x00F0;
       EQep1Regs.QCLR.bit.IEL = 1;    // Clear __interrupt flag
    }

    //
    // High Speed Calculation using QEP Position counter
    //
    // Check unit Time out-event for speed calculation:
    // Unit Timer is configured for 100Hz in INIT function
    //
    if(EQep1Regs.QFLG.bit.UTO == 1)    // If unit timeout (one 100Hz period)
    {
        //
        // Differentiator
        //
        // The following lines calculate
        // position = (x2-x1)/4000 (position in 1 revolution)
        //
        pos16bval = (unsigned int)EQep1Regs.QPOSLAT;   // Latched POSCNT value
        tmp = (long)((long)pos16bval*(long)p->mech_scaler); // Q0*Q26 = Q26
        tmp &= 0x03FFF000;
        tmp = (int)(tmp>>11);                               // Q26 -> Q15
        tmp &= 0x7FFF;
        newp = _IQ15toIQ(tmp);
        oldp = p->oldpos;

        if(p->DirectionQep==0)                     // POSCNT is counting down
        {
            if(newp>oldp)
            {
                Tmp1 = - (_IQ(1) - newp + oldp);    // x2-x1 should be negative
            }
            else
            {
                Tmp1 = newp -oldp;
            }
        }
        else if(p->DirectionQep == 1)              // POSCNT is counting up
        {
            if(newp<oldp)
            {
                Tmp1 = _IQ(1) + newp - oldp;
            }
            else
            {
                Tmp1 = newp - oldp;                 // x2-x1 should be positive
            }
        }

        if(Tmp1>_IQ(1))
        {
            p->Speed_fr = _IQ(1);
        }
        else if(Tmp1<_IQ(-1))
        {
            p->Speed_fr = _IQ(-1);
        }
        else
        {
            p->Speed_fr = Tmp1;
        }

        //
        // Update the electrical angle
        //
        p->oldpos = newp;

        //
        // Change motor speed from pu value to rpm value (Q15 -> Q0)
        // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q
        //
        p->SpeedRpm_fr = _IQmpy(p->BaseRpm,p->Speed_fr);

        EQep1Regs.QCLR.bit.UTO=1;                   // Clear __interrupt flag
    }

    //
    // Low-speed computation using QEP capture counter
    //
    if(EQep1Regs.QEPSTS.bit.UPEVNT == 1)               // Unit position event
    {
        if(EQep1Regs.QEPSTS.bit.COEF == 0)             // No Capture overflow
        {
            temp1 = (unsigned long)EQep1Regs.QCPRDLAT; // temp1 = t2-t1
        }
        else   // Capture overflow, saturate the result
        {
            temp1 = 0xFFFF;
        }

        //
        // p->Speed_pr = p->SpeedScaler/temp1
        //
        p->Speed_pr = _IQdiv(p->SpeedScaler,temp1);
        Tmp1 = p->Speed_pr;

        if (Tmp1>_IQ(1))
        {
            p->Speed_pr = _IQ(1);
        }
        else
        {
            p->Speed_pr = Tmp1;
        }

        //
        // Convert p->Speed_pr to RPM
        //
        if(p->DirectionQep == 0)  // Reverse direction = negative
        {
            //
            // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q
            //
            p->SpeedRpm_pr = -_IQmpy(p->BaseRpm,p->Speed_pr);
        }
        else                     // Forward direction = positive
        {
            //
            // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q
            //
            p->SpeedRpm_pr = _IQmpy(p->BaseRpm,p->Speed_pr);
        }

        EQep1Regs.QEPSTS.all = 0x88; // Clear Unit position event flag
                                     // Clear overflow error flag
    }
}

//
// End of file
//

and finally the pospeded.h file is :
//###########################################################################
//
// FILE:    Example_posspeed.h
//
// TITLE:   Pos/speed measurement using EQEP peripheral
//
// DESCRIPTION:
//
// Header file containing data type and object definitions and
// initializers.
//
//###########################################################################
// $TI Release: F2837xS Support Library v210 $
// $Release Date: Tue Nov  1 15:35:23 CDT 2016 $
// $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
//             http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

#ifndef __POSSPEED__
#define __POSSPEED__

//
// Included Files
//
#include "IQmathLib.h"

//
// Defines
//
#define POSSPEED_DEFAULTS {0x0, 0x0,0x0,0x0,0x0,16776,2,0,0x0,\
                           250,0,6000,0,\
                           0,0,0,\
                           (void (*)(long))POSSPEED_Init,\
                           (void (*)(long))POSSPEED_Calc }

//
// Globals
//
typedef struct {int theta_elec;         // Output: Motor Electrical angle (Q15)
                int theta_mech;         // Output: Motor Mechanical Angle (Q15)
                int DirectionQep;       // Output: Motor rotation direction (Q0)
                int QEP_cnt_idx;        // Variable: Encoder counter index (Q0)
                int theta_raw;          // Variable: Raw angle from Timer 2 (Q0)
                int mech_scaler;        // Parameter: 0.9999/total count, total
                                        // count = 4000 (Q26)
                int pole_pairs;         // Parameter: Number of pole pairs (Q0)
                int cal_angle;          // Parameter: Raw angular offset
                                        // between encoder and phase a (Q0)
                int index_sync_flag;    // Output: Index sync status (Q0)

                Uint32 SpeedScaler;     // Parameter :  Scaler converting 1/N
                                        // cycles to a GLOBAL_Q speed (Q0) -
                                        // independently with global Q
                _iq Speed_pr;           // Output :  speed in per-unit
                Uint32 BaseRpm;         // Parameter : Scaler converting
                                        // GLOBAL_Q speed to rpm (Q0) speed -
                                        // independently with global Q
                int32 SpeedRpm_pr;      // Output : speed in r.p.m. (Q0) -
                                        // independently with global Q
                _iq  oldpos;            // Input: Electrical angle (pu)
                _iq Speed_fr;           // Output :  speed in per-unit
                int32 SpeedRpm_fr;      // Output : Speed in rpm  (Q0) -
                                        // independently with global Q
                void (*init)();         // Pointer to the init funcion
                void (*calc)();         // Pointer to the calc funtion
                }  POSSPEED;

typedef POSSPEED *POSSPEED_handle;

//
// Function Prototypes
//
void POSSPEED_Init(void);
void POSSPEED_Calc(POSSPEED_handle);

#endif //  __POSSPEED__

//
// End of file
//
All the necessary files have been included. Any help would be highly appreciated.
Thank you.
  • Hi Ki,
    The issue is that the IQmath.lib used in the ccs is v160 for c2820 whereas we are using v210 of ccs in f28377s. The code running shows error of non compatibility. Any suggestion or the required file in case if u have would be highly appreciated.
  • KUNAL DAS said:
    The issue is that the IQmath.lib used in the ccs is v160 for c2820 whereas we are using v210 of ccs in f28377s. The code running shows error of non compatibility. Any suggestion or the required file in case if u have would be highly appreciated.

    I will move this thread to the C2000 forum. The experts there will be best able to help you with this compatibility issue.

    Thanks

    ki

  • Is the "unresolved symbols" error the one you're referring to? I don't see where the IQmath .lib file is being pulled in in your linker options. Do you have it added to your project?

    I'm not sure what incompatibility you're referring to. The v160 is the version for the IQMath library and the v210 is the version of the F28377S device support. They're two different products within controlSUITE. Their version numbers don't need to match to be compatible.

    Whitney
  • Hi Whitney,

    If you notice in the code for example posspeed.h file.. in the declaration one value is set to 16776 and assigned to mechanical scaler with count value of 4000 por. In our case our encoder is of 2000ppr. We are not able to understand how the conversion works. Could you help us?

    Thanks

  • Did you fix your linker error that you mentioned above?

    There's a comment in Example_posspeed.h that says mech_scaler is "0.9999/total count...(Q26)," so it's something like 16776 = .9999 / 4000 * (2 ^ 26)

    Whitney