+ Reply to Thread
Results 1 to 1 of 1

Thread: Driving a servo motor- Timer0, Timer2

  1. #1
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default Driving a servo motor- Timer0, Timer2

    This is continuous from "Driving a servo motor- Timer0, Timer1".
    This time we just modify the previous program and use Timer0 and Timer2.
    The only thing to change is to use Timer2 to set the period of the pulse.

    When TMR2 increments to the value = calculated value in PR2, TMR2 interrupt is triggered and TMR2 will start counting from zero again. There's no need to reload the value into PR2.

    To set up Timer2:

    1) Set value in PR2.
    2) Set Prescale in T2CON- bit 0 and bit 1.
    3) Set Postscale in T2CON- bit 3 to bit 6.
    4) Set TMR2ON to "1".

    2) to 4) can be set in one instruction.

    To calculate value for PR2:

    F= Fosc/ machine cycle/ Prescale/ PR2/ Postscale

    Example:

    Period= 16mS, Fosc= 4Mhz, choose Prescale= Postscale= 16

    1/0.016= 4000000/4 /16 / PR2/ 16

    PR2= 62.5 round off to 63

    Please refer program for detail. This program will make the servo motor's shaft to rotate to far right, pause, to the middle position, pause, and to the far left postion.

    Servo motor_T0T2.txt

    Next we will control the servo motor by switches connected on PortA.......
    Last edited by Wingmax; 7th December 2007 at 03:18 AM.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg


+ Reply to Thread

Similar Threads

  1. Driving a servo motor
    By Wingmax in forum Robotics Chat
    Replies: 26
    Latest: 11th February 2008, 09:56 PM
  2. Driving a servo motor- Timer0
    By Wingmax in forum Robotics Chat
    Replies: 14
    Latest: 26th November 2007, 11:24 AM
  3. Servo problems
    By bananasiong in forum Micro Controllers
    Replies: 0
    Latest: 16th September 2007, 02:16 AM
  4. Servo Controll... In reverse?
    By savage in forum Micro Controllers
    Replies: 9
    Latest: 1st December 2006, 03:11 PM
  5. Help required with servo motor controller
    By mayhem in forum Robotics Chat
    Replies: 3
    Latest: 26th May 2006, 04:21 PM

Tags for this Thread