View previous topic :: View next topic |
Author |
Message |
Keith Ward
Joined: 09 Apr 2005 Posts: 2
|
Delay Routines And "Time" Parameter |
Posted: Sat Apr 16, 2005 8:53 pm |
|
|
According to the compiler manual the delay routines will accept variable values up to 255 or constants up to 65536. Why is this and why would it make a difference?? I discovered this "feature" by accident when attempting to change a variable to values above 255 and noticed that the delay values were being truncated to acceptable values for the routine. I have never seen a function that does anything like this before. Comments? Explanations? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Apr 17, 2005 12:08 am |
|
|
It is because that's the way CCS made it. The delay routine isn't really just C code that they include but it is generated asm code based on how you call the "magic" function. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Sun Apr 17, 2005 9:38 am |
|
|
Mark is right. The answer is "just because". It is a bit screwy and a compiler warning message about wrong data type as the function argument would be helpful.
But in general, if at all possible, work out a way to NOT use the delay functions in your code. Use timers and interrupts or if a PIC is available with dedicated hardware to accomplish your goal, use that instead of bit-banging a port.
And please, please, please don't ever put a delay_ms or _us statement into an interrupt service routine. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 17, 2005 2:31 pm |
|
|
Quote: |
I discovered this "feature" by accident when attempting to change a
variable to values above 255 and noticed that the delay values were
being truncated to acceptable values for the routine. |
A possible work-around for this limitation:
http://www.ccsinfo.com/forum/viewtopic.php?t=16656 |
|
|
Keith Ward
Joined: 09 Apr 2005 Posts: 2
|
|
Posted: Sun Apr 17, 2005 7:30 pm |
|
|
Can't say I like the reason of "just because" but there is probably a good reason that someone went to the effort of making it that way. My actual use is quite simple, it's just for piezo buzzer freqs and not for acutual code timing.
Thanks all. |
|
|
|