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 function

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



Joined: 08 Apr 2011
Posts: 4

View user's profile Send private message Visit poster's website

delay function
PostPosted: Fri Apr 08, 2011 11:35 am     Reply with quote

I am using a servo motor with pic 16f877a and using built in delay function for generating pulses . When i pass a constant value like 1500 or 2000 in delay_us function it works fine but when i declare variable " int16 a= 2000" and then pass "a" in same function , delay is not generated properly so is there a different way to pass a variable?????
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 11:47 am     Reply with quote

As a suggestion, I would recommend that you use a timer to generate a delay instead of the delay() function. When you use the delay function the PIC can't do anything else while it just sits there, twirling it's thumbs while it waits for the delay to finish. Using a timer will allow you to do other things, if you want, while the pulse generating routine waits for the pulse width to be generated. Simply have a timer count to a specified number and then set a flag. Evaluate this flag in your main, or other routine, and then set your outputs accordingly.

Try to stay away from a lot of delays if you can so your PIC isn't just sitting around doing nothing.

Ronald
SherpaDoug



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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 11:48 am     Reply with quote

Tell us what your compiler version is. I know with my older CCS compiler the delay function takes an INT16 constant, but only an INT8 variable. You should find info on this if you search the forum.
_________________
The search for better is endless. Instead simply find very good and get the job done.
luvuslim



Joined: 08 Apr 2011
Posts: 4

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 08, 2011 11:50 am     Reply with quote

Thanx for the reply i'll try to use timer for delay generation but my problem still remains unsolved....
luvuslim



Joined: 08 Apr 2011
Posts: 4

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 08, 2011 11:55 am     Reply with quote

My compiler version is 3.221 and both int 16 and int 8 works the same way..
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 12:02 pm     Reply with quote

Okay, with That version you can have a constant from 0 - 65535 and a variable of 0 - 255. To have a 16 bit variable you need to have version 4.xxx. That's about it.

Ronald
luvuslim



Joined: 08 Apr 2011
Posts: 4

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 08, 2011 12:04 pm     Reply with quote

thanx a lot ronald....
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 2:33 pm     Reply with quote

If you do a forum search, a 16 bit variable delay routine for the older compilers was posted some time ago. By PCM programmer I think.

Best Wishes
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