Continue to Site

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.

  • 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?

Status
Not open for further replies.

camerart

Well-Known Member
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.
 
They can in C but I doubt Vlad made it possible.... Why? Is it an issue!!
Hi I,
I should have asked, which is the 'best way' to write to TMR0? I need to set it to a string/variable received with a serial input.. (1000-2500)
C.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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:
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top