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 20:20
Read: times


 
#166157 - I think you should read Murray's comments
Responding to: ???'s previous message
Ok. I have just looked at Murray's code.

1. He has already stated that you need to calibrate the function.

2. Yes. It would need re-calibration for a change of memory model

3. Yes. It may need re-calibration for a change of compiler version. It may need re-calibration for a change in optimisation setting.


You can solve the memory model by specifying the data type of the local variable. Then the basic loop will remain the same. The preamble will obviously have a different but insignificant execution time. e.g:
void delay_ms(volatile unsigned int xcount)
{
    data volatile unsigned int count = xcount;
    for(count *= DELAY_MULTPLR; count > 0; count--) continue;

    return;
}



As I said in an earlier post, other compilers and cpus permit inline assembly. So you can use a macro that will produce the exact number of machine cycles.

Personally I would seek a delay_us(us) macro and a delay_ms(int ms) function. And this is exactly what you do with sdcc. But given the limitations of Keil, you could write a single delay.asm with conditional assembly for each memory model.

But for the average Joe, he can just check the given calibration constant and go.

As an exercise for Mr Neil and Mr Malund, I would be interested in a compiler version or setting that creates a different timing loop:
?C0001:
	SETB 	C
	MOV  	A,count?041+01H
	SUBB 	A,#00H
	MOV  	A,count?041
	SUBB 	A,#00H
	JC   	?C0004
?C0003:
	MOV  	A,count?041+01H
	DEC  	count?041+01H
	JNZ  	?C0001
	DEC  	count?041
?C0005:
	SJMP 	?C0001


Yes. I am well aware that the compiler is quite free to create different code. I doubt that it will alter the generation unless there is a version change. In which case the user would re-calibrate.

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