Académique Documents
Professionnel Documents
Culture Documents
2.
3.
[http://3.bp.blogspot.com/e9Thmcf7Wz4/UhEnlTfvKPI/AAAAAAAAApE/tunUHIzU_tY/s1600/DSC04852.JPG]
Figure 1. Servo motor.
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
1/7
4/9/2014
It has three wires brown, red and orange. Brown is ground wire while
red is positive and orange is for PWM signal. As servo has no other supply
wire so voltage should be supplied externally. I am using 3.3VDC for this
particular example you may use 5.0VDC. It will work on both voltages. I tried
with no load. For use with five volts you may also need to pass signal through
a level translator (3.3VDC to 5.0VDC) as DsPIC33 is working on 3.3VDC. I
also connected two push buttons with RD14 and RD15. These are for
increasing and decreasing Duty cycle of PWM signal. Which actually controls
the angle of servo motor. The complete circuit is shown in following figure 2.
[http://4.bp.blogspot.com/-dsf5HeO_fZY/UhEng9OVWhI/AAAAAAAAAo8/JrdjTCyZDc/s1600/circuit.PNG]
Figure 2. Complete Circuit.
[http://1.bp.blogspot.com/-XhPks-WMMU/UhEnfv6SkvI/AAAAAAAAAow/Y42MZfjFmLk/s1600/pulse.PNG]
Figure 3. Pulse ON time and corresponding Angle on Servo motor.
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
2/7
4/9/2014
. We have 15.6 bits resolution and hence we have 100% duty cycle on 215.6
= 49667. So for 5% duty cycle we have 49667x1/100 = 2483. On the other
hand we have 10ms total time period. And hence for 0.5ms ON pulse we
have (0.5ms/10ms)x100 = 5% this is the value of duty cycle. Now for 0o we
simply compare two values for 5% duty cycle we have PWM value 2483. All
these values will be calculated in such a way. Some of them are show in
following table.
Angle in
degrees
Corresponding
value for PWM
0o
Duty cycle
@100Hz
(10ms)
5%
2483
Corresponding
pulse width (ON
time)
0.5ms
45o
10%
4967
1.0ms
90o
15%
7450
1.5ms
135o
20%
9933
2.0ms
180o
25%
12417
2.5ms
Now you have to calculate the value of PWM that could change the
angle of servo by 1o. So here it is by subtracting the value of PWM at 0o and
180o (12417 2483 = 9934). Now this is the change in value of PWM for
change in angle of 0 to 180o. Now simply divide this value by 180 you get the
value 55.188 ignore values after decimal you have 55 value for 1o change in
angle. Take decimal values as a tolerance in angle. Now for example for
changing angle to 5o you have to add 55 times 5 in value of PWM at 0o that
is 2483 + 55x5 = 2758.
In the following figure 4. An animations shows how LCD is updated
when we increase and decrease the PWM between 5% to 25% and
ultimately change an angle of servo. In third line we have symbolic
representation of angle in degrees. While in fourth line we have
corresponding duty cycle in percentage. Which is increased or decreased by
using Up or down buttons.
[http://2.bp.blogspot.com/-84SnYDZBI1M/UhEnf789aTI/AAAAAAAAAo0/02gw3hTiu6s/s1600/anigif.gif]
Figure 4. LCD updates.
Code:
In the following figure 4. This is the main function. In which first I
Initialize the PWM one module for frequency 100Hz. Remember this
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
3/7
4/9/2014
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
4/7
4/9/2014
[http://4.bp.blogspot.com/RQNKb_o2AeU/UhEneYJaFQI/AAAAAAAAAok/DfED5RuH0S8/s1600/main1.PNG]
Figure 5. Main function Servo motor.
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
5/7
4/9/2014
Downloads:
You can download Code (MPLAB X and C30 compiler) and Schematic. Click
here [https://www.dropbox.com/s/0j5otpr999iebj2/Servo%20motor.zip]
Reading Suggestions:
[http://ibrahimlabs.blogspot.com/2013/08/gps-module-interfacing-with-pic24.html] .
[http://ibrahimlabs.blogspot.com/2013/08/how-to-interface-4x4-keypad-with-pic24.html] .
[http://ibrahimlabs.blogspot.com/2013/08/two-wirelessly-communicating-circuits.html]
[http://ibrahimlabs.blogspot.com/2013/06/how-to-get-interrupt-on-change-of-logic.html] .
protection-circuit.html]
[http://ibrahimlabs.blogspot.com/2013/08/step-by-step-home-made-pcb-tutorial-how.html]
[http://ibrahimlabs.blogspot.com/2013/08/how-to-measure-negative-and-positiveTemperature.html]
[http://ibrahimlabs.blogspot.com/2013/08/digital-ac-voltmeter-schematic-code.html]
Thats all for this post hope you will learn please
comment if you have any questions for upcoming posts
please subscribe or follow.
IbrahimLabs.blogspot.com
All the text and graphics contained on this blog belongs to owner except otherwise
mentioned. Other parties' trademarks and service marks that may be referred to herein are
the property of their respective owners. Reproducing or distributing text and graphics on
your own site is strictly not allowed without proper linking to original content and before
publishing that you should ask for permission.
Copyright 2013 IbrahimLabs. All rights reserved.
6/7
4/9/2014
View comments
8 comments
Add a comment
Top comments
1 Reply
http://ibrahimlabs.blogspot.in/2013/08/how-to-interface-servo-motor-with-pic.html
7/7