Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

connecting servo to a PIC

Status
Not open for further replies.

themaccabee

Full Member level 4
Joined
Apr 1, 2007
Messages
201
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
3,003
hello
Im triing to drive a servo motor with PIC16f877a
Can I connect the PIC pins directly to the servo??or is there should be a buffer or a resistor in between the servo trigger pin and the PIC pin??If so plz tell me why??
 

use a 220R resistor in series with the pic pin and the servo control pin
+5v and ground
 

i think all U have just connect 2 cabel to power and ground . And another cable to uC . And program is about make pulse signal about 1 to 2 ms and frequency is 60 Hz
 

Hi -

I am trying to interface a dc servo motor with pic16F877A, the code is written in
Basic. I don't see the hardware responding at all to the code. I think it is because of the initialization of the configuration bits. So can you help me out with what and how to initialize parameter in Basic.

Regards
Ankit
 

You can connect them directly. I have done that many times. If the servo is driven from the same supply, just make sure that there are no spikes that will upset or confuse the processor.
 
Hi -

The basic problem is that the controller kit (16F877A, 16Mhz) is not responding to the program I loaded on it. It seems that it executes the first instruction
but after that gets reseted automatically. The language in which I am programming is Basic, and the complier is MicroCode Studio. Can I have any sample code
written in any language for same controller, so that I can see the initializing parameters.

Regards
Ankit
 

Hi-

This the code :

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/23/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

@ device PIC16F877A,HS_OSC
@ device PIC16F877A,WDT_OFF
@ device PIC16F877A,PWRT_OFF
@ device PIC16F877A,DEBUG_OFF
@ device PIC16F877A,CPD_OFF
@ device PIC16F877A,PROTECT_OFF

loop: high 1
pause 20
low 1
pause 20
goto loop

end
 

what is the output port? i dont see any output..what compiler u use? PROTON IDE?
 

Hi -

HIGH 1 -- means port B.1 is made high

Regards
 

here the code

Code:
        Device 16F877A
        Xtal 16
        TRISB = %00000000
        Low PORTB
        All_Digital true

        start:
        PORTB.1 = 1
        delayms 20
        PORTB.1 = 0
        delayms 20

        goto start

i think this is help what u want
 

Controlling a servo is a little more involved than this code. See if the information from this link Controlling a Servo helps you to understand how to control the servo from a PIC.

"Servos are controlled with a 5vdc positive-going variable pulse width that repeats every 20mS. The pulse length determines the servo output shaft position but the 20mS frame rate is not position critical. The frame rate does need to repeat at least every 20mS or it will lose power or even stutter. The servo was designed for pulse widths that vary from 1.0mS to 2.0mS, where 1.5mS is centered. In the normal range the servo will move +/- 45 degrees from the centered (neutral) position.

Most servos can be positioned to around +/- 90 degrees from neutral by expanding the range to 0.75mS to 2.25mS. However, care must be taken to avoid commanding a servo beyond its capabilities. Personal experience with Hitec servos reveals all of the standard size servos can achieve a full 180 degree range. Micro and special purpose servos are often limited to less than 180 degrees."

So your entire loop should take 20ms including both when the pin is low and high; The amount of time the PIC pin is high will range from .75ms to 2.25ms in most cases.
 

Hi -

Thanks for the quick reply but wanted to know that which complier to use with the code.
I think Basic uses PAUSE instead of delayms.

Regards
 

There are many variants of BASIC and there may be different commands to pause, such as delayms, pause, or sleep. (I use FreeBASIC, but control my servos through a serially attached servo controller rather than directly. The controller I use is a Lynxmotion - SSC-32 Servo Controller) You have to be careful as some BASIC variants cannot pause in sufficiently fine increments. The pulse widths required are in the µs range. Your code has the pin high for 20ms and then low for 20ms, which is totally out of range for a hobby servo.
 

can any one help me with servo resolution.
Right now i am driving servo but it is done with steps.
how can we get a smooth rotation of servo.
i am also using the PIC16f877 microcontroller
Thanks
MAK
 
I think smooth movement of the servo motor can be achieved using a cubic spline algorithm.But the processing power required will be more.And im not quite sure whether a cubic polynomial spline equation can be successfully ran on a PIC. I had a project in which a robotic arm was controlled using hermite spline equation.We gave the start and stop points & the tangent the spline equation is used to derive the points in between(PWM values) for a smooth transition.I think the resolution can also be adjusted. We used an AVR32 calculating spline values and communicated them serially to PIC16F877A which controlled the servos..Hope this helps..
 

My problem is resolved, thanks for your help
 

Just curious ..How did u solve the problem?? :)
 

This can be achived with use of timer intrupt service routine.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top