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

Need Help on RC Servo Ramp (speed)

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



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

Need Help on RC Servo Ramp (speed)
PostPosted: Fri Jan 08, 2010 8:19 pm     Reply with quote

Hi, all CCS member and Happy new year!!

I am a student at Singapore, I got a project about controlling 16 RCservo motors on PORTB & PORTC. Currently I am using 16F877A & 20MHz. I can control position but my problem now is how to control RC servo speed (ramp)?

Can PIC16F877A do a ramp program? Using which PIN? CCP? T0M1L Or T1M1L? Or it can only be done using DSPIC

Can anyone teach me the theory behind or could you just give me reference book or website. I have been searching on internet but cannot find it.

Thank you very much for your time and it is a big help if anyone can share some knowledge with me.
Ttelmah
Guest







PostPosted: Sat Jan 09, 2010 4:02 am     Reply with quote

The ramp won't involve a pin.
It will be down to how _you_ control your pulse widths.

For instance. You have a servo at one end of it's travel, with a pulse coming to it,of perhaps 0.6mSec. You want to move it to the other end of it's travel, so you change the pulse to 2.4mSec. The servo will move as fast as it can to this new position.
If instead, you change the pulse to 0.7mSec, count 100 loops of the servo pulse code, change it to 0.8mSec, count another 100 loops, and do this till the value reaches 2.4mSec, the servo will now take 1700+ cycles of your code, to move the distance.
So, you need to control the rate at which you change the pulse widths when moving. Down to some counting. Hw to do it, will depend on how your servo code is implemented, what the loop time is, what rates you want, etc. etc..

Best Wishes
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

RC Servo Ramp (speed)
PostPosted: Sat Jan 09, 2010 7:53 am     Reply with quote

ok Shocked

Because I have more than 2 RC servos, I have to generate PWM manually using loop.

Exp for 1 servo:
Code:


int i;

void main()

{
while(1)
  {

    (i=0;i>50;i++)
      {
          portB=0x00;
          delay_us(1000);
          portB=0x01;
          delay_us(19000);
       }

    (i=0;i>50;i++)
       {
          portB=0x00;
          delay_us(2000);
          portB=0x01;
          delay_us(18000);
       }
   }
}


This example I try to move the RC servo from 0 - 180 deg..

1) To make the servo ramp, do I have to change from i++ to i=i+0.1?

2) Is the i>50 have effect on RC servo speed if I increase or decrease or it is just to make it hold RC servo longer?

3) I see in some RC servo controller board, it can support up to 63 ramp rate. What is that mean? Is it a change in i++?
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Jan 09, 2010 5:14 pm     Reply with quote

You can generate PWM using timer interrupt Wink

Look on forum I have posted an example for 8 servos on PIC18F4550 but it should not be a problem to recode it for your need.

Then you'll have to do ramping in your main code, but that will be easier because interrupt will take care of PWM for all the servos at "once"
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Sat Jan 09, 2010 10:04 pm     Reply with quote

I was all set to say that this is a tough little problem, but now I think I see the solution--you don't try to run the servo pulses all at once, but in sequence. First of all, make the servo refresh rate 32msec instead of the conventional 20 msec; apparently they still work OK if this is done. Dedicate the first 2msec of the 32msec to Unit 0, the next 2 msec to Unit 1 etc up to unit 15. That way, you only have to produce one pulse at a time, which means closely-matched intervals don't cause problems when they almost coincide, but not exactly. Just count through the 16 settings and generate a time interval for each. It seems workable. Use a proper timer with an interrupt and not that horrible delay() function.

I've only ever played with very cheap little servos, but what I found when I tried to control the speed was that they responded with a sequence of jerks rather than smooth motion. Maybe higher quality ones would be better, but you might have to live with less than perfectly smooth action.

Oh wait--the servo pulse never goes below 1msec. So maybe you could keep the 20msec cycle, but instead of having the units operate one after another, you could overlap the operating periods, starting each one when the previous one reached 1msec. That way, when Unit 0 ended (between 1msec and 2msec) Unit 1 would be running, but Unit 1 wouldn't end until a time between 2msec and 3msec, and by then you'd have started Unit 2, and so forth. You could use one timer to generate the repeated 1msec start times, and a second timer whose start and stop times would be interleaved with the first one, to produce the servo pulses. Would that be fun, or what?
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Thu Jan 14, 2010 3:25 am     Reply with quote

Hi bungee-

I still don't understand your coding on http://www.ccsinfo.com/forum/viewtopic.php?p=115112#115112. Is it for remote control flight?

1) I have compile and try to simulate in proteus ISIS, but nothing happen? Do the program is waiting user to give input then it will move to certain position?

2)Is PPM same with PWM?

3) And how to do ramping program? Can you write down some program. Because I have try hard to understand your program.

Thanks
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Thu Jan 14, 2010 4:25 pm     Reply with quote

#1 - code there is correct, but the part where the servo's are moved is missing. If you want to move servo you just set the variable servo[x] to some value in the main program loop there where I put the delay_cycles(1). like: servo[3]=19;

#3 - So if you wan't to slowly move servo then you can do that in a loop in a main part of program like that:
Code:

for (i=0;i<=64;i++)
      {
            servo[2]=i;
            delay_ms(50);
      }


This code will move second servo from one end to the other in two seconds. In my code every servo have 65 possible positions, so 0 and 64 are final positions. And you can control 8 servos with that code.

To do a little bit more explaining. Program is based on timer interrupt and this timer will overflow every 1/64 of milisecond. Servos will react on pulses that are 1~2ms long. First in this interrupt routine I make shure that every servo gets 1ms long signal. Then according to position demand I prolong this signal. After this part there is 20ms pause as servos like it Wink


This code was only implemented in some tests I didn't use it in RC flight .... just some fun with servos Wink

#2 - I don't really understand the question. Please collaborate.
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