Timer delay problems

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

Timer delay problems

817 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JohnBurton on Wed Jul 07 06:11:55 MST 2010
Hello, I've just started experimenting with an LPCXpresso board with an LPC1434 chip on it and mostly it's going well.

However I'm having a little problem with delays and timers and wondered if anyone could see what I'm doing wrong?

In the sample code I found a file timer16.h which has a delay_microseconds in it which uses a 16 bit timer to perform the delay. I'm calling it like this

#include "timer16.h"

//
// Simple delay of approx ms milliseconds
// Can't delay for very long, so do lots of shorter delays instead
//
void delay_ms(int ms)
{
ms = ms * 10;

while(--ms) {
// Delay for a total of 100uS
delay_microseconds(0, 25);
delay_microseconds(0, 25);
delay_microseconds(0, 25);
delay_microseconds(0, 25);
}
}


If I call delay_ms(1000) I get a delay of only a short delay and not even close to 1s. All delays are similarly short.  I realise this isn't going to be accurate, and I realise there are better ways to use the timer but it concerns me that this doesn't work for me as clearly there is something I don't understand.

Am I calling this function correctly? Is there anything I need to explicitly initialize first such as timer hardware or the system clock?

Any thoughts would be welcome
0 Kudos
Reply
2 Replies

734 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JohnBurton on Thu Jul 08 03:33:26 MST 2010
Thanks, I've looked some more at the examples, and the data sheets and got it all to work.
0 Kudos
Reply

734 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jul 07 07:36:44 MST 2010
There were some minor issues with regards to early versions of timer16 based examples. If you want to make use of one or more timers, I would suggest making sure that you have the latest LPCXpresso IDE installed (v3.4) and then looking at the following examples:


[LIST]
[*]LPCXpresso1343_blinky - for timer16
[*]LPCXpresso1343_timer32 - for timer32
[*]LPCXPresso1343_systick - for system timer
[/LIST]
from:

<IDE_Install_Dir>\Examples\LPC1000\LPC13xx\LPCXpresso1343.zip

The system timer is probably the easiest to set up and make use of.

Regards,
CodeRedSupport
0 Kudos
Reply