Timer is not Ticking

Thread Starter

devjeetmandal

Joined May 7, 2017
48
Hello Everyone,

I am using timer to create 1sec delay using LPC2138

here is what i am doing

C:
/*
*  Project Name: Blink Led Using Timer
*  Author: Devjeet Mandal
*  MCU used: ARMv7 LPC2138
*  CCLK: 60MHz
*  PCLK: 12MHz
*  PR = [CCLK x Required Time Delay(in sec)] - 1
*/

//include header file for LPC2138(same header file for LPC213 1/2/4/6/8)
#include <LPC213X.h>

#define PRESCALE 60000


void _delay_ms(int ms)
{
     T0TCR = 0x02; // Reset Timer
    T0TCR = 0x01; // Enable Timer
    while (T0TC < ms);  // Till TC is less than ms wait. as TC = 1ms
    T0TCR = 0x00;  // Disable Timer
}

int main(void)
{
     T0CTCR = 0x00;  //Timer Mode
    T0PR  = PRESCALE - 1;  //Setting the Prescale
    T0TCR  = 0x02;  // Reset Timer
    IO0DIR = (1<<0);  // LED Pin
    while (1)
     {
         IO0SET |= (1<<0);
        _delay_ms(1000);
        IO0CLR |= (1<<0);
        _delay_ms(1000);
     }
}
this is my PLL Setup

Capture1.PNG


Here is what i am getting when i'm debugging my code

Capture.PNG

When I'm trying to simulate in Proteus my led blinks continuously and oscilloscope shows this

Capture2.PNG


can someone please help me with this?
thank you in advance.
 
Last edited:

MrChips

Joined Oct 2, 2009
34,807
My first step in debugging would be to replace the _delay_ms() function with a software loop to make sure the rest of the code is working.

The next step would be to examine the Timer code and module to see what it is doing.
 

bertus

Joined Apr 5, 2008
22,922
Hello,

On the scope, your trigger source is on A, but your signal is on B.
Also the time scale can be wrong.

Bertus
 
Top