View previous topic :: View next topic |
Author |
Message |
luvuslim
Joined: 08 Apr 2011 Posts: 4
|
delay function |
Posted: Fri Apr 08, 2011 11:35 am |
|
|
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
|
|
Posted: Fri Apr 08, 2011 11:47 am |
|
|
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
|
|
Posted: Fri Apr 08, 2011 11:48 am |
|
|
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
|
|
Posted: Fri Apr 08, 2011 11:50 am |
|
|
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
|
|
Posted: Fri Apr 08, 2011 11:55 am |
|
|
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
|
|
Posted: Fri Apr 08, 2011 12:02 pm |
|
|
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
|
|
Posted: Fri Apr 08, 2011 12:04 pm |
|
|
thanx a lot ronald.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri Apr 08, 2011 2:33 pm |
|
|
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 |
|
|
|