chipKIT® Development Platform

Inspired by Arduino™

Issue OC1 interruptions in mode Compare event toggles

Created Wed, 12 Nov 2014 21:58:23 +0000 by PICedh


PICedh

Wed, 12 Nov 2014 21:58:23 +0000

Hello,

I have loaded the following code into a Uno32 in order to test interrupts based on OC1 defined as Compare event toggles.

it seems that the interrupt is never raised as I dont see the led blinking

Could someone explain what is wrong

Thanks

#include <plib.h>


void setup()
{ 
 // Initialization TIMER2
  T2CON = 0x0000 ;  // 0x0000=0000000000000000 
  		    // ON=0 (Timer is disable for now)
                    // FRZ=0 (Continue operation even when CPU is in Debug Exception mode)
                    // SIDL=0 (Continue operation even in Idle mode)
                    // TGATE=0 (Gated time accumulation is disabled) 
                    // TCKPS=000 (prescale value updated below)
                    // T32=0 (TMRx and TMRy form separate 16-bit timer)
                    // TCS=0 (Internal peripheral clock) 
  T2CONbits.TCKPS =  0;   //TCKPS= prescale value CPU clock = 80 MHz => Period : prescale value/80Mhz = prescale value/80 000 000                                              
                                           //111 = 1:256 prescale value
                                           //110 = 1:64 prescale value
                                           //101 = 1:32 prescale value
                                           //100 = 1:16 prescale value
                                           //011 = 1:8 prescale value
                                           //010 = 1:4 prescale value
                                           //001 = 1:2 prescale value
                                           //000 = 1:1 prescale value

  PR2 = 50000;  // TIMER2 Period = (50000+1)* prescale value/80 000 000  seconds
        
  // Configure the control register OC1CON for the output compare channel 1
  OC1CON = 0x0000; // clear OC1
  OC1CONbits.OCTSEL = 0; // Select Timer 2 as output compare time base
  OC1CONbits.OCM = 0b011; // OCM=011: Compare event toggles OCx pin

  // Configure the compare register OC1R for the output compare channel 1
  OC1R = 50000;  // set initial cycle in counts
  
     
  // Configure int 
  IFS0CLR = 0x0040; // Clear the OC1 interrupt flag 
  IEC0SET = 0x040; // Enable OC1 interrupt 
  IPC1SET = 0x001C0000; // Set OC1 interrupt priority to 7
  IPC1SET = 0x00030000; // Set Subpriority to 3, maximum
   
  // Enable Timer 2 and OC1              
  T2CONSET =  0x8000; // Enable Timer2
  OC1CONSET = 0x8000; // Enable OC1
  
  pinMode(13, OUTPUT);
      
}

void loop()
{
}

extern "C"
{

void __ISR(_OUTPUT_COMPARE_1_VECTOR,ipl7) OC1_IntHandler(void)   
  {    
      digitalWrite(13, 1);
      delay (100);
      digitalWrite(13, 0);
      delay (100);
    // Clear interrupt flag
         IFS0CLR = 0x0040;  

 

  }
}