PDA

View Full Version : Writing 16 bit numbers to timer 1



bison_bloke
- 24th March 2010, 09:10
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.

aratti
- 24th March 2010, 10:44
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.

bison_bloke
- 24th March 2010, 11:01
Thanks a bunch!

So simple...