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.

How to calculate the 1 second time delay in LPC2148

Status
Not open for further replies.

sucharitha_999

Newbie level 1
Joined
May 26, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,289
Dear all,

How to calculate 1 second time delay in LPC2148 microcontroller.

With Regrads
Sucharitha
 

There is your clock, e.g. 48 MHz or 60 MHz. There is a peripheral clock divider, by default set to 4. There are Timers that count the clock and they can be divided further.
Depending on the total divider, you have to count to a number that represents 1 sec. If peripheral clock divider is 1 and you run with 48 MHz the counter has to count 48 Million clocks during one sec.
In case you are talking about RTC, the same logic applies. If you have an external 32 kHz clock, the divider is easier and it can be used during low power state.
Much more details in the User Manual
hth, Bob
 

Hi

Create a "tick" time base of 1 msec using one of the LPC21xx timers

Use the timer interrupt to advance a counter

Raise a flag (set a memory bit ) when the counter count 1000 = 1 sec

reset the counter and start all over

All the best

Bobi

The microcontroller specialist
 

Hi i have written code for 1 sec delay. But its not generating desired delay. Is there anyting wrng? please help.
code is as follows:

/*------------------------------------------------------------
Program for Multiplexed 7Segment using Timers with ARM LPC2138
Fosc=14.7658Mhz
Common Cathode 7 Seg is used.
--------------------------------------------------------------*/

#include <LPC213x.h>

void sec1_delay(unsigned int a)
{

//unsigned int d;
//for(d=0;d<1100000;d++);
unsigned int d;
for(d=0;d<a;d++)
{
T0PR = 0x0000270F;
T0MR0 = 0x000000AF;
T0TCR = 0x01;
while(T0TC!=T0MR0);
T0MCR = 0x00000002;
T0TCR=0x02;
}
}

int main(void) // in ARM main should be int or it will show error
{
IODIR1=0x00ff0000; //set the direction for I/O Port 1= o/p,0=i/p
for(;;)
{
IO1SET=0x003f0000; //for setting the bit value to 1
sec1_delay(1);
IO1CLR=0x003f0000; // for clearing the bit value same reg vlaues are used

IO1SET=0x00060000;
sec1_delay(1);
IO1CLR=0x00060000;

IO1SET=0x005b0000;
sec1_delay(1);
IO1CLR=0x005b0000;

IO1SET=0x004f0000;
sec1_delay(1);
IO1CLR=0x004f0000;

IO1SET=0x00660000;
sec1_delay(1);
IO1CLR=0x00660000;

IO1SET=0x006d0000;
sec1_delay(1);
IO1CLR=0x006d0000;

IO1SET=0x007d0000;
sec1_delay(1);
IO1CLR=0x007d0000;

IO1SET=0x00070000;
sec1_delay(1);
IO1CLR=0x00070000;

IO1SET=0x007f0000;
sec1_delay(1);
IO1CLR=0x007f0000;

IO1SET=0x006f0000;
sec1_delay(1);
IO1CLR=0x006f0000;
}
}
 

But its not generating desired delay. Is there anyting wrng?

Yes, if you think your code should do what you design it to do.

No, if you think it is OK if your code does not do what you design it to do.

code is as follows:

you are here asking people to help you. so it is in your interest to make sure that you make it as easy as possible for others to help you. Adding comments to your code and outlining your thought process behind your code would help a long way.
 

sorry fogot to mention comments....

here it is...

/*------------------------------------------------------------
Program for 1 sec delay using Timers with ARM LPC2138
Fosc=14.7458Mhz
--------------------------------------------------------------*/

#include <LPC213x.h>
#define delay 1

void wait(unsigned int a)
{

unsigned int d;
for(d=0;d<a;d++);
{
VPBDIV=0x00000001; //select periferal clock same as of main clock which will be 14.7458Mhz
PCONP=0x00000002; //enable use of timer0
T0PR=0x0000399A; // set prescale register counter,
//PC will increment at every clock cycle up to this count
//and on reach it will increment T0TC by 1
// count is 14746 so after every 14746 clk cycle T0TC will be incremented by 1
T0TCR=0x00000001; // start timer0
T0MR0=0x000003E8; //match register value to match with T0TC
while(T0TC != T0MR0); //Wait until counter 0 gets to 1000 so finally 1000*14746*67.82ns = 1sec
T0TCR = 0x00000003; // reset T0TC register to 00
}

}

int main(void) // in ARM main should be int or it will show error
{

IODIR1=0x00ff0000;

while(1)
{
IOSET1=0x003f0000;
wait(delay);
IOCLR1=0x003f0000;

}
}

I have checked this code on my development board but its not working.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top