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

timer0 ARM M3 do not count properly

Hello everyone,
I'm experiencing a strange behavior with the timer0 on my board, a landtiger with a lpc1768.

The issue is the number MR0 of the counter in order to get a fixed amount of delay and get an interrupt.

My configuration is as follow:
-) master clock source of 12Mhz (the crystal installed on the board) and with the 'clock generation schematic' in debug i see the clock is correctly chosen, the cclk is 100 Mhz and so the PCLK/1=100, PCLK/2 50 etc.
-)On my 'clock dividers window' the timer0 selection is on CCLK/4 and 25.0000 MHz.
-)the prescaler found in 'timer0' window is PR=0
-)my MR0 is 0x17D7840 (25*10e6) - it is found by multiplying 1s*25*10e6 1/s= 25*10e6 tick to count 1s.

When i debug the application inserting one breakpoint to the timer activation (LPC_TIM0->TCR = 1) and one on the first instruction of the IRQ_timer0Handler, the time shown the bottom right corner of keil, is 10s.

But if i have selected a 25Mhz clock, no presclarer, why 10s?
More strange is that, when i debug in simulation, the timer count 1s. But i cannot figure out what is going wrong with the board.
Can you please give me some advice about it? What am i missing?
Thank you

  • Get a scope and check your frequency assumptions.
    Make sure external clocks are running at the right frequencies.
    Where there are options to export internal clocks to a pin, use those and measure them.
    Where they can be output via a timer, review the frequency, and work back the internal values from the divider.
    Decode the PLL settings.
    Don't rely on Keil to provide timing. Make sure the XTAL settings, or whatever it is using to compute the time are correct. Figure a scaling value if you need to translate.

  • Hello.

    For the "Clock Generation Schematic" view, the "Xtal (MHz)" value on the "Options for Target ... -> Target" tab needs to be correct. So, if you have a 12MHz crystal on your board, enter "12" there.

    For the timing in the debugger, set the correct "Core Clock" in the "Settings for your debug driver -> Trace". So, if you have configured this to 100MHz, enter "100" there.

    With this, the "Stop Watch" times should match the actual values.