Problems with multiple interrupts

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

Problems with multiple interrupts

1,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lennyk87 on Sat Sep 29 06:17:20 MST 2012
Hey guys,

i've got a problem with timer interrupts. I use the OneWire-bus implementation of this post http://knowledgebase.nxp.com/showpost.php?p=5896&postcount=20 to read my DS18S20. It works fine until I try to use a second timer to generate a 300kHz Signal that calls an interrupt.

Here's my code for the 300kHz-timer:

void timer_init(void) {

    /* disable timer */
    LPC_TMR16B0->TCR = 0;

    /* External Match Register 
     */
    LPC_TMR16B0->EMR = (1<<6)|(1<<1);

    /* Outputs */
    LPC_IOCON->PIO0_9 = 1<<1;

    /*
     * 1 -> PWM for EM1
     */
    LPC_TMR16B0->PWMC = 1<<1;

    LPC_TMR16B0->MR3 = 160; // 300kHz
    LPC_TMR16B0->MR1 = 80; // 50% PWM

    LPC_TMR16B0->MCR = (1<<10) | (1<<9);

    /* start timer */
    LPC_TMR16B0->TCR = 1;

    /* enable interrupt */
    NVIC_EnableIRQ(TIMER_16_0_IRQn);
}

void TIMER16_0_IRQHandler(void) {
    /*
     * just to test
     */
    if(LPC_TMR16B0->IR & (1<<3)) {
        LPC_TMR16B0->IR |= (1<<3);
    }

}
The interrupt works, if I don't use the second timer of the One-Wire-bus implementation. The other way round, the One-Wire-bus works, if I don't use the 300kHz-timer. I've also got a third interrupt for an UART. The UART stops working if I use both but works if I only use one of the other interrupts.

I hope you can help me, I'm running out of ideas what the error could be.

Greetings,
Lenny.
0 Kudos
Reply
6 Replies

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Sep 30 08:16:41 MST 2012

Quote:

I hope I gave you enough information now...

Yes, that's enough :confused: Now I know that you don't use the original linked sample, your timer code is different from timer code above and you're not answering my questions :rolleyes:

And it's enough to show that you don't know how NVIC works I would guess that your code suffers from Tail Chaining :eek: A simple change of Priority would show that:

 NVIC_SetPriority(TIMER_16_0_IRQn,1);
0 Kudos
Reply

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lennyk87 on Sun Sep 30 03:58:28 MST 2012
Hi, I'm sorry my posts were so sketchy.

I use the interrupts to count the PWM cycles and toggle one pin after 30 cycles (I need kind of a burst mode). Plus I need to toggle another Pin after another number of cycles. Thats realised by a switch case statement.

If I don't use the interrupt, everything works fine. Note that it doesn't even work with an empty interrupt routine (and interrupt enabled).

I hope I gave you enough information now, sorry again.
0 Kudos
Reply

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Sep 30 03:35:13 MST 2012
Ahh, it's a christmas guessing game :)

So week 2 :D

#1 Why do you use interrupts to generate a PWM and what is happening if you generate your PWM without Interrupt?

#2 How did you set your Interrupt Priorities?
0 Kudos
Reply

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lennyk87 on Sun Sep 30 02:27:16 MST 2012
I'm using TMR16B1 for the onewire-bus of course :P Sorry, I didn't mention that.

It doesn't work anyway...
0 Kudos
Reply

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Sat Sep 29 10:46:54 MST 2012
Kayoda is right. Using TIMER16B0 for both one wire implementation and simultaneously for 300Khz frequency generation is not safe design practice.
One easy solution is to try to use the any other unused timers such as TIMER16B1 to generate your frequency in your application.:)

Or even better you could use something like an analog temperature sensor like LM35...which also unfortunately requires only one pin....;)
0 Kudos
Reply

994 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sat Sep 29 07:10:40 MST 2012
Don't know what you are trying to do but using this timer while onewire is using it and changing MCR registers several times doesn't look like a really good idea ;)
0 Kudos
Reply