18 Series PIC writing to TMR

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
I need to write a WORD to the TIMER of an 18LF4431 PIC.
I've read the D/S and see that the TMR0.HB is actually a buffer and must be WRITEn to and READ in a certain order.

How do I WRITE to it please? I'm using Oshonsoft BASIC

Camerart.
 

ericgibbs

Joined Jan 29, 2010
21,477
hi C,
As you know a WORD is 16 Bits ie 2 * 8 Bit Bytes
You write WORD.HB to TMR0.HB and WORD.LB to TMR0.LB
Is this what you are asking.?
''Oshonsoft as
TMR0.LB = WORD.LB
TMR0.HB = WORD.HB

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
As you know a WORD is 16 Bits ie 2 * 8 Bit Bytes
You write WORD.HB to TMR0.HB and WORD.LB to TMR0.LB
Is this what you are asking.?
''Oshonsoft as
TMR0.LB = WORD.LB
TMR0.HB = WORD.HB

E
Morning E,
I've been looking at shifting etc, then just before you replied, tried this:

tim0h = 65535
TMR0H = tim0h.HB
TMR0L = tim0h.LB

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

and of course it verifies what you say. Thanks,
C
 
Last edited:

AlbertHall

Joined Jun 4, 2014
12,636
If you really want to get into details, read thru this link.
http://www.pcbheaven.com/picpages/The_Timer_Modules_Timer1/
That does not apply to this application. This PIC has a buffer for the high byte of the timer. When the low byte of the timer is read the PIC hardware copies the high byte to this buffer, then you read the high byte which actually reads the buffer. Therefore there is no worry about update between the two readings. A similar process applies when writing. You write the high byte first to the buffer then when you write the low byte the hardware copies the high byte from the buffer.
 

Kjeldgaard

Joined Apr 7, 2016
476
Many of PIC18 have a choice between 8 and 16 bit access to Timer0.

At the PIC18F4431 types it is T0CON.T016BIT: Timer0 16-bit control bit
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
H,
Here is the confusing section from the D/S.

I've tried it both ways as suggested by E, and it shows OK in the Oshonsoft SIM.

I am setting an INTERRUPT, so no READing.

EDIT: T0CON.T016BIT set.
C.
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
21,477
What does that mean?
Everything is controlled by the program flow.
It simply means that the program code is written in the correct syntax as to control the operation of PIC's internal hardware modules.
When programming in Assembler the programmer should know the limitations and requirements of the PIC's hardware, before writing any code.

But, the TS is using Oshonsoft Basic not Assembler, the Basic compiler will correctly determine which machine code to use to get the correct operation.
As he explained, he has already tried 'both ways' and they work.

E
 
Last edited:
Top