View previous topic :: View next topic |
Author |
Message |
bignick270
Joined: 11 Sep 2008 Posts: 44
|
delay functions inaccurate |
Posted: Wed Nov 12, 2008 11:58 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 12, 2008 12:09 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
bignick270
Joined: 11 Sep 2008 Posts: 44
|
|
Posted: Wed Nov 12, 2008 12:23 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: delay functions inaccurate |
Posted: Wed Nov 12, 2008 1:49 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Nov 12, 2008 2:14 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
bignick270
Joined: 11 Sep 2008 Posts: 44
|
|
Posted: Wed Nov 12, 2008 2:16 pm |
|
|
it could be the problem, this chip is using the internal oscillator. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 12, 2008 2:35 pm |
|
|
This is why we want a test program. We would notice the INTRC_IO
fuse being used. |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Nov 12, 2008 5:55 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
bignick270
Joined: 11 Sep 2008 Posts: 44
|
|
Posted: Thu Nov 13, 2008 7:16 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|