Problem in timer 32 code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem in timer 32 code

673 Views
lpcware
NXP Employee
NXP Employee
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;
    
    }
}

0 Kudos
Reply
3 Replies

619 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Jan 07 04:45:01 MST 2013
The MAT0 interrupt is not enabled in your code, only MAT1 causes interrupt and it looks like both flags are set at that time, so both LEDs are set at that time. The only strange thing is: why interrupt cause flag is set for MAT0 if MAT0 interrupt is not enabled? This is something not described in the manual as far as I remember.
0 Kudos
Reply

619 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by aamir ali on Mon Jan 07 02:54:06 MST 2013
I had checked it earlier. Independently both match registers worked.
But when combioned this don't work. Both pins switch states at same time inspite of diff match value s
0 Kudos
Reply

619 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Sun Jan 06 11:15:34 MST 2013
Use the debugger to examine the value of IR register within interrupt  handler. Verify the values of all the registers you use before enabling  the timer.
I would suggest to start by toggling a single pin using either MR0 or MR1. If it runs fine, then try toggling two pins.
Hope it helps.:)
0 Kudos
Reply