LPC 1114 Interrupt and PWM on the same timer?

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

LPC 1114 Interrupt and PWM on the same timer?

883 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NsN on Mon May 24 17:12:14 MST 2010
Hi, i was wondering if it is possible to use Match2 on Timer16_0 to generate an interrupt, while Match_0 and Match_1 are used for PWM outputs?  Alternatively I could also adjust the PWM frequency, if it would be possible to generate an Interupt on Match3 before it resets the TC.  I tried it, but sofar everything has resulted in Match_0 and Match_1 being always high.  My initialization is:

       LPC_TMR16B0->TCR = 0;
        //prescale to so the TC increments every 0.05ms
        LPC_TMR16B0->PR = 200;

        LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);

        /* Setup the external match register */
        LPC_TMR16B0->EMR = (1<<10)|(0<<8)|(1<<6)|(1<<4)|(1<<3)|(0x05);

        LPC_IOCON->PIO0_8           &= ~0x07;
        LPC_IOCON->PIO0_8           |= 0x02;        /* Timer0_16 MAT0             */
        LPC_IOCON->PIO0_9           &= ~0x07;
        LPC_IOCON->PIO0_9           |= 0x02;        /* Timer0_16 MAT1             */

        /* Enable the selected PWMs and enable Match3 */
        LPC_TMR16B0->PWMC = 0x08 || 0x02 || 0x01;

        /* Setup the match registers */
        LPC_TMR16B0->MR3 = 1024;
        LPC_TMR16B0->MR0 = 512;
        LPC_TMR16B0->MR1 = 512;
        LPC_TMR16B0->MR2 = 1000;

        /* Set the match control register */
        LPC_TMR16B0->MCR = (1<<10) || (1 << 6);                /* Reset on MR3, Interrupt on MR2 */

        /* Enable the TIMER1 Interrupt */
        NVIC_EnableIRQ(TIMER_16_0_IRQn);
        LPC_TMR16B0->TCR = 1;
Using breakpoints, i can see, that the Interrupt gets triggered, but the pwm won't work.
If I use
LPC_TMR16B0->MCR = (1<<10);
instead the pwm works, but of course i don't have an interrupt anymore...
0 Kudos
Reply
2 Replies

811 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Mon May 31 03:12:00 MST 2010
Hi NsN,
Did it solve your problem?

Kind regards,
0 Kudos
Reply

811 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Wed May 26 02:13:22 MST 2010
Hi NsN,
First thing that I noticed is that you use a double OR --> || in stead of a single OR --> |. A double OR will put the logical [B]test[/B] outcome in the register, so only a 1 or a 0.

/* Enable the selected PWMs and enable Match3 */
LPC_TMR16B0->PWMC = 0x08 | 0x02 | 0x01; 

instead of 
/* Enable the selected PWMs and enable Match3 */
LPC_TMR16B0->PWMC = 0x08 || 0x02 || 0x01;

and

/* Set the match control register */
LPC_TMR16B0->MCR = (1<<10) | (1 << 6);

instead of
/* Set the match control register */
LPC_TMR16B0->MCR = (1<<10) || (1 << 6);


This will probably solve your problem.

Kind regards,
0 Kudos
Reply