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/TMDSDOCK28335: Instead of running the command u2k = DCL_runDF22_C2(&controller2, ek); Why it is entering into ILLEGAL_ISR(void) ?

Part Number: TMDSDOCK28335
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE

Tool/software: Code Composer Studio

Dear Expert,

I am trying to run the boost converter in closed loop voltage control mode using DF22 controller. By placing breakpoints at various lines I have observed that the program is entering into ILLEGAL_ISR(void) just before executing the line 

u2k = DCL_runDF22_C2(&controller2, ek);

What are the probable reasons behind this and how to overcome this problem ?

I am attaching the main() code for your reference.

N.B.- I am using Digital Control Library version 3.0 (DCL v3.0) for the controller section.

Thanks in advance.

Regards,

Soumya.

//###########################################################################
// $TI Release: F2833x/F2823x Header Files and Peripheral Examples V142 $
// $Release Date: November  1, 2016 $
// $Copyright: Copyright (C) 2007-2016 Texas Instruments Incorporated -
//             http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include "DCL.h"
#include "DCLF32.h"
#include "DCL_fdlog.h"

// Prototype statements for functions found within this file.
__interrupt void adc_isr(void);
 void InitEPwm2Example(void);
#define DATA_LENGTH 1601

// global  variables
long IdleLoopCount = 0;
long IsrCount = 0;
//float u1k;
float u2k =0;
float dk;
float upperLim;
float lowerLim;
uint16_t v;
DCL_DF22 controller1 = DF22_DEFAULTS;
DCL_DF22 controller2 = DF22_DEFAULTS;
int vadc=0;
// FDLOG eBUf = FDLOG_DEFAULTS;
 int out=0;
// Global variables used in this example:
// Uint16 ConversionCount;
float rk = 0.4199f * 4096;
float ek;
float yk;
int d1=0, d2=0, x=2, y=3, d3=0;
main()
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.

    InitSysCtrl();
   DINT;
   InitEPwm2Gpio();
    /*.............................ADC_BLOCK..........................*/
   EALLOW;
   #if (CPU_FRQ_150MHZ)     // Default - 150 MHz SYSCLKOUT
     #define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3)   = 25.0 MHz
   #endif
   #if (CPU_FRQ_100MHZ)
     #define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2)   = 25.0 MHz
   #endif
   EDIS;

   // Define ADCCLK clock frequency ( less than or equal to 25 MHz )
   // Assuming InitSysCtrl() has set SYSCLKOUT to 150 MHz
   EALLOW;
   SysCtrlRegs.HISPCP.all = ADC_MODCLK; // High Speed Periphal clock set to 25 MHz
   EDIS;

// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
   InitGpio();  // Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts


// 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 DSP2833x_PieCtrl.c file.
   EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
      EDIS;
           InitEPwm2Example();
        EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    EDIS;

   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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_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 register
   PieVectTable.ADCINT = &adc_isr;
   PieVectTable.TINT0 = &adc_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   InitAdc();  // For this example, init the ADC

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

// Enable ADCINT in PIE
   PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
   IER |= M_INT1; // Enable CPU Interrupt 1
   EINT;          // Enable Global interrupt INTM
   ERTM;          // Enable Global realtime interrupt DBGM

   v = 0;
  // Configure ADC
   AdcRegs.ADCTRL1.bit.ACQ_PS = 0x2;
   AdcRegs.ADCTRL1.bit.CPS = 0x1;
   //AdcRegs.ADCTRL3.bit.ADCCLKPS = 0x1;
   AdcRegs.ADCMAXCONV.all = 0x0000;       // Setup 2 conv's on SEQ1
   AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA0 as 1st SEQ1 conv.
   //AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA1 as 2nd SEQ1 conv.
   AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
   AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // Enable SEQ1 interrupt (every EOS)
   AdcRegs.ADCTRL3.bit.SMODE_SEL = 1;

// Assumes ePWM1 clock is already enabled in InitSysCtrl();
   EPwm1Regs.ETSEL.bit.SOCAEN = 1;        // Enable SOC on A group
   EPwm1Regs.ETSEL.bit.SOCASEL = 2;       // Select SOC from from CPMA on upcount
   EPwm1Regs.ETPS.bit.SOCAPRD = 1;        // Generate pulse on 1st event
   EPwm1Regs.CMPA.half.CMPA = 0x08FF;     // Set compare A value
   EPwm1Regs.TBPRD = 0x0FFF;              // Set period for ePWM1
   EPwm1Regs.TBCTL.bit.SYNCOSEL = 0x01;
   EPwm1Regs.TBCTL.bit.CTRMODE = 0;       // count up and start

   // configure CPU timer 0
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0, 90.0, 1.0e+03);

    // initialise full controller
    controller1.a1 = -1.619f;
    controller1.a2 = 0.619f;
    controller1.b0 = 0.004115f;
    controller1.b1 = 7.841e-7f;
    controller1.b2 = -0.004114f;

    // Initialize Pre-computed controller
    controller2.a1 = controller1.a1;
    controller2.a2 = controller1.a2;
    controller2.b0 = controller1.b0;
    controller2.b1 = controller1.b1;
    controller2.b2 = controller1.b2;

    // clamp limits
    upperLim = 4096.0f;
    lowerLim = 0.0f;

    // enable interrupts
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    IER |= M_INT1;
    EINT;
    StartCpuTimer0();
    // idle loop
    while(1)
    {
        IdleLoopCount++;
    }

} // end of main



__interrupt void  adc_isr(void)
{
    // clear timer flag & acknowledge interrupt
        CpuTimer0Regs.TCR.bit.TIF = 1;
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

        // read data & run controllers
            // read input data
              yk = ((float) AdcMirror.ADCRESULT0);
              ek = rk - yk;
            // run pre-computed controller
            u2k = DCL_runDF22_C2(&controller2, ek);
            out = (int) u2k;
            EPwm2Regs.CMPA.half.CMPA = (out) ;
               EPwm2Regs.AQCTLA.bit.CAD = AQ_SET;             // Set PWM1A on Zero
               EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
             // Clear INT flag for this timer
              EPwm2Regs.ETCLR.bit.INT = 1;
            // Acknowledge this interrupt to receive more interrupts from group 3
             PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
            v = DCL_runClamp_C1(&u2k, upperLim, lowerLim);
            if (0 == v)
            {
               DCL_runDF22_C3(&controller2, ek, u2k);
            }
        IsrCount++;


 if(IdleLoopCount==0)
 {
  if(v == DATA_LENGTH)
  {
     v = 0;
     IdleLoopCount=1;
  }
  else
  {
      vadc = (AdcRegs.ADCRESULT0 >>4)  ;
      v++;

  }

  }
  // Reinitialize for next ADC sequence
  AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;         // Reset SEQ1
  AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;       // Clear INT SEQ1 bit
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE
  return;
}

 void InitEPwm2Example()
{
   // Setup TBCLK
   EPwm2Regs.TBPRD = 750;           // Set timer period 801 TBCLKs
   EPwm2Regs.TBPHS.half.TBPHS = 0x0000;           // Phase is 0
   EPwm2Regs.TBCTR = 0x0000;                      // Clear counter
   // Set Compare values
   EPwm2Regs.CMPA.half.CMPA = out;     // Set compare A value old data 1953
   // Setup counter mode
   EPwm2Regs.TBCTL.bit.CTRMODE = 0; // Count up
   EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
   EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1;       // Clock ratio to SYSCLKOUT
   EPwm2Regs.TBCTL.bit.CLKDIV = 0;
   EPwm2Regs.TBCTL.bit.SYNCOSEL = 0x00;

   // Setup shadowing
   EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
   EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
   EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  // Load on Zero
   EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;


   // Set actions
   EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;             // Set PWM2A on event A, up count
   EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;           // Clear PWM2A on event A, down count
}

  • Hi Soumya,
    I think I responded to your post before...may be I am mistaken. As advised, would you please step through the code and see if you can narrow down to a smaller portion of the application where this problem occurs. The first occurrence of: u2k = DCL_runDF22_C2(&controller2, ek); is in the adc interrupt.
    Do you see the issue immediately upon entry into the interrupt? What if you disable the interrupt? If you do not see the problem when single stepping, can you run through smaller portions of the application and narrow down the problem to a fewer set of instructions? Does the initialization successfully and consistently complete without issues?
    Please provide some more details...
    Thanks,
    Krishna
  • Sir,
    I have tried everything .
    Just before the execution of the line , it is entering into Illegal ISR.
    Now I have removed the adc_isr programme (i.e commented out the lines 101 and 102 in the above programme), then it is not entering into the Illegal ISR.
    So the problem seems to be in the controller part.
    Please help in the particular mater.
    Regards,
    Soumya.
  • Hi Soumya,
    Thanks for the follow up. It is good that you narrowed down the problem to the ISR. This means all the initialization is most likely good...I am guessing this has to do with the mapping of the ADC interrupt to the right vector. Can you check to be sure that this mapping is correct?
    Thanks,
    Krishna
  • Hi Soumya,
    Are you still seeing issues or is the problem resolved?
    Thanks,
    Krishna
  • Dear Sir,
    Thank you for your suggestions.
    I have used the ADC part, the DF22 controller part and the EPwm2 to produce the pulse, which is to be supplied to the boost converter.
    What should be the suitable mapping for this purpose?
    And Please go through the adc_isr() subroutine, as the program is entering into ILLEGAL_ISR(void) just before executing the line
    u2k = DCL_runDF22_C2(&controller2, ek);

    Please suggest the suitable way.
    Regards,
    Soumya.
  • Hi Soumya,

    Please check the following two things:
    1. Comment out the line 164, that enables interrupts. Recompile and run. Do you still see the problem? I expect that you will not. Please confirm.
    2. Put that instruction back in and now set a breakpoint on the first instruction in the ISR. In your attached code, that is line 179.
    I expect that you will not hit that breakpoint...not sure...please confirm one way or the other.

    Thanks,
    Krishna
  • Sir,
    Here I am answering point by point.
    1) Doing as per your instruction, I commented out line 164 i.e. EINT; . However the code is entering into adc_isr and running into the ILLEGAL_ISR. I think it is because the address of adc_isr is loaded into both ADCINT and TINT0 lines. We disabled only the ADCINT line but the TINT0 line was active (Please refer lines 101 and 102 in the attached code).

    2) Commenting in the line 164, and placing a break point at the first line of adc_isr (line 179), still the code is hitting the break point.

    Regards,

    Soumya.
  • Hi Soumya,
    Ok, I see that the interrupts are being enabled twice; once on line 115 and again on 164. What is purpose of doing that?
    Secondly, what is the intention behind the following:
    PieVectTable.ADCINT = &adc_isr; --- From Line 101
    PieVectTable.TINT0 = &adc_isr; --- From Line 102
    Thanks,
    Krishna
  • Sir,
    I have tried doing both the options alone. Like,
    First, I have commented out the line 101 and it's corresponding lines 113,114,115
    Secondly, I have commented out the line 102 and it's corresponding lines 162,163,164 (while commenting in 101,113,114,115).
    In both the cases, program is entering into the ILLEGAL_ISR(void).
    Please go through the Controller part as it seems to be the troubling one.
    Also we had checked using BPs inside the adc_isr() that the code is entering into ILLEGAL_ISR(void) just at the point of controller action. (line 187).
    Regards,
    Soumya.
  • Sir,
    I have created a new project including all the files (header and source) from C2000ware and Now it is not entering into ILLEGAL_isr mode. Previously I think I have added some files from C2000 ware and some from ControlSuite. Still my Project is not working as it should?
    I am opening a new thread for that.
    Regards,
    Soumya.