programming a 1 ns delay for microcontroller/processor

Thread Starter

grafight

Joined Oct 10, 2013
2
The problem is i have to create a 10 ns delay, 140 ns delay and a 450 ns delay in c, which i have found almost impossible to do. The microprocessor has a max clock speed of 50 Mhz and a max bus speed of 25 Mhz. Is there a way to create such a short delay in my c code?
 

Thread Starter

grafight

Joined Oct 10, 2013
2
i'm using an already made microcontroller and i'm not able to actually make any changes to the hardware only the coding for this task...I figured it would take at minimum 41ns per 1 instruction so i guess that would be as close as i could but i'm not sure the assembly language the C code gets translated to so that i can only use 1 instruction

I hope that makes sense lol
 

MrChips

Joined Oct 2, 2009
35,131
No, it doesn't make sense.

You still need to specify the exact model mcu.

You also need to state exactly what you are trying to accomplish.

Simply saying you want a delay of 140ns doesn't tell me much.
 

Art

Joined Sep 10, 2007
806
He means, using a higher level compiler,
doesn't know if he has access to the native language that would guarantee timing of single instructions.
I always wondered how you get around that with C on microcontrollers.
 

John P

Joined Oct 14, 2008
2,068
Yes you can get control of a processor's instructions by embedding sections of assembly language in your C code. I think just about any compiler allows this, though it's contradicting the idea of having a compiler if you do it. However, sometimes it's necessary.

But a 10nsec delay on a processor that has a clock rate of 50MHz??? One cycle at 50MHz is (obviously) 20nsec, and the processor can't do anything in less time, so it seems to me as if this can't work.
 

Brian Griffin

Joined May 17, 2013
64
1ns pulse is impossible at basic microcontrollers, and even on FPGA. The rise up and down times are exceeding 1ns.

A delay generator could maybe do that, but the one I have handled are at most 10ns, if I'm not mistaken.
 
Top