Writing 16 bit numbers to timer 1


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    12

    Default Writing 16 bit numbers to timer 1

    Hey all, I'm a newbie with a newbie question.

    I'm trying to find out how to write to timer1(16bit) with a decimal variable that constantly changes. I can't input it manually because it's always different.

    From looking through the datasheet it seems I need to write to both the high and low 'pair' with half the 16 bit value going to each, ie. tmr1H = 255, tmr1L = 255. I don't know how to do this automaticly from a value such as 34657, and I don't know ASM.

    Here's an attempt at some code:

    IF SERVO1 = 1 THEN
    TMR1 = (65535 - TMROFF)
    LOW SERVO1
    ENDIF

    This obviously didn't work.

    I'm trying to control a servo, and I need to be able to vary the angle constantly.

    I tried using Darryl Taylors servo include, but a.) I couldn't get it to work, and b.) I need to run two servos at once and half of his program is in ASM so I can't modify it.

    Thanks for any help.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I don't know how to do this automaticly from a value such as 34657, and I don't know ASM.
    Hi bison_bloke, just devide your number as the below example.

    tmr1H = 34657/256 ' (extract the high byte)

    tmr1L = 34657-(tmr1H*256) ' (extract the low byte)


    Al.
    Last edited by aratti; - 24th March 2010 at 10:52.
    All progress began with an idea

  3. #3
    Join Date
    Mar 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Thanks a bunch!

    So simple...

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts