This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

********* delay routines *************************

I am now urgant.

Thank you. But I must need ready and tested routines for slow frequence (31kHz, 125kHz, 250kHz etc.).

Please for me.

  • Yes, you are urgant (sic!). But why are you urgant? Or actually arrogant! Have you not spent the last days with Google, or using the search function on this forum, or downloading example code from the chip manufacturer? Reading the chip datasheets and application notes?

    Well then, exactly what have you done?

    A private tutor charges money. A private contractor - consultant - charges money. Why do you think people on this forum should start jumping because you have a need? That is both rude and silly. Prove that you are not a leach: Start showing some work! People will not donate time on you, unless you show that it is worth it.

    And why do you make a post that doesn't even mention the processor? Do you really think it is enough to say that you have a station wagon when you buy spare parts for a car? No need for exact make and model (and in that case also fabrication year, or serial number)?

  • Hello Urgant,

    The function I use is:

    void DelayForSpecifiedTimeInMicroSeconds(int TheDelay);
    

    And when I want to have the delay specified by frequency I use the function:

    int ConvertFrequencyToPeriod(int TheFrequency);
    

    Just insert this into your code - But don't bother compiling it unless you are prepared to spend time investigating the probable errors the linker might report.

  • Silly Sausage.

    Your functions are incredibly dangerous.

    If you were to use a negative integer for the delay the program will go back in time and could destroy the entire space time continuum.

    Please change all your programs using these functions to take unsigned numbers, for the sake of the universe.

  • The compiler could detect that, and would just optimise-out the entire universe?!

    That's why such functions should never be written in a high-level language.

    Obviously.

  • In C? ASM?
    For microseconds? seconds? weeks?
    12 clock? 6 clock?, 1 clock? CPU?
    Wait loop or timer?

    C lopping delay routines are never guaranteed. the compiler version can change things.

    the spelling is "Urgent"

  • A delay for 250kHz is no fun at all. 4us delays do not produce 250kHz - every single interrupt will consume time. And with a 4us delay you have to subtract the time needed to actually do something - you never delay without doing something.

    Are you going to produce a frequency output on a port pin? Then you do not use a delay. You do not want to let the processor manually toggle a poin every 4us (or possibly 2us if you want real 250kHz square wave.

    There are many easier methods of producing a square wave than using a microcontroller - especially when producing a square wave that will not leave any processing capacity left for doing other things.

    So please start by telling why you need your delays - maybe you just need to configure the timer(s) in your unknown processor and can then let a timer compare-match handle everything.