LPC1768 Timer3 use

05 Sep 2010

Hi,

I know that Timer3 (of LPC1768) is used by the mbed library, but if I don't need the mbed library, can I use Timer3 for my own purposes, by writing directly to its registers? I do that with many other peripherals, and they work fine. However, Timer3 does strange things, as if "someone else" was changing the value of some of its registers, once in a while. I have a piezo buzzer connected between MAT3.0 and MAT3.1, and I want to drive it with a variable (audio) frequency signal.

My question: the mbed library writes into the Timer3 registers only once at the beginning, or every once in a while?

Thanks.

05 Sep 2010

Hi Cesar,

We use TIMER3 to generate a 1us tick for use with the mbed libraries, currently used by Ticker, Timer, Timeout and wait (plus potentially others in the future). The first time you use one of these classes/functions, it'll go and setup TIMER3 to a 1us tick. Any subsequent use will only result in a read of the underlying TIMER3.

So, unless you are using any of Ticker, Timer, Timeout or wait, you shouldn't see any modification of these registers. But one thing to consider is that although you may not directly be using it, you may indirectly in some other code that might use them.

Hope this clarifies things. I'd be interested if you could confirm you are getting the behaviour you'd expect, with this additional information.

Simon

06 Sep 2010

Hi Simon,

I include mbed.lib in my project just to get your initialization for the Stack, Heap, PLLs, Flash, etc, but I don't instantiate any class belonging to mbed and I don't call any function belonging to mbed, neither directly nor indirectly, except for:

NVIC_SetPriority()

NVIC_EnableIRQ()

NVIC_DisableIRQ()

(I use my own interrupts)

and yes, I do see that once in a while (right now every approximately 45 seconds, but this could depend on my clock or prescaler settings, I don't know), Timer3 suddenly stops doing what I programmed it to do. Also, what happens every 45 s is NOT a reset. It does not sound like a watchdog issue.

 

Question: Does the mbed library implement any of these interrupt handlers?

- TIMER3_IRQHandler

- WDT_IRQHandler

- SysTick_Handler

- RIT_IRQHandler

- RTC_IRQHandler 

 

Tomorrow I'll try to isolate which register is being modified, by that ghost hand.

Thank you.

06 Sep 2010

Problem solved. It was my fault. The mbed library does NOT modify Timer3 registers once in a while, as I was suspecting (at least, none that it affects me).

I was changing T3.MR0 and T3.MR1 (to generate a signal across MAT3.0 and MAT3.1 with a variable frequency) without resetting T3.TC. Timer3 does NOT have shadow registers for the match registers, so the changes are immediate. If, for example, MR1 is set to reset T3 on match, MR1=300, TC=280, and I change MR1 down to 250, TC will go above 300, it won't be reset at 300, and it will resync again only after overflowing at 2^32-1.

Now I reset T3.TC right after every change to all T3.MRm, and it works beatifully.

Thanks!