10 years, 5 months ago.

the delay function which i have written is not making my led blink can anyone suggest me way.....

<<code>>

  1. define PRESCALAR 25000 (asuming 25mhz so that (25000/25mhz)= 1 msec

Serial pc(USBTX, USBRX);

DigitalOut myled(LED1);

void pclock() {

LPC_SC->PCONP|=(1<<1);/pconp for timer

LPC_SC->PCLKSEL0|=(0<<2);cclk/4

} void inittimer()

{

pc.printf("timer\n");

LPC_TIM0->CTCR|=(0<<0); SELECT TIMER

LPC_TIM0->PR= PRESCALAR-1;/ ASSIGN PRESCALAR

int value=LPC_TIM0->PR;

pc.printf("%d\n",value);

LPC_TIM0->TCR|=(1<<0); enable timer

LPC_TIM0->TCR|=(1<<1);/ RESET TIMER

} void delay ( unsigned int millisec)

{

pc.printf("millisec\n");

LPC_TIM0->TCR|=(1<<1);/n RESET TIMER

LPC_TIM0->TCR|=(1<<0); enable timer

pc.printf("%d\n",LPC_TIM0->TC);

while(LPC_TIM0->TC < millisec);

LPC_TIM0->TCR|=(0<<0); disable timer

pc.printf("disabled\n");

}

int main() {

pclock();

inittimer();

while(1)

{

myled=1;

delay(500);

myled=0;

delay(500);

}

}

Please place your code between <<code>> and <</code>> (on seperate lines), now it is unreadable.

Also what did you try to debug yourself? For example print the value of the timer to see how fast it is increasing.

posted by Erik - 27 May 2014

hi have attached my link pls gothrought it adn help me

posted by Ashok K 27 May 2014

hi erik i have written my code pls check and reply..

posted by Ashok K 27 May 2014

1 Answer

Ashok K
poster
10 years, 5 months ago.

define PRESCALAR 25000 (asuming 25mhz so that (25000/25mhz)= 1 msec
Serial pc(USBTX, USBRX);

DigitalOut myled(LED1);

void pclock() {

LPC_SC->PCONP|=(1<<1);/pconp for timer

LPC_SC->PCLKSEL0|=(0<<2);cclk/4

} void inittimer()

{

pc.printf("timer\n");

LPC_TIM0->CTCR|=(0<<0); SELECT TIMER

LPC_TIM0->PR= PRESCALAR-1;/ ASSIGN PRESCALAR

int value=LPC_TIM0->PR;

pc.printf("%d\n",value);

LPC_TIM0->TCR|=(1<<0); enable timer

LPC_TIM0->TCR|=(1<<1);/ RESET TIMER

} void delay ( unsigned int millisec)

{

pc.printf("millisec\n");

LPC_TIM0->TCR|=(1<<1);/n RESET TIMER

LPC_TIM0->TCR|=(1<<0); enable timer

pc.printf("%d\n",LPC_TIM0->TC);

while(LPC_TIM0->TC < millisec);

LPC_TIM0->TCR|=(0<<0); disable timer

pc.printf("disabled\n");

}

int main() {

pclock();

inittimer();

while(1)

{

myled=1;

delay(500);

myled=0;

delay(500);

}

}

Accepted Answer

Looks like I can't respond anymore with an answer, only with comments. First of all, add <</code>> also at the end, then it gets properly formatted.

What happens if your print the value of LPC_TIM0->TC in the while loop? Then you can see if it increments and how fast. The standard speed is by the way 24MHz with a /4 prescaler (96MHz core frequency). Also doing |= (0<<0) doesn't set a bit to zero, for that you need:

LPC_TIM0->TCR&=~(1<<0);

Edit: That is also directly your issue, from the user manual:

Quote:

When one, the Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero.

Since you are assigning bits with a logical or, it never leaves reset. If you do in the third line of your delay function:

LPC_TIM0->TCR=(1<<0);

It should work. Not it just sets that register to 00000000001. Since the only two bits are reset and enable, that disables the reset and keeps it enabled.

posted by Erik - 27 May 2014

THANK YOU SO MUCH ITS WORKING I DIDN'T KNEW ABOUT THAT OR LOGIC THANK YOU ERIK..

posted by Ashok K 27 May 2014

i modified d code .hi in the above code if i try to print any msg in initpclock and inittimer to check weather it enters the function it dosent get printed but the msg in the main gets printed and code works for blinking , can any one tell me y,

posted by Ashok K 28 May 2014

Assigned to Ashok K 10 years, 5 months ago.

This means that the question has been accepted and is being worked on.