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 properly do hardware delay

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi,

Anyone can help me to check the simple code (the program is work).

The problem is when i using Keil to simulate the result is.. 1.029805sec at 1000 looping but...when practically is not ~1sec (it take more then few min).

So, i change it to 1 at DELAY_T0_Wait(1); then in practical the result nearly to ~1sec.

The hardware crystal is 11.059MHz.

Can anyone tell me why?

Thank
 

Re: Hardware Delay

Hello

This is a wrong way to do hardware delay!

You should set the timer for periodic inerrupt who increase a long type variable

TimeValue = TimeValue +1;

when you wish to start a delay you need to save this register value + the delay

period.

Temp = TimeValue + Delay;

for testing create an if loop who read the variable and coper it to the one you saved once the value are equle or large then -> the delay is over

DlayFlag = 0;
Temp2 = TimeValue;
if(Temp >= Temp2)
DlayFlag = 1;



All the best

Bobi
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Hardware Delay

Hi Friend,

Very happy you can explain to me but i still got a bit blur blur.:cry:.., please can you help me to modified my code. So, i can study/try from the code, if i still not understand it so we come and discuss more further can we?

Thank You
 

Re: Hardware Delay

I can't see anything wrong with this code (from Chapter 6: "Meeting real-time constrains", Embedded C), even if it doesn't use interrupts ..
Can you post the compiled code which you try to use in real microcontroller ..
Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Re: Hardware Delay

hi,

I am using that i post it to run it in real microcontroller. Only the different with the code is.. the book is given DELAY_T0_Wait(1000); then i change it to DELAY_T0_Wait(1); because if i using the book given value i can't achieve ~1sec in real microcontroller.

Do you got any idea??

Thank You
 

Re: Hardware Delay

I checked the HEX file from your ZIP, disassembled it and couldn't find any errors ..

Then I tested your code in 87C52 micro and as it is I have 1.2ms square wave on pin 1.0, so I assume if N=1000 the square wave would have 1.2s ..

Regards,
IanP
 

Re: Hardware Delay

Hi,

So, you mean that is no problem with the code when you using my code? you got change the N=1000 or N=1 on code then run it in practical way? At N=1000 the code i need to wait the pin1.0 with LED blinking very long...what's the broblem??:cry: Is it my hardware problem??

Thanks..
 

Re: Hardware Delay

That is correct, the software runs well ..

Just to make sure that it also performes with N=1000, can you compile new files with N=1000 and post them?

If you can, replace microcontroller with another 8051-compatibile, and check if the clock frequency is 11,059200 ..

Regards,
IanP
 

Re: Hardware Delay

Hi,

I already post N=1000 and N=1 Hex file to you, please try and see...

I only have 89c52 and i am using 11.059M crystal..

Thanks A Lot....
 

Re: Hardware Delay

I have tried the N=1000 option and the resultant square wave has ≈0.7s period ..
So, more than less it is manageable ..
On the other hand why your 89C52 behaves differently .. I really don't know ..
Regards,
IanP
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top