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

Problem in Timer

Hi,

I am using lpc1768. By using Timer, i have generated a square wave with time period of 16ms. The ON period should be 1ms and OFF period should be 15ms. I used two match registers MR0 and MR1. I done with MR0 for OFF period and MR1 for ON period. But am getting the signal as 15ms as ON period and 1ms as OFF period. Plz suggest some solutions.

Thank You

Parents
  • Why are you using two match registers but only managing to have your ISR behave as if the timer had just a single match register?

    Don't you recognize that there can be multiple matches (and multiple match interrupts) without any reset in between? Why else would there be an option to configure the chip to reset (or to not reset) the timer on each of the individual match values?

    By the way - driving processor pins from the interrupt means there will always be latencies and jitter involved. The ISR isn't always trigged at exact time when you get a match. And then you spend a number of instructions just to figure out what to do. Match pins can toggle with zero ISR intervention. Match pins can produce that 15ms + 1ms cycle completely without ISR intervention - so the ISR would only be needed if you want your counters incremented.

    Have you actually spent time reading the timer chapter? And look at available sample code? And then returned back and read the timer chapter of the processor users manual a second time?

Reply
  • Why are you using two match registers but only managing to have your ISR behave as if the timer had just a single match register?

    Don't you recognize that there can be multiple matches (and multiple match interrupts) without any reset in between? Why else would there be an option to configure the chip to reset (or to not reset) the timer on each of the individual match values?

    By the way - driving processor pins from the interrupt means there will always be latencies and jitter involved. The ISR isn't always trigged at exact time when you get a match. And then you spend a number of instructions just to figure out what to do. Match pins can toggle with zero ISR intervention. Match pins can produce that 15ms + 1ms cycle completely without ISR intervention - so the ISR would only be needed if you want your counters incremented.

    Have you actually spent time reading the timer chapter? And look at available sample code? And then returned back and read the timer chapter of the processor users manual a second time?

Children
  • First i have done without reset. But its not working...

    Thank You

  • Well, you would normally have one match register produce a interrupt+reset while the other only produces an interrupt.

    And you make MR0 = 15ms and MR1 = 16ms. Or MR0 = 1ms and MR1 = 16ms.

    Then you get a 16ms cycle that either have 1+15 or 15+1 - both alternatives can give the correct output - the only difference is with of the periods it starts with directly when you initialize the timer.

    But in the end, it is important to note that things often doesn't work on first try. The task then isn't to rewrite the code randomly and see what happens. You instead take one step back and try to compare what you think you instructed the processor to do, with that the processor manual describes the processor to do. And the debugger can be used to look at state and compare with the state you assumed you would have.

    Random "work around" changes are seldom producing good solutions.

  • Why dont you use keil simulator? Or Connect a debugger and check whats actually happening?

    Is posting a thread and waiting for the reply the fastest method to solve the problem [given the nature of the problem. It can be solved by studying the example codes also]??

  • Actually in the MCR register i have given reset and interrupt in both MR) and MR1 register. Thats why i didnt get. Now am getting the expected signal.

    Thank You

  • And that was why I explicitly wondered why you played with two match registers while still configuring the timer to reset on every match making it impossible to reach any second match value.

    So next thing - are you aware that if you use the match output pins, then you can have the timer drive these pins with zero ISR involved? And zero jitter from interrupt response time or varying code paths of any code sequences?