Thread: probably simple answer but i cant figure it out

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    probably simple answer but i cant figure it out

    I am writing a C programme to blast into a PIC micorcontroller and i need a 1 millisecond delay. Could anyone provide me code for a 1 miollisecond delay

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    sleep(1); But I doubt many platforms would be able to perform a 1 millisecond delay precisely.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Not mentioning which OS/Compiler you're actually using makes for vague answers.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    OS/Compiler

    Using the Microsoft based package Visual C++

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    11
    Software delay can be done using "for" loops

    for( a=0;a<8; a++ )
    for( b=0; b<80; b++ );

    or
    by using assembly lang delay routines can be written

    Delay routines depend on Clock frequency/Time each instruction takes.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Even though Sleep() is in milliseconds, you're not likely to get consistent 1mS delays out of it.

    I would suggest you need another approach to the problem, one which doesn't need precise time delays.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Off topic, but GREAT sig there, Salem....
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Quote Originally Posted by pprabhakar
    By using assembly lang delay routines can be written.
    It needs someone to know the design of the machine. There is a timer interrupt in PCs (int0). I think it should be used for making delays at the highest precise that that machine can make, without consuming CPU time.
    I don't know, but that micorcontroller may has a special type library included, to handle such things (ex special sleep() function).
    Last edited by siavoshkc; 03-13-2006 at 06:06 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I simple little problem but i cant figure it out
    By SebastionV3 in forum C++ Programming
    Replies: 9
    Last Post: 05-24-2006, 05:55 PM
  2. Trying to figure out a simple loop....
    By chadsxe in forum C++ Programming
    Replies: 9
    Last Post: 01-05-2006, 01:31 PM
  3. Simple code :: Cant figure out the problem...
    By pritin in forum C++ Programming
    Replies: 11
    Last Post: 09-02-2005, 04:02 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. can't figure out simple program
    By blight2c in forum C++ Programming
    Replies: 4
    Last Post: 03-16-2002, 05:17 PM