Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/16/09 07:39
Read: times


 
Msg Score: 0
 +1 Good Answer/Helpful
 -1 Answer is Wrong
#166115 - Yes a delay function is useful
Responding to: ???'s previous message
There are several ways to implement a delay.

1. Using the hardware Timers
2. A software delay loop

Both methods depend on the system clock. The first method requires resources that may be already in use.

The software method is fairly portable with the important proviso that you need to calibrate it for your particular compiler, version memory model ....

Having done the single calibration, all of the project code is going to run at the intended speed. e.g. if you want to delay for one millisecond you call delay_ms(1) rather than some arbitrarily named function with some magic constant.

With many microcontroller compilers, you implement the delay with inline ASM code with the parameters calculated by a C macro solely dependent on F_CPU and the #microseconds required.

If the compiler does not permit inline ASM, you just have to calibrate a C loop that is written to give "predictable" code. ( probably by forcing specific memory model volatile variables). By no means perfect but a practical solution.

And if you change compiler, cpu, memory model... you only have one place to alter or re-calibrate your macro or function.

David.

List of 30 messages in thread
TopicAuthorDate
s/w delay function            01/01/70 00:00      
   Software loops can be optimized away            01/01/70 00:00      
   lacks side-effects            01/01/70 00:00      
      First time with LINT?            01/01/70 00:00      
   lacks side-effects            01/01/70 00:00      
      That does not mean it is an error.            01/01/70 00:00      
      It also blocks            01/01/70 00:00      
   How to post legible source code            01/01/70 00:00      
   DELAY_0.1.ZIP Useful?            01/01/70 00:00      
      That doesn't help, and it won't work anyhow!            01/01/70 00:00      
         I stand by it.            01/01/70 00:00      
            Yes a delay function is useful            01/01/70 00:00      
               wrong !!!!            01/01/70 00:00      
               No, that's precisely where you're wrong            01/01/70 00:00      
            How can you say that?            01/01/70 00:00      
               I think you should read Murray's comments            01/01/70 00:00      
                  I have seen ...            01/01/70 00:00      
                     Timers usable without start/stop too            01/01/70 00:00      
                        free-running counter/timer            01/01/70 00:00      
                           Unsigned integers            01/01/70 00:00      
                              re: unsigned            01/01/70 00:00      
                                 Try unsigned subtraction with borrow            01/01/70 00:00      
                                 bug in second (improved!?) code block            01/01/70 00:00      
   Delay Loops in 'C'..!!! NO            01/01/70 00:00      
      Go on. Suggest a SIMPLE alternative            01/01/70 00:00      
         My Methods            01/01/70 00:00      
            So he has a long list of constraints            01/01/70 00:00      
               oh boy what a load who wil have 10 minutes for this            01/01/70 00:00      
                  Ok. I was being naughty.            01/01/70 00:00      
                     you forget the obvious ...            01/01/70 00:00      

Back to Subject List