Delay generation using NOP of 8051

Respected Experts, Iam RaviKumar.N, working on AT89c52 microcontroller.

I want to generate a delay of 1ms(milli second) using NOP instruction of 8051.

I would like to know how many NOP instructions I have to insert to generate the above specified delay.

With regards RaviKumar.n

Reply to
Ravi kumar.N
Loading thread data ...

If you use a 504kHz clock, the answer is 42.

Peter

Reply to
moocowmoo

I thought it was "how many idiot posters from google groups do you killfile each week"?

Reply to
nospam

RaviKumar.n,

This is like asking how many stones will fit in a 4 liter bucket. The first question is, "How big are the stones?"

This sounds suspiciously like a homework problem to me....

In any case, even if I didn't know what processor you were asking about, I'd ask the same two questions, to start:

- What is the clock rate of your processor?

- How many clock cycles does a NOP take to load and execute, including any wait states?

Aside from issues about some prefetching, caching, or speculative execution that some processors use, the answer to your question will fall out of the math.

Al

Reply to
Al Gosselin

ROFL! VGA!! [Very Good Answer]

I'll add that to my list of neat replies to dubious questions from customers!

Al.

Reply to
Al

Close the proper questions for the 8051 are What is the Xtal frequency and what is the clock divider 12, 4, 3,2, or 1 (12 being standard) No prefetching, caching, or speculative execution in this 8 bitter

Reply to
Neil Kurzman

Thanks for ur kind reply Peter.

The crystal Iam using is of 11.03MHz. For this crystal frequency how many NOP's should I include.

Please let me know the answer as early as possible.

With Regards RaviKumar.N

Reply to
Ravi kumar.N

If you can't do arithmetic yet, you should probably go back to banging rocks together, because you won't be able to learn embedded programming.

The answer was in Peter's mail. At 504KHz, 42 Nops take 1ms. That means each takes 12 clock cycles. Now you can work it out from your clock speed.

Reply to
Clifford Heath

Clifford Heath wrote in news:37lc44F5ehi7tU1 @individual.net:

...Assuming he's using a vanilla 8051 not one of the newfandangled gofaster ones. Now make way for the new hyperspace bypass..last orders please! M

Reply to
Mike Diack

Each NOP on your processor takes 12 cycles. At 11.03MHz each NOP is 12/11030000 or about 1088nS. So for 1mS you need 1000000/1088 NOPs which is 919.

However only the Ravenous Bugblatter Beast of Traal would be stupid enough to use that method of doing a delay because it wastes enough program space to build a hypersteller bypass in it. The correct way to do a delay is to use the timer. If the timer is being used for something else then Don't Panic it's not the End Of the World. Instead construct a delay loop and that will use much less space.

Your next task is to read the datasheets and understand how the crystal frequency is related to the machine cycle, and how many cycles each of the instructions take. It's not rocket science.

Peter

Reply to
Peter

In a 100 MHz single clock per cycle 8051, you can't fit that many NOPs into memory, so I would choose to execute just one NOP many times.

Cheers, Alf

Reply to
Unbeliever

One answer is Two NOPs, plus two other bytes. Be sure and inlude all the working in your homework :)

-jg

Reply to
Jim Granville

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.