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 CCS Technical Support

delay functions inaccurate

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



Joined: 11 Sep 2008
Posts: 44

View user's profile Send private message

delay functions inaccurate
PostPosted: Wed Nov 12, 2008 11:58 am     Reply with quote

Is it just me or is the delay functions inaccurate. My 200ms delay using the built in ccs function can be more or less than that value, it is different for each restart.

There are no interrupts running at the time these delays are going.

Is there a more accurate way to create delay functions?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 12:09 pm     Reply with quote

For a question like this, you need to post your PIC, compiler version and
test program that shows the problem. Explain how you measured the
pulse length. Did you use a logic analyzer ? Which one ? What settings
did you use on it. This is so we can duplicate your test environment.


We don't remember your PIC and compiler version from one thread to
the next. It might change. You need to tell us again in each new thread.
bignick270



Joined: 11 Sep 2008
Posts: 44

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 12:23 pm     Reply with quote

my bad...

PIC: 16F886
8 Mhz clock

Compiler is 4.0.74

I have observed the code on a Digiview logic analyzer.

The function uses delays in between changing channel led's. The function is somewhat long so I will not post it on here but basically it goes like this

Code:

output_high(ch1G);
delay_ms(200);
output_low(ch1G);
output_high(ch2G);
..and so on


There are like 21 total delay_ms commands in this startup function. I output a test character over rs-232 at end of the function to so i can observe the timing and the function is be off by a sec or more sometimes and others it will be running roughly in the right range.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: delay functions inaccurate
PostPosted: Wed Nov 12, 2008 1:49 pm     Reply with quote

bignick270 wrote:


Is there a more accurate way to create delay functions?


Use timers.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 2:14 pm     Reply with quote

I find the CCS delay functions to be pretty accurate and VERY repeatable, as long as there are no interrupts. Could your crystal be unstable?
_________________
The search for better is endless. Instead simply find very good and get the job done.
bignick270



Joined: 11 Sep 2008
Posts: 44

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 2:16 pm     Reply with quote

it could be the problem, this chip is using the internal oscillator.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 2:35 pm     Reply with quote

This is why we want a test program. We would notice the INTRC_IO
fuse being used.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 5:55 pm     Reply with quote

The internal oscillator for these chips is quiet accurate, 1% at 25C and 2% for 0C to 85C. A one second start up difference will not be caused by this.

Normally the CCS delay functions are quiet accurate and certainly will not cause a variable delay.
For such long delay variations at start up I'm more thinking of power supply problems resetting the CPU.

Like PCM Programmer said, post a test program demonstrating your problem. Now we have to do wild guessing.
bignick270



Joined: 11 Sep 2008
Posts: 44

View user's profile Send private message

PostPosted: Thu Nov 13, 2008 7:16 am     Reply with quote

I have found a problem as I have also posted in my other topic dealing with the same chip.

I had an array length that according to the datasheet was still in good memory addresses but come to find out I was over running into reserve locations which was causing the PIC to restart. Once I changed the array spacing the delays seemed to be more constant.
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