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 generate 1 useg delay for at89s52?

Status
Not open for further replies.

pasmosodico

Newbie level 4
Joined
Jun 23, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,337
Hello everbody i have a proyect with the at898s52, i need a 1 useg delay to generate a square wave

im using keil uvison 3

this is my code:
#include <REGX52.h>
#include <stdio.h>
#include <intrins.h>
void T0Delay(void);
short int a=0;
void uartInit(void);
void main(void){
T0Delay();
uartInit();

while (1)
{
}


}
void T0Delay(){
TMOD=0x01;
//TL0=0x00;
//TH0=0xFF;
TR0=1;
ET0=1; /* enable timer0 interrupt */
EA=1; /* enable interrupts */
//while (TF0==0);
//TR0=0;
//TF0=0;
}
void ISR_Timer0(void) interrupt 1
{
TF0 = 0;
TL0=0xA5;
TH0=0xFF;
a++;
if(a<2){P1_5 =0;}
else{P1_5 =1;}
if(a==99){a=0;}
}


void uartInit(void) // con timer 2
{
SCON = 0x52; //01010010b
T2CON=0X34;
RCAP2H = 0xFF; //Corresponden a direcciones altas y bajas
RCAP2L= 0XD9; //para 19200(19230) baud rate 65496(en decimal)
TR2 = 1;
}


With this code i generate a 50 useg delay, work fine but now i need another delay aprox 1 usec to generate other square signal.


Can i, with keil generate very very small delay (1useg).How??

Any ideas please

Regards

(Sorry by my english)

---------- Post added at 20:06 ---------- Previous post was at 20:06 ----------

i am using a 24 mhz crystal
 

Re: 1 useg delay at89s52

Smaller timmings requirements at C compilers must be calibrated empirically.
That´s because optimization levels may affect the way code is implemented at assembly.

However, if I remember correctly, KEIL IDE allow take time measurement during simulations, and you could perform a fine tunning.

+++
 

Re: 1 useg delay at89s52

since you are using 89S52 with 24MHz
It has its internal clock divier with factor 12
so your system clock will be 2MHz & your machine cycle will be 0.5usec
if try to make any function, its going to take more than 2 machine cycles, so avoid calling fuction
however you van use
_nop_(); (include INTRINS.H in your project file)
whicj will give delay of 0.5usec
use two _nop_() for two time

or
use macro like this

#define DELAY_1USEC _nop_();_nop_()

while(1)
{
P0_0 ^= 1; // toggle line
DELAY_1USEC; // 1 usec delay
}
 

Re: 1 useg delay at89s52

I agree with andre_teprom... in many previous discussion i have told that you dont get accuracy in C program... but instead you go for asm program to get excat delay....

the reason is also stated clearly as the number of machine cycles taken by processor differs when C is broken down to asm program... and the delay is calculated at assembly level... as it is very easy to get the opcode and machine cycles consumed by the processor for each instruction,,,,
 
Re: 1 useg delay at89s52

Even while using C, if we use timers for delay, we can get nearly accurate delays.

maximum time delay you can generate is 71.7 millisec .. then if you multiply it by 14 times you get 995.4msec and not 1000 msecs...
 

Re: 1 useg delay at89s52

maximum time delay you can generate is 71.7 millisec .. then if you multiply it by 14 times you get 995.4msec and not 1000 msecs...

Thats the reason I said nearly accurate not completely accurate, also it depends on the application, for example one can generate a 50 milli sec delay with descent accuracy.
 
Last edited:

Re: 1 useg delay at89s52

upto 71.1 millisec you can generate and not after that......... thats what i told in my post .. you are repeating the same answer???????????

or you want to convey something different??????? dont misguide people.....
 

Re: 1 useg delay at89s52

Hey guys I think Hareesh is talking about 1uSec delay..
why are you talking about mSec..
It also depends upon your application, how accurate you want
You can write timer interrupt for 1mSec.. & count it for your application
 

Re: 1 useg delay at89s52

upto 71.1 millisec you can generate and not after that......... thats what i told in my post .. you are repeating the same answer???????????

or you want to convey something different??????? dont misguide people.....

Just read my post again, I am not misguiding.
Perceptions differ, and I am not responsible for that, if you read my post carefully, you will get the point.

What I am conveying is upto some extent (for example if an application needs only 50 milli sec delay) you can also get somewhat accurate delay even while using C, by using timers.
 

Re: 1 useg delay at89s52

Just read my post again, I am not misguiding.
Perceptions differ, and I am not responsible for that, if you read my post carefully, you will get the point.

What I am conveying is upto some extent (for example if an application needs only 50 milli sec delay) you can also get somewhat accurate delay even while using C, by using timers.

what post are you talking about??

so you said delays can not do timer interrupts for times as short?

thanks for answers
 

you could use nop function 1usecond is not possible if you are using 11.0592MHz crystal.. if you use a 12Mhz then if you use nop function you can get 1usec delay and if you use 10 nop function then you get 10usec delay... without interrupt..... but use 12MHz crystal and _nop funtion in keil...........
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top