How do i access the MSB of the 16bit timer counter?

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

This potentially to be one of the stupid question, but please help me out there. I'm using Xplain-A1. And I'm just trying to get familiarize with accessing stuff in the Xmega chip. So I use the following code to get the lower 8 bit of the 16bit Timer counter C1 register.

PORTE.OUT= ~TCC1.CNTL;

It works and can get the value to output to the LEDs. But when I do the same to access the upper 8 bit, it no longer can get a reading:

PORTE.OUT= ~TCC1.CNTH;

In the IO view, it shows that the upper 8 bits has certain value other than 0, but it's not showing it in the LEDs.

I then tried to read it directly into a variable:

variable= TCC1.CNTH;

The "variable" gets 0 all the time when in the IO view, the CNT register shows something other than a 0. I can get the 16bit value by doing:

variable2= TCC1.CNT;

But How can i just get the upper 8 bits?

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

Under 'Accessing 16-bit registers' in the xmega manual:

Quote:
For a read operation, the low-byte of the 16-bit register must be read before the high-byte. When
the low byte register is read by the CPU, the high byte of the 16-bit register is copied into the
temporary register in the same clock cycle as the low byte is read. When the high-byte is read, it
is then read from the temporary register.

So I would just do something like

variable = (TCC1.CNT >> 8);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GordonFreeman wrote:
So I would just do something like

variable = (TCC1.CNT >> 8);

Yea, i read that. I was thinking about this way to go by doing it too, but somehow i thought i can directly use the CNTH.