2
\$\begingroup\$

I recently finished a project programming a PIC18F2620. All was good, but I decided to explore the new stuff Microchip has to offer, and am now trying out the PIC18F47Q43.

I'm getting a strange problem when loading a value into Timer 0. For the 18F2620, all you had to write in MPLAB was "TRM0 = 65535" and boom the thing has it's 16 bit value. When I try and do the same with this micro though, it's saying its not a 16 bit register, and I'm getting this error:

enter image description here

I know that TMR0 isn't actually a register, it is just a tool put together in XC8 to make things easier, but they wouldn't have revoked this feature in later releases would they?

If they have taken away this feature, can you please help me figure out how to load these timers with 16 bit values. I'm using MPLAB IDE and XC8 2.30 (the latest version).

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Not an answer yet because I don't have confidence, but can you try writing the value as 255 into TMR0L and 255 into TMR0H? Datasheet page 380 suggests that the timer register is split into two. \$\endgroup\$
    – nanofarad
    Sep 3, 2020 at 15:29
  • 1
    \$\begingroup\$ Refer to the datasheet section 24.1.2 on page 380 (as nanofarad commented above). You need to write TMR0H & TMR0L individually - and you must write TMR0H before TMR0L. When reading it's the opposite, so read TMR0L then TMR0H. \$\endgroup\$
    – brhans
    Sep 3, 2020 at 15:55
  • \$\begingroup\$ There should be a config or register for 16-bit timer value. You must chage it. Read datasheet. Never used this pic but I saw that in others. \$\endgroup\$ Sep 3, 2020 at 21:34
  • \$\begingroup\$ Check the XC8 header file for this particular processor. You might find it’s not named TMR0 for some reason. For example if there is an 8-bit mode, as hunted by other answers, it would not make sense to always write 16 bits. \$\endgroup\$
    – David
    Sep 3, 2020 at 22:19

2 Answers 2

3
\$\begingroup\$

Everyone is right about the reading and writing order of the two 8 bit registers. I've also found the XC8 functions WRITETIMERx(value) & READTIMERx() which control the correct reading and writing procedures of the TMRxH and TMRxL registers.

Additionally, the PIC18F47Q43 datasheet states that while Timer 0 is active in 16-bit mode, no writes are allowed.

///////////////////////////////////////////[FROM PAGE 380]

enter image description here

//////////////////////////////////////////////////////////////////////////

Upon reading this I initially thought all you had to do before writing a 16-bit value was disable the timer in OSCCON0, but that is not the case for this particular device. Good thing Timer 0 has a plethora of pre and post scaling options to pick from.

NOTE: In 8-bit mode, an overflow interrupt gets flagged when TMR0L matches TMR0H, so to control the period just have to write your values to the TMR0H register.

\$\endgroup\$
3
\$\begingroup\$

in the data sheet

section: 24.1

page 379,

It states that the time 0 can be either 16 bit or 8 bit.

Timer0 can operate as either an 8-bit or 16-bit timer. The mode is selected with the MD16 bit

24.5.1 T0CON0
Name: T0CON0
Address: 0x31A

the bit of interest is bit 4 of the T0CON0 register

Bit 4 – MD16 16-Bit Timer Operation
when the bit is set to 1 TMR0 is a 16-bit timer
when the bit is set to 0 TMR0 is an 8-bit timer

also:

Timer0 Output
TMR0_out
8-bit mode: toggles on every match between TMR0L and TMR0H
15-bit mode: toggles every time TMR0H:TMR0L rolls over

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.