+ Reply to Thread
Results 1 to 1 of 1

Thread: Driving a servo motor- Timer0, Timer1

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

    Default Driving a servo motor- Timer0, Timer1

    This is continuous from "Driving a servo motor - Timer0."

    This time we'll use Timer0 to set the pulse width, and Timer1 to set the
    period of the pulse train. When Timer1 interrupt is software triggered, the pulses will be generated by the interrupt routine, thus the micro can do something else while generating pulses in the background. MicroController used: P16F628A.

    Driving a servo motor- Timer0, Timer1-t0t1grapha.jpg

    The period of pulses is fixed and pulse width is variable.
    The alogorithm is as follow:

    Timer1 was set for 16 mS.
    Timer0 was set for required pulse width.

    START:
    Turn on Timer1 and wait for it to overflow.
    .....Set pulse high. Turn on Timer0 and wait for Timer0 overflow.
    .....When Timer0 overflows, set pulse low. Still waiting for Timer1 overflows.
    When Timer1 overflows, it's one period. Reset values in Timer0 and Timer1 and repeat from START.

    Timer1 register is consists of TMR1H and TMR1L registers. Maximum steps of increment the two registers
    combine= 65536. For Fosc= 4Mhz, each step is 1 uS.

    Example to set value in TMR1H and TMR1L register:

    Fosc= 4Mhz
    Period of pulses= 16 mS
    Prescale= 1:1

    65536 - (16000 (in uS))/1

    = 49536
    Convert this number into binary number= 11000001 10000000

    TMR1H= 11000001 or 193d
    TMR1L= 10000000 or 128d

    Refer following program for detail of setup.
    This program only send pulses with width of 1.3 mS, which is middle position.

    Servo Motor_T0T1_C.txt

    Next we'll modify the program to use Timer0 and Timer2........
    Last edited by Wingmax; 2nd December 2007 at 04:02 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