This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

17xx timer

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.

Parents
  • This line is incorrect - not what the text in the processor user manual tells you to use:

    LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
    

    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...

Reply
  • This line is incorrect - not what the text in the processor user manual tells you to use:

    LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
    

    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...

Children
  • 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.