CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

delay_ms() issues - being shorted on time!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SuperAlpha



Joined: 19 Apr 2007
Posts: 4
Location: DFW, TX

View user's profile Send private message Yahoo Messenger

delay_ms() issues - being shorted on time!
PostPosted: Wed May 09, 2007 8:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 09, 2007 9:09 am     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Wed May 09, 2007 9:25 am     Reply with quote

I am using PCH compiler v4.021.
SuperAlpha



Joined: 19 Apr 2007
Posts: 4
Location: DFW, TX

View user's profile Send private message Yahoo Messenger

PostPosted: Wed May 09, 2007 9:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 09, 2007 10:20 am     Reply with quote

Then your oscillator is not 20MHz.
SuperAlpha



Joined: 19 Apr 2007
Posts: 4
Location: DFW, TX

View user's profile Send private message Yahoo Messenger

PostPosted: Wed May 09, 2007 4:03 pm     Reply with quote

#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

View user's profile Send private message

PostPosted: Wed May 09, 2007 4:08 pm     Reply with quote

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 ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group