• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can timers be written to as a WORD?

camerart

Active Member
Thread starter #1
Hi,
I'm setting a TMR0 like this:
TMR0H = %11111111
TMR0L = %11111110
Can they be written to like this:

TMR0 = 1000, or in a similar way.

Camerart.
 

Pommie

Well-Known Member
Most Helpful Member
#5
If you can't write a word then always write low byte last and read it first. The chips with a 16 bit timer0 have a feature to enable safe reading and writing of 16 bits.
 

Pommie

Well-Known Member
Most Helpful Member
#7
Try,
word=readADC()
lowByte = word and 255
highByte = word/256

Or, this may also work, (not familiar with what Osh can do)
lowByte = word
highByte=word>>8

If there is any kind of union in Oshonsoft then you may be able to use that.

Mike.
 

camerart

Active Member
Thread starter #8
Try,
word=readADC()
lowByte = word and 255
highByte = word/256

Or, this may also work, (not familiar with what Osh can do)
lowByte = word
highByte=word>>8

If there is any kind of union in Oshonsoft then you may be able to use that.

Mike.
Hi M,
I've just tried this, and it looks like it's ok:

tim0h is the ON time of a PIN tim0l is OFF.

tim0h = 65535
TMR0H = tim0h.HB
TMR0L = tim0h.LB
What do you think?
C.
 

camerart

Active Member
Thread starter #9
If you can't write a word then always write low byte last and read it first. The chips with a 16 bit timer0 have a feature to enable safe reading and writing of 16 bits.
Hi P,
I also read that the LB should be written first, but I tried changing the order of the above example, and it worked.
I'll use LB first though.
C.
 

Pommie

Well-Known Member
Most Helpful Member
#10
Assuming you're still using a 18F4331 then section 11.4 describes the reading and writing of timer0. The register TMR0H is not always TMR0H!!!

Mike.
 

camerart

Active Member
Thread starter #11
Assuming you're still using a 18F4331 then section 11.4 describes the reading and writing of timer0. The register TMR0H is not always TMR0H!!!

Mike.
Hi M,
Yes, I read that it is a buffer, but I think #8 is ok, thanks.
Still using 18LF4431.
C.
 
Last edited:

camerart

Active Member
Thread starter #13
X. HB, X. LB
You have used this before :)
Hi J,
Ok.
This proves one thing: that you have a better memory than I do;)

Actually, I was trying to separate the BYTES, but I've now found that the solution at #8 works instead.

Thanks,
C.
 

Latest threads

EE World Online Articles

Loading

 
Top