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

Help with Servos

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



Joined: 22 Jan 2016
Posts: 2

View user's profile Send private message Yahoo Messenger

Help with Servos
PostPosted: Sat Jan 23, 2016 12:06 am     Reply with quote

Hello
I am using a PIC18F2550 at internal clock 8 Mhz and using the CCS Compiler Servos.c library with no changes in that one, using pins B1 and B2... I am simulating with proteus 8...

I am trying to control two servo motors, but I can only make them to turn in one direction. In order to control the servos I would need 1 ms pulse every 20ms to go one direction, a 2 ms pulse to go in the other direction and 1.5 ms pulse to stop it...??? I connected those pins to the virtual oscilloscope and I am getting 7 pulses in 20 ms instead of 1 and the width of the pulse is smaller than 1 ms...

Please advise...

The code I am using is just for testing:

Code:

#include <18F2550.h>
#use delay (clock=8000000)

#include <C:\Users\servos.c>

#fuses NOWDT, NOPROTECT, NODEBUG

void main()
{
enable_interrupts(GLOBAL);

init_servos();

set_servo(0,1,3);    //I picked one servo in one direction
delay_ms(100);
stop_servos();
set_servo(0,0,3);   //same servo at the opposite direction, but  does not work
delay_ms(100);
stop_servos();
}

_________________
Regards,
Thanks a lot!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sat Jan 23, 2016 2:19 am     Reply with quote

If these are normal RC servos, they don't go in a 'direction' (except for sail winch ones). They go to a position. The driver is referring to the use of DC motors controlled by servo pulses (ESC's). Which are you using?. The code as given only supports four 'speed' settings, for an ESC, and you will need to change the table (expand it a lot), to give position control for a normal servo motor. You'll also be better to alter the driver to get rid of the idea of 'direction'...

If you are controlling an ESC, then the driver is OK, except it has a very limited range of speeds.

For a standard servo, if you send 0.8 to 1mSec pulses they move to one end of their travel, if you send 1.5mSec pulses they go to centre travel, and if you send 2 to 2.2mSec pulses they go to the other end of their range. The interval between doesn't matter at all. All modern servos will support pulses sent at 400Hz, 100Hz, 50Hz, or even with long gaps 'missing' (some are programmable so that if pulses are lost for more than a particular interval, they will move to a specific location - however this is more commonly done by the RC receiver than the servo). The driver allows you to specify the minimum/maximum pulse widths, and these default to 0.9mSec to 2.1mSec.
This is all done by calculations in defines in the driver file. These calculations depend on the timer division and you must start by reading this comment:

"//// * Note: This driver uses timer one to control pulses. Edit the ////
//// line "#define TIMER_1_DIV" to configure timer one ////
//// division."

This has to be set to suit the clock rate you are running. The timer values must all fit in an int16 at your clock rate. The largest one is the one for 'LOW_TICKS'.

So do the calculation for this at your clock rate:

(int16)(((float)TIMER_RATE * (PULSE_TIME - CENTER_TIME)) - 42)

TIMER_RATE is 1000000 at the default settings.

(1000000*(0.1985)) - 42 = 198458

Much too large to fit in an INT16.

If you switch 'TIMER_1_DIV' to be 8 (the maximum), the result becomes 49614, which will then fit in the int16.

So your strange pulses are almost certainly because the value is too high at your clock rate. Use:

Code:

#define TIMER_1_DIV 8
#include <C:\Users\servos.c>


and it should start to work (bad documentation I'm afraid).

If you want to use standard servos, not ESC's, come back, and we will try to guide you through the changes needed.
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jan 23, 2016 6:27 am     Reply with quote

You also MUST BE AWARE that Proteus may (probably) will NOT run your code like a real PIC will in the real World.
Every Proteus 'schematic' presented here has serious design errors, any of which will not allow a real PIC to run. There are several serious issues that even the latest version fails to correct.

Just a warning...

As pointed out 'servos' is a generic term. Fortunately we knew by the post you're working with RC servos, a specific subset of servos. Whenever posting, it really helps to include a link to your devices or part numbers. RC servos now have 3 or 4 subsets themselves.....

Jay
jcalba87



Joined: 22 Jan 2016
Posts: 2

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Jan 23, 2016 11:21 am     Reply with quote

Thanks for replying...

I did configure the TIMER_1_DIV to 8, which by default is 2 in the Servos.c library, but I got no success.


Regarding the motors, I am not sure what I am using, how can I know if the motors are RC or ESC?...
_________________
Regards,
Thanks a lot!!!
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jan 23, 2016 12:09 pm     Reply with quote

re: motors

well as a tech you better figure out WHAT you're using real fast !! You could do serious damage to real parts by not knowing what they are !!

RC in general means Remote Control. a 'general' term for 'hobby servos' that get controlled by a 1.5ms +-.5ms series of pulses...

ESC in general means Electronic Speed Control. a device that at 1.0 ms gives zero output and at 2.0 ms gives full output from a power source controlled by a MOSFET.

You should Google 'RC servo meaning' to get more info !

Jay
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