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.

Counting rising/falling edge interrupts (F28027F) Illegal ISR



Firstly, and importantly, this is for an instaSPIN application. InstaSPIN forums suggest I try my luck here....

I am trying to 'read' 50Hz, 1-2ms (high) PWM to use as the torque set-point for instaSPIN. I have already written some code to do this on my F28027 Launch and I am now trying to port it to instaSPIN. Step one of this is to trigger the ISRs, I have two separate ISRs being triggered from the rising / falling edge of GPIO12 (HW is DRV8301BOOST) which I *believe are setup correctly... When GPIO12 changes state (i.e. either rising or falling edge) my code gets caught by the illegal_ISR routine... I have done some research on this and it seems that it may be the stack getting 'lost' - not enough memory dedicated so I tried to increase from 0x200 (default) to 0x280, the largest I could go without rewriting the linker (which I'm not game to do without some advice on memory locations first) but this obviously didn't work.

*I have also stepped through my program and it is definitely falling over when the interrupt is triggered... If I leave GPIO12 floating I can spin the motor and everything plays nicely. 

My code, (added to a clean copy of lab05a.c - below is the only change from stock lab05a)

In drv.c I have added:

Enable interrupts

void DRV_enableRCInts(DRV_Handle handle) //PF
{
  DRV_Obj *obj = (DRV_Obj *)handle;

  PIE_setExtIntPolarity(obj->pieHandle, CPU_ExtIntNumber_1, PIE_ExtIntPolarity_RisingEdge);
  PIE_setExtIntPolarity(obj->pieHandle, CPU_ExtIntNumber_2, PIE_ExtIntPolarity_FallingEdge);

  PIE_enableExtInt(obj->pieHandle, CPU_ExtIntNumber_1);
  PIE_enableExtInt(obj->pieHandle, CPU_ExtIntNumber_2);

  CPU_enableInt(obj->cpuHandle, CPU_IntNumber_1);

}

Setup GPIO12:

  // No Connection
  GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_GeneralPurpose);
  /////////////////////////////////////PF///////////////////////////////////////////////////
  GPIO_setDirection(obj->gpioHandle, GPIO_Number_1, GPIO_Direction_Input);
  GPIO_setQualification(obj->gpioHandle, GPIO_Number_1, GPIO_Qual_Sample_6);//GPIO_Qual_Sync);

  GPIO_setExtInt(obj->gpioHandle, GPIO_Number_12, CPU_ExtIntNumber_1);
  GPIO_setExtInt(obj->gpioHandle, GPIO_Number_12, CPU_ExtIntNumber_2);
  ///////////////////////////////////////////////////////////////////////////////////////

And in DRV.h I have:

define interrupts:

// **************************************************************************
// the globals

extern interrupt void mainISR(void);
extern interrupt void xint1_isr(void);//PF
extern interrupt void xint2_isr(void);//PF

// **************************************************************************

Enable ExtInt

static inline void DRV_initRCIntVectorTable(DRV_Handle handle) //PF
{ DRV_Obj *obj = (DRV_Obj *)handle;
PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;

ENABLE_PROTECTED_REGISTER_WRITE_MODE;

PIE_enableInt(obj->pieHandle, PIE_GroupNumber_1, PIE_InterruptSource_XINT_1);
PIE_enableInt(obj->pieHandle, PIE_GroupNumber_1, PIE_InterruptSource_XINT_2);


DISABLE_PROTECTED_REGISTER_WRITE_MODE;

return;

}

Acknowledge interrupt

static inline void DRV_acqRCInt(DRV_Handle handle) //PF
{
  DRV_Obj *obj = (DRV_Obj *)handle;


  // Acknowledge interrupt from PIE group 1
  PIE_clearInt(obj->pieHandle,PIE_GroupNumber_1);

  return;
}

And, in Lab05a.c I have:

// the globals

volatile uint32_t Xint1Count;//PF
volatile uint32_t Xint2Count;//PF

Clear Count

  Xint1Count=0; //PF
  Xint2Count=0; //PF

Initialize PIE for external interrupt:

  // initialize the interrupt vector table
  DRV_initIntVectorTable(drvHandle);

  //PF
  DRV_initRCIntVectorTable(drvHandle);

  // enable the ADC interrupts
  DRV_enableAdcInts(drvHandle);


  // PF
   DRV_enableRCInts(drvHandle);

  // enable global interrupts
  DRV_enableGlobalInts(drvHandle);

The ISRs:

interrupt void xint1_isr(void)
{
	Xint1Count++;


	//CpuTimer2Regs.TCR.bit.TRB = 1; //Reload Timer
	//CpuTimer2Regs.TCR.bit.TSS = 0; //Start Timer

    // Acknowledge this interrupt to get more from group 1
   // PIE_clearInt(myPie, PIE_GroupNumber_1);
	DRV_acqRCInt(drvHandle);
}

interrupt void xint2_isr(void)
{	Xint2Count++;

//CpuTimer2Regs.TCR.bit.TSS = 1; //Stop Timer
//test = (0xFFFFFF-CpuTimer2Regs.TIM.all)*0.00002; // Read TimerTIMER_getCount(myTimer2);

    // Acknowledge this interrupt to get more from group 1
   // PIE_clearInt(myPie, PIE_GroupNumber_1);
DRV_acqRCInt(drvHandle);
}

This screen shot has some address's in it that I thought might be useful for debugging? 

Thanks for any tips, I've been stuck on what should in essence be very simple for two days now.

PS. to any InstaSPIN devs who see this - assuming I can get this working, how should I be timing the high time of the PWM? I was originally thinking Timer2, but the instaSPIN forums seem to think there may be a better way (PWM ticks)???

  • Hi all,

    Sorry, I'm going to have to try and keep this thread alive (I'm desperate)...

    Update:

    I don't think my problem is related to the stack size - moved to lab01 (instaSPIN FOC) and doubled the stack size which made no difference.

    Certain that the interrupt is triggering... By disallowing interrupts in the register watcher I can see the interrupt trigger. e.g. - With xint3... I can set PIEIEFR12 (PIE,INT12 Group Enable Register) to 0x00 which disallows the interrupt, then if I put a rising edge on GPIO12, I can see PIEIFR12 (PIE, INT12 GROUP FLAG REGISTER) go to 0x001; no problems... of course I have to manually clear the interrupt and add to the count - exhausting keeping up with rising edges at 50Hz so I would like this to happen automatically :) .... When I allow the interrupt again I get caught in PIE_illegalIsr....

    Thanks, I'd really appreciate some help on this, even advice on what I should be doing to debug this further.... I am truly stuck!

    PIE registers when I hit PIE_illegalIsr trap...

  • Hello Patrick,

    I am wondering, did you already assign the isr functions of your external interrupts (XINT1 and XINT2) to pie?

    For example, in drv.h of original proj5a, there is   pie->ADCINT1 = &mainISR; to assign mainISR function to ADC interrupt.

    static inline void DRV_initIntVectorTable(DRV_Handle handle)
     {
      DRV_Obj *obj = (DRV_Obj *)handle;
      PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;


      ENABLE_PROTECTED_REGISTER_WRITE_MODE;

      pie->ADCINT1 = &mainISR;

      DISABLE_PROTECTED_REGISTER_WRITE_MODE;

      return;
     } // end of DRV_initIntVectorTable() function

    So in your case, i think it should be:


    pie->XINT1 = &xint1_isr;

    pie->XINT2 = &xint2_isr;

     

    Also I am wondering, whether these lines are mistyped or not:

    GPIO_setDirection(obj->gpioHandle, GPIO_Number_1, GPIO_Direction_Input);
    GPIO_setQualification(obj->gpioHandle, GPIO_Number_1, GPIO_Qual_Sample_6);//GPIO_Qual_Sync);

    The bold words should be GPIO_Number_12, aren't they?

    Hope you can find the solution soon!

    Best regards,

    Maria

  • Hi, Maria,

    Thank you for having a look at this... it is killing me!

    Maria Todorova said:
    I am wondering, did you already assign the isr functions of your external interrupts (XINT1 and XINT2) to pie?

    Yes, I have done this...

    In my original post, I have:

    static inline void DRV_initRCIntVectorTable(DRV_Handle handle) //PF
    { DRV_Obj *obj = (DRV_Obj *)handle;
    PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;
    
    ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
    PIE_enableInt(obj->pieHandle, PIE_GroupNumber_1, PIE_InterruptSource_XINT_1);
    PIE_enableInt(obj->pieHandle, PIE_GroupNumber_1, PIE_InterruptSource_XINT_2);
    
    
    DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
    return;
    
    }

    Which I believe has exactly the same effect as:

    pie->XINT1 = &xint1_isr;

    pie->XINT2 = &xint2_isr;

    In any case, I have also tried &xintX_isr but it makes no difference, still get caught in PIE_illegalISR...

    Re the GPIOs, good eye, this is just left over from when I tried a different GPIO, my current code is based off GPIO12. i.e.:

    // No Connection
    GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_GeneralPurpose);
    /////////////////////////////////////PF///////////////////////////////////////////////////
    GPIO_setDirection(obj->gpioHandle, GPIO_Number_12, GPIO_Direction_Input);
    GPIO_setQualification(obj->gpioHandle, GPIO_Number_12, GPIO_Qual_Sample_6);//GPIO_Qual_Sync);
    
     
    GPIO_setExtInt(obj->gpioHandle, GPIO_Number_12, CPU_ExtIntNumber_1);
    GPIO_setExtInt(obj->gpioHandle, GPIO_Number_12, CPU_ExtIntNumber_2);
    ///////////////////////////////////////////////////////////////////////////////////////

    - It is the same problem regardless of the GPIO set....

    Thanks

  • Hi Maria,

    I thought I should let you and anyone else who reads this know that there really was no problem at all to begin with. Well, there was a problem, but by the time I posted this it was solved - the code posted should work - save a few things that Maria has already pointed pointed out..

    The real problem is that in CCS if you have multiple tabs open at a time ( I have lab01, DRV.C and Drv.h for example) and you edit one and then move off it to another tab, the builder does not actually save all of the edits... Because I was not manually hitting ctrl s on each tab after editing, I was actaully building the exact same version each time...

    Is there somewhere I can report this? (Just wasted 3 days because of it!)

    Thanks - now on to timing the pulse.

  • Is there somewhere I can report this? (Just wasted 3 days because of it!)

    If you really feel that such an option should be automated then you can report it over here:

    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81.aspx

    Regards,

    Gautam

  • Hello Patrick,

    I think you are not using CCS5.5 because in my experience, when I use CCS5.5 the unsaved file in the project will be saved automatically.

    In CCS5.4, I don't experience this, I need to save the unsaved file manually.

    So if you want, you can upgrade your CCS version to be 5.5.

    Have nice days!

    Best regards,

    Maria