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

LPC2148 timer0 not working as expected

I am new to ARM and I am trying to produce 1 second delay using timer 0 in LPC2148. But in debug session in Keil, it is giving delay of 4 seconds with 15MHz and 5 seconds with 12 MHz. What is the issue ?

Here is my code.

#include <lpc214x.h>
int main()
{
    IODIR0 = 1; // P0.0 is output pin
    IOSET0 = 1; // P0.0 is high
    T0PR = 15000000 - 1;
    T0TC = T0PC = 0;
    T0TCR = 1;  // start
    do {
        while(T0TC == 0);
        T0TC = 0;
        IOCLR0 = 1; // P0.0 is low
        while(T0TC == 0);
        T0TC = 0;
        IOSET0 = 1; // P0.0 is high
    } while(1);
}

Parents
  • Ok, so you've got the timer working and the pin to toggle. Why it is not quite at the frequency you want is another matter, but it appears to track your master clock input, so clearly some ratio involved. Not a part I'm using, not super invested in root-causing it.

    Suggest perhaps that you write some simple register decoder functions, so say you can pull the PLL or CLOCK registers and decode them into a human readable form. Perhaps read the multiple timer registers and decode their content.

    Do other tests, experiment with other peripherals, but be aware that anything outside the core may be poorly emulated.

    Do things related to the ARM7 core rather than the NXP implementation around it. Perhaps code some assembler routines, convert decimals to/from binary and ASCII.

Reply
  • Ok, so you've got the timer working and the pin to toggle. Why it is not quite at the frequency you want is another matter, but it appears to track your master clock input, so clearly some ratio involved. Not a part I'm using, not super invested in root-causing it.

    Suggest perhaps that you write some simple register decoder functions, so say you can pull the PLL or CLOCK registers and decode them into a human readable form. Perhaps read the multiple timer registers and decode their content.

    Do other tests, experiment with other peripherals, but be aware that anything outside the core may be poorly emulated.

    Do things related to the ARM7 core rather than the NXP implementation around it. Perhaps code some assembler routines, convert decimals to/from binary and ASCII.

Children