lpcware

LPC1114 Timer resolution issue

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jschimpf255 on Mon Jan 26 11:30:14 MST 2015
Hi,
     I am using the the 32 bit timer03 in the chip with a 48 MHz clock, minimum resolution with a prescale of 1 should be about 20 ns.  I am attempting to generate ticks at about 500 ns. I set it up like this:

Chip_TIMER_Init(LPC_TIMER32_0);

/* Timer rate is system clock rate */
timerFreq = Chip_Clock_GetSystemClockRate();

// Set up for match at 500 ns intervals

Chip_TIMER_Reset(LPC_TIMER32_0);
Chip_TIMER_PrescaleSet(LPC_TIMER32_0, 1);
Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 1);
val = (timerFreq /2000000);// 500.0 nsec = 48,000,000/2,000,000
Chip_TIMER_SetMatch(LPC_TIMER32_0, 1, val);
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 1);
Chip_TIMER_Enable(LPC_TIMER32_0);

/* Enable timer interrupt */
NVIC_ClearPendingIRQ(TIMER_32_0_IRQn);

The match value is 24 which should give me the 500 ns ticks I need.

I am using this in a  program running under FreeRtos. I want to get 4 500 ns ticks to generate a waveform then I disable the timer till I need it again. I start it like this:

Chip_TIMER_Reset(LPC_TIMER32_0);
NVIC_EnableIRQ(TIMER_32_0_IRQn);

It then begins to call an interrupt routine.  In that routine for testing now, I have it turn on GPIO 7 on entrance and then turn it off on exit.

When I run this and observe the GPIO 7 toggles on a scope I cannot get less than about 2.5 micro second period between the toggles. (this is trying all sorts of smaller values than 24 also)  Is there some overhead in FreeRtos should I be using a different timer # or the 16 bit timers ?

Thank you very much for your help.

--jim schimpf







Outcomes