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

bug in delay_us()

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







bug in delay_us()
PostPosted: Sat Mar 12, 2005 4:57 pm     Reply with quote

Hi,

I have a bug in delay_us(x).
In below sample program when the delay_us(x) was used (where x is variable<255 and initalized at 12) the obtained delay value is 287us in stopwatch which is wrong. whereas when the delay_us(12) was used the obtained delay value is 12us on stopwatch which works corrrectly. Can anyone please explain me why is it happening in delay_us() function.Is there any bug in delay_us() function.Whereas delay_ms() function works correctly in both the cases.

please reply asap.
bye.

#include <16F876.h>
#device 16F876 ICD=TRUE
#use delay(clock=4000000)
#fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT
#define pin0 56
main()
{
int x;
x=12;
while(1)
{
output_high(pin0);
delay_us(x);
output_low(pin0);
output_high(pin0);
delay_us(12);
output_low(pin0);
}

}
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Sat Mar 12, 2005 5:33 pm     Reply with quote

Which version of the compiler are you using? There have been a few problems with the delays in past versions.

Also, are you certain that your oscillator/crystal is running at 4MHz?
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Sat Mar 12, 2005 5:33 pm     Reply with quote

I built this with 3.219 (you didn't, and should have, stated your version).

Try looking at the list file.... the compiler handles variables and constants *way* differently... you're only executing 1 instruction per microsecond, and the differences in the way the delay is done probably account for the extra 31 uSecs....

Try using 250 for x and the fixed value - I'd guess the delta will still be about 30 uSecs.

Solutions: use the variable approach for both and tune for your needs or crank up your processor speed to make the error smaller.

Finally - be careful with consecutive output_high/output_low instructions, especially if you speed up the processor. The reason for this caution can be found on this forum....

Good luck!
shiva



Joined: 12 Mar 2005
Posts: 2

View user's profile Send private message

bug in delay_us
PostPosted: Sun Mar 13, 2005 2:02 am     Reply with quote

Sorry i forgot about the version i used.Its v3.0.0.13
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 13, 2005 8:16 am     Reply with quote

That's not a valid version number. Look at the top of the LST file.
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