Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How can I make 1 ms delay ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,312
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,436
If I want to have 1 ns delay, what should I do ? divide 1us by 1000 ? since if I put TH0 and TL0 = FF, it's about 1 us delay for 11.0592 Mhz
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,020
Reputation
4,156
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
1ns is not possible with any embedded mcu.

1ns is the period of 1GHz which is a huge frequency, I doubt that you can achieve that even if you try an external clock divider, even an FPGA wouldn't be able to give such a delay.
 

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,312
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,436
1ns is not possible with any embedded mcu.

1ns is the period of 1GHz which is a huge frequency, I doubt that you can achieve that even if you try an external clock divider, even an FPGA wouldn't be able to give such a delay.
is it possible if I create 100 ns, since my oscilator is 11.0592 Mhz ?

Thanks
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
is it possible if I create 100 ns, since my oscilator is 11.0592 Mhz ?
The shortest delay would be the execution of an instruction requiring the minimum amount of instruction cycles.

You do not appear to mention the specific MCU, therefore without further details a definitive answer cannot be given.

However, many MCUs offer a No Operation (NOP) which essentially delays execution flow for the minimum number of instruction cycles. You can usually call this assembly instruction from within both assembly and C code. If using a C Compiler, consult your compiler's documentation concerning the use of assembly language from within C code.

If your MCU does not have a NOP instruction, there is usually an instruction which can provide similar results.

BigDog
 

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,312
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,436
The shortest delay would be the execution of an instruction requiring the minimum amount of instruction cycles.

You do not appear to mention the specific MCU, therefore without further details a definitive answer cannot be given.

However, many MCUs offer a No Operation (NOP) which essentially delays execution flow for the minimum number of instruction cycles. You can usually call this assembly instruction from within both assembly and C code. If using a C Compiler, consult your compiler's documentation concerning the use of assembly language from within C code.

If your MCU does not have a NOP instruction, there is usually an instruction which can provide similar results.

BigDog
I'm using AT89S52 and create delay with timer, so far the fastest from timer is 1uS, is it possible to make it become 100nS ( divide by 10 ) ?
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
I'm using AT89S52 and create delay with timer, so far the fastest from timer is 1uS, is it possible to make it become 100nS ( divide by 10 )?
The short answer is NO.

A system clock frequency of 11.0592MHz generates a system clock period of approximately 90ns. However, a single instruction cycle of a AT89S52 requires 12 system clock cycles. Therefore the period of a single instruction cycle of a AT89S52 with a 11.0592MHz system clock is approximately 1.09µs.

Using a timer can rarely achieve a shorter delay than the execution of a single instruction. Besides the time overhead of configuring the timer there is also the time overhead required for the MCU to respond to the timer overflow.

What are you attempting to accomplish exactly? What is the task requiring a 1ns delay?

BigDog
 
Last edited:

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,312
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,436
The short answer is NO.

A system clock frequency of 11.0592MHz generates a system clock period of approximately 90ns. However, a single instruction cycle of a AT89S52 requires 12 system clock cycles. Therefore the period of a single instruction cycle of a AT89S52 with a 11.0592MHz system clock is approximately 1.09ms.

Using a timer can rarely achieve a shorter delay than the execution of a single instruction. Besides the time overhead of configuring the timer there is also the time overhead required for the MCU to respond to the timer overflow.

What are you attempting to accomplish exactly? What is the task requiring a 1ns delay?

BigDog
How about 100 nS ? I want to make a delay for array of LED
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
The smallest delay you can create is equal to the time taken for one instruction to execute and this is done through a no operation statement. Anything smaller than that can not be created, as it is smaller than the instruction cycle.

bigdogguru has already stated in post #26 that with a 11.0592MHz system clock is approximately 1.09µs and he has also explained this.

So, since 1.09µs is the time taken for one instruction cycle, the minimum delay time that can be created is 1.09µs.

The only way you could utilize a timer to create a smaller delay would be if the timer can run off a different faster clock besides the system clock. However, seeing as how 1.09µs is the instruction cycle, getting a 100ns delay time (if it was possible) could not be reliably had as you would need to carry out some instructions for the timer. This would again, bring into play the 1.09µs instruction cycle and thus (had it been possible to have the timer interrupt every 100ns), you could not use it due to the limiting slower instruction cycle.

Hope this helps.
Tahmid.
 
Last edited:

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,064
Reputation
4,128
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,276
The 1.09ms is a typo - it should be 1.09us. It doesn't alter the conclusions though.

Rather than repeatedly asking about trying to make delays shorter than your processor instruction cycle it would be more useful to explain why you want a delay. It is perfectly possible to create very short delays in hardware very easily.

Keith
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
@Keith - I appreciate the typo correction, sometimes the right hemisphere is out-of-sync with the left hemisphere.

@bianchi77 - As Keith mentioned, very short delays can be achieved with external hardware such as a simple inverting/noninverting buffer which typically have propagation delays in the 5ns to 30ns range depending on the specific device. Cascading several buffers to achieve longer delays is also an option.

BigDog
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top