We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello all
i am very new in lpc17xx i want to introduce delay in program of 10ms. can any one give me some examples for lpc1768 .and i also want to know how to calculate MR0 value, is any formula for that??
Thanks in advance.
void LARGE_DELAY ( int chicken ) { do { SMALL_DELAY ( 147 ); if ( chicken != 0 ) chicken = chicken - 1 ; } while ( chicken != 0 ); } void SMALL_DELAY ( int cockroach ) { do { int leaf ; for ( leaf = 0 ; leaf < ( 196 * 2 ) ; leaf = leaf + 1 ) { leaf = leaf + 1; } SMALL_DELAY ( 147 ); if ( cockroach != 0 ) cockroach = cockroach - 1 ; } while ( cockroach != 0 ); }
Don't you think that the manufacturer - NXP - have already given a formula for calculating the MR0 value? Is there some part of the user manual for the processor that you find hard to understand?
SMALL_DELAY ( 147 );
Ah, yes. The very "small" delay. Until next power failure or stack overflow or watchdog reset.
ok thank you for this information ...can you give me a delay program by using timers or any material where i can understand the timer concept. i have one delay code related to timer..
void delayMs(uint8_t timer_num, uint32_t delayInMs) { if ( timer_num == 0 ) { 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 interrrupts */ 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); } else if ( timer_num == 1 ) { LPC_TIM1->TCR = 0x02; /* reset timer */ LPC_TIM1->PR = 0x00; /* set prescaler to zero */ LPC_TIM1->MR0 = delayInMs * (9000000 / 100-1); LPC_TIM1->IR = 0xff; /* reset all interrrupts */ LPC_TIM1->MCR = 0x04; /* stop timer on match */ LPC_TIM1->TCR = 0x01; /* start timer */ /* wait until delay time has elapsed */ while (LPC_TIM1->TCR & 0x01); } return; }
but i not undestand this part..
LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
why they taken ..(9000000 / 1000-1) value.
and in "system_LPC17xx.c" file there is define following things..
#define XTAL (12000000UL) /* Oscillator frequency */ #define OSC_CLK ( XTAL) /* Main oscillator frequency */ #define RTC_CLK ( 32000UL) /* RTC oscillator frequency */ #define IRC_OSC ( 4000000UL) /* Internal RC oscillator frequency */
i tried but not getting delay what they mentioned..and i want to dealy 10ms.....how can i get????when i change the value (9000000 / 1000-1) i get different delay but not exact what i want.
thank you in advance..please reply
www.nxp.com/.../
http://www.lpcware.com/
http://www.keil.com/support/
www.lmgtfy.com
This line is incorrect - not what the text in the processor user manual tells you to use:
You say "they". Who are "they"? Why do you think you can just pick up code from "them" and make use of it without reading the NXP documentation that explicitly tells the meaning of all these fields and how to compute the match register value?
By the way - that -1 in the formula should be there as explained in the user manual. But standard schoolbook math would tell you how to properly use parentheses to get the correct evaluation order of expressions.
Note that when you use the timers, it isn't enough to care about a crystal frequency. Is the PLL used, i.e. what is the actual CCLK frequency? And is the timer run at full CCLK speed or not? Because the timer works based on the PCLK frequency it receives as input. Which is derived from CCLK. Which is derived from your selected oscillator and your optional PLL. All shown quite clearly in the processor user manual.
You really do have to get the routine to invest time in reading. Not in jumping to web forums instantly when you feel you want to know something. People can write huge amounts of code all on their own using the time you spend waiting for answers on web forums. And if you do get an answer on a forum, you will still not understand "why" something is done, and "how" it actually works. So you will not be able to understand how you can modify code to better suit you. You will not even be able to realize exactly how much the processor is able to do, unless you read the documentation.
NXP released the processor together with a user manual just so people would be able to use the processor without getting stuck hoping to find anyone on the net to help. As a matter of fact - there could not bee any people on the net able to help unless they had spent time reading the processor users manual in the first place...
Thank you so much for your response. I appreciate your help.
you are right,i started lpc17xx 3 days before and many things is left to read. we will meet in future.....
As you notice that your times are off from what you want, you should by now have realized that your PCLK is not 9MHz. So your timer do not tick 9000000/1000 = 9000 ticks/ms. So 9000-1 is not the correct value to use for 1ms delay. And 18000-1 is not the correct value to get a 2ms delay.
So you then have two options. Either figure out what PCLK you actually have (takes reading of the code and reading of the user manual). Or decide what PCLK you want and then change the code correspondingly. Which also requires reading of the same processor user manual.