Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

delay problem in lpc1768

Status
Not open for further replies.

karthik chandra

Newbie level 5
Joined
Jul 10, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
69
im calculating delay for 1sec using timer 0, but im getting delay of 500ms
im using 12Mhz external crystal
Code:
#include "lpc17xx.h"
void delayMs(uint32_t delayInMs)
{
	LPC_TIM0->TCR = 0x02;		/* reset timer */
	LPC_TIM0->PR  = 0x00;		/* set prescaler to zero */
	LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
	LPC_TIM0->IR  = 0xff;		/* reset all interrupts */
	LPC_TIM0->MCR = 0x04;		/* stop timer on match */
	LPC_TIM0->TCR = 0x01;		/* start timer */
  
	/* wait until delay time has elapsed */
	while (LPC_TIM0->TCR & 0x01);
}
int main(void)
{
	SystemInit();
	LPC_GPIO0->FIODIR |= 0x00000010;
	while(1)
	{
		LPC_GPIO0->FIOSET |= 0x00000010;
		delayMs(1000);
		LPC_GPIO0->FIOCLR |= 0x00000010;
		delayMs(1000);
	}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top