×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

timer, delay, sleep function, in need fo accuracy

timer, delay, sleep function, in need fo accuracy

timer, delay, sleep function, in need fo accuracy

(OP)
Hi, I'm a C++ programmer and don't know much about assembly(though I'd like to learn in the near future). I'm writing on this forum since I need of a time delay optimized function..accurate to nearly the millisecond(Zen Timer is accurate to the microsecond I think).first off, to know why I need precise accuracy in this function, down to the exact millisecond is because I am trying to produce a frequency through my parallel port. I timed the call and return of the _outp()(function to write to the port in VSC++6.0) to be around 1/200,000th of a second. I only need my program to be exact to the 1/1000th of a second so that isn't much of a time consumer. On the other hand, the Sleep(ms) function is a MAJOR time consumer. I can only achieve at most 100Hz doing this:

while(1){

_outp(0x00378, 0x01); //Switch pin 0 to High
Sleep(1);
_outp(0x00378, 0x00); //Switch pin 0 to Low
Sleep(1);
}
The Supposed result should be that it pauses for 1 ms between switching from on to off, meaning that it does a cycle(on off) in 2 ms. This theoretically mean that it would give a frequency of 1000/2 per second or 500Hz.But it gives me 100Hz, 100 cycles a second at most!

and no, I don't think the while loop has anything to do with it since I batch process it, doing it 10 times before repeating a while.(I even experimented with no while, doing it 100 times)

I tried making my own delay function using clock() but the calls to clock() take Significantly longer than the calls to Sleep(). I'm thinking Sleep might be coded in assembly.

I need help finding an assembly written function to be used with C++ or such that might be able to help me make near precise frequencies. I know Micheal Abrash's Zen Timer does some pretty accurate calculations. Can someone show me a way to do this? Thanks!

RE: timer, delay, sleep function, in need fo accuracy

Precise accuracy like you need it can't really be achieved by software, because if an interrupt is called at irregular moments (a key pressed f.e.), your program waits until the interrupt function is completed.

I think the best option is to connect in some way the Square Wave Generator (used for making sounds with the PC speaker) to the parallel port.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://www.geocities.com/thevhbcompany/
Don't worry what people think about you. They're too busy wondering what you think about them.

RE: timer, delay, sleep function, in need fo accuracy

(OP)
Bert, hrmm are you talking about the Speaker Timer? and making that work? But isn't the speaker timer only connected to the speaker and such..

One Idea on how to stop interrupts was brought up by Michael Abrash when I read about his Zen Timer for timing optimized code fragments. He stops all interrupts during execution but since I know no assembly, I haven't figured out that or how he got the timer to calculate to the micro seconds when the Internal PC timer counts down in +-40ms gaps..

how would I go about connecting the square wave generator? btw does anyone here know a good tutorial resource for one trying to learn assembly? Thanks!

RE: timer, delay, sleep function, in need fo accuracy

NASM is a good choice for learning assembly.

If you disable all interrupt,then you can get an microsecond timer determined by your machine's frequency.
You can look up the clock period of intel instruction to get an appropriate instruction(i have no manual at hand :( )
The following instructions should apprear in your sleep function
            ...
            cli
            out port#,al
            out port#,al
            sti
            ...
If i get exact one ,i will post it again!

I want to emigrate Canada or Australia. Any relative information you supplied will be appreciated!

zallen@cmmail.com
ICQ:101229409

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close