View previous topic :: View next topic |
Author |
Message |
SuperAlpha
Joined: 19 Apr 2007 Posts: 4 Location: DFW, TX
|
delay_ms() issues - being shorted on time! |
Posted: Wed May 09, 2007 8:06 am |
|
|
Hi.
I am using the built-in delay function and it does not work as advertised. Interrupts are not disabled so I expect the delay to be "at least" 20ms. The clock is 20MHz as measured and serial communications function well.
The delay varies from 16.0ms to 17.5ms, but never >=20.0ms.
Does anybody know what could be wrong here? I want to avoid making my own version of a delay loop, if possible.
#pragma use delay(clock=20M, ocillator, restart_wdt)
delay_ms(20);
Thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 09, 2007 9:09 am |
|
|
I'm not aware of any problems with the delay_ms() function. Which compiler version are you using?
The code as posted has some typing errors in it. Can you post a short but program that we can copy/paste for testing? Make sure the program is complete, including the #device and #fuse lines. |
|
|
SuperAlpha
Joined: 19 Apr 2007 Posts: 4 Location: DFW, TX
|
|
Posted: Wed May 09, 2007 9:25 am |
|
|
I am using PCH compiler v4.021. |
|
|
SuperAlpha
Joined: 19 Apr 2007 Posts: 4 Location: DFW, TX
|
|
Posted: Wed May 09, 2007 9:27 am |
|
|
The typo is the word oscillator. This is not necessary. I have tried it with and without the additional parameters in the #use delay. |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Wed May 09, 2007 10:20 am |
|
|
Then your oscillator is not 20MHz. |
|
|
SuperAlpha
Joined: 19 Apr 2007 Posts: 4 Location: DFW, TX
|
|
Posted: Wed May 09, 2007 4:03 pm |
|
|
#pragma use delay(clock=20M, restart_wdt)
delay_ms(20);
or
#pragma use delay(clock=20M)
delay_ms(20);
I still see a delay from about 16-18ms, never >=20ms. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 09, 2007 4:08 pm |
|
|
1. Post your PIC.
2. Also tell us how you are determining that the delay period is shorter
than expected. Are you measuring it with an oscilloscope or a logic
analyzer ?
3. Post a very short (but compilable) program that demonstrates the
problem.
4. Are you running actual hardware or is this being done in Proteus ? |
|
|
|