lpcware

Problem in timer 32 code

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by aamir ali on Sun Jan 06 04:31:33 MST 2013
I wrote code fro MAT0 & MAT1 if imer32. At match of MR1 timer there will be int only while at MAT0 match timer will be rest & TC will be zero.
In int routine I set two diff pins.Problems is both pins gets sets & clear at same time.


volatile uint32_t timer_int_reg =0;

void CT32B0_IRQHandler(void)
{
    timer_int_reg = LPC_CT32B0->IR;
   
    if(timer_int_reg & 0x02 == 0x02)
    {
        LPC_CT32B0->IR = 0x02;   /* Clear MAT0.1 MATinterrupt flag */
            LPC_GPIO->NOT[0] = 0x00040000; 

    }
   
    if(timer_int_reg & 0x01 == 0x01)
    {
            LPC_CT32B0->IR = 0x01;   /* Clear MAT0.0 MATinterrupt flag */
            LPC_GPIO->NOT[0] = 0x00080000; 

    }   
   

   


}



int main(void)
{
    LPC_IOCON->PIO0_18 = 0x00000080;               // pin for checking timings
    LPC_GPIO->DIR[0] |= 0x00040000; 
   
    LPC_IOCON->PIO0_19 = 0x00000080;               // pin for checking timings
    LPC_GPIO->DIR[0] |= 0x00080000; 

    NVIC_SetPriority(CT32B0_IRQn,0);          /* Default priority group 0, can be 0(highest) - 31(lowest) */
    NVIC_EnableIRQ(CT32B0_IRQn);           /* Enable 32-bit Timer0 (CT32B0) Interrupt */

   
    LPC_SYSCON->SYSAHBCLKCTRL  |= (1<<9);         //enable clock
    LPC_CT32B0->TCR = 0x02;     /* reset timer */
    LPC_CT32B0->PR  = 99;                   //prescaler value
LPC_CT32B0->MR0 = 18000;               //Total delay = MR0 * (PR + 1) * Inst cycle , i.e 0x1c20 * (99+1) * (1/72Mhz)
    LPC_CT32B0->MR1 = 7200;
LPC_CT32B0->IR =  0x003f;            //disable interrupt initially
    LPC_CT32B0->MCR = 0x0003 | 0x08;          //reset on match i.e TC will be zero, & interrupt on match
     LPC_CT32B0->TCR = 0x01; 
   
  

 
    while(1)
    {
        __NOP();
        //if(me > 1000)
          //  LPC_CT32B0->TCR = 0x00;
   
    }
}

Outcomes