Accessing data from Split Timer (Type 2)

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will use TCD0 in split mode, to have two 8 bit timers.

It seems that there are some missing definitions in the compiler:

HCNT, LCNT, HPER, LPER.

By looking at the datasheet, I see they live in the same address as the main timer, so I could just use these:

CNTH, CNTL, PERH, PERL.

But my main concern is that I am unsure if I need to access these registers as if they were 16 bit registers (Access low byte, then high byte), or perhaps the micro will know that the timer is split, and thus access the registers independently...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My understanding is that if you use CNTH and CNTL the compiler will do 8 bit accesses, but if you use CNT it'll do a 16-bit access. And of course the same applies to the period registers. You could verify that by looking at the assembly of the output in the .lss file, as that's the final word.

Jeff Nichols

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pixel2001n wrote:
My understanding is that if you use CNTH and CNTL the compiler will do 8 bit accesses
No, this is not about the compiler, but the hardware itself. To guarantee an atomic operation, the micro has a temporary 8 bit register that is used when accessing these 16bit registers. Check the manual, section 3.11.

For example, if I just do something like:
TCD0.PERL = 85;
The operation will not be complete, since this only writes to the temporary register. The operation needs to be completed by writing the high byte.

Anyway, I have just confirmed that just by having the timer in Split mode, the registers are accessed like 8bit registers, without the use of the temporary register.

I also found another missing register definition:
CTRLF

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Obviously I shouldn't post programming advice late at night. Glad you figured it out though.

Jeff Nichols