Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] TIMER PROBLEM in LPC2129

Status
Not open for further replies.

v.s.n.kumar

Member level 1
Joined
Dec 2, 2013
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
303
Hi,
please can anybody help me to solve the below problem. i have been facing this problem since 3days. i.e., cclk=12mhz, pclk=3mhz. i have created a time delay of 2 seconds and used as delay function to blink and led. when i debugged this code, after 2seconds i.e., the timer counter value doesn't reset even though i used the instruction T0TCR=1<<1. please anybody can solve my problem...........
Code:
#include<LPC21xx.h>
#define LED 1<<1
void delay(void);
void main()
{
 IODIR0=LED;
 T0PR=2999999;
 while(1)
 {
   IOSET0=LED;
   delay();
   IOCLR0=LED;
   delay();
 }
}
void delay(void)
{ 
 T0TCR=(1<<1);
 T0TCR=(1<<0);
 while(!(T0TC==2));
 T0TCR=(0<<0);
}
 
Last edited by a moderator:

download the lpc2300 code bundle http://www.lpcware.com/content/nxpf...pc23xxlpc24xx-peripherals-using-keils-μvision in the folder common/src/timer.c you will find the following function


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*****************************************************************************
** Function name:       delayMs
**
** Descriptions:        Start the timer delay in milo seconds
**                      until elapsed
**
** parameters:          timer number, Delay value in milo second             
**                      
** Returned value:      None
** 
*****************************************************************************/
void delayMs(BYTE timer_num, DWORD delayInMs)
{
  if ( timer_num == 0 )
  {
    /*
    * setup timer #0 for delay
    */
    T0TCR = 0x02;       /* reset timer */
    T0PR  = 0x00;       /* set prescaler to zero */
    T0MR0 = delayInMs * (Fpclk / 1000-1);
    T0IR  = 0xff;       /* reset all interrrupts */
    T0MCR = 0x04;       /* stop timer on match */
    T0TCR = 0x01;       /* start timer */
  
    /* wait until delay time has elapsed */
    while (T0TCR & 0x01);
  }
  else if ( timer_num == 1 )
  {
    /*
    * setup timer #1 for delay
    */
    T1TCR = 0x02;       /* reset timer */
    T1PR  = 0x00;       /* set prescaler to zero */
    T1MR0 = delayInMs * (Fpclk / 1000-1);
    T1IR  = 0xff;       /* reset all interrrupts */
    T1MCR = 0x04;       /* stop timer on match */
    T1TCR = 0x01;       /* start timer */
  
    /* wait until delay time has elapsed */
    while (T1TCR & 0x01);
  }
  return;
}



You just need to define the Fpclk which represents your clock frequency and maybe change the register names of the timer in case they are different (usually not the case)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top