## TimerCounter0 on Normal mode-Calculating tick intervals

8 posts / 0 new
Author
Message

hello again AVR xbins warriors
:)

I am trying to figure out the math/calculation type for getting interrupt timming on TCC0 overflow for 16bit mode, Normal mode on xmegas, using internal 32MHz RC clock.

Here is the init setup of my code

void init_timer(void)
{
TCC0.PER = 0x0100; //Period 16bit register setup
TCC0.CTRLA = 0x01; //Prescaller Fclk/1
TCC0.CTRLB = 0x00; //Normal mode timer operation
TCC0.INTCTRLA |= 0x03; //Overflow Interrupt: Level High Level(3)
PMIC.CTRL |= 0x07; //Enable high level interrupts only
}

So if TCC0.PER got 0x0100, what should be the timekeeping of my interrupt? I guess in xx.xxx microseconds :?:

No clue on Atmels app note about calculating this time intervals on just normal mode (I will use it as a base time for other tasks)

Thanks , any help appreciated (btw on simple megas like mega128 life was a little easier) :idea:

The concept is the same as in the Megas and Tinies.

32 MHz Clock gives a Period of 1/32MHz = 0.03125 microSec per clock period.

A 16 bit counter will count up to 65,535. Perhaps add one for the roll over to 0, (open for discussion by others).

0.03125 uS x 65,536 = 2.048 milliSec per Overflow Interrupt on the Timer/Counter.

(This assumes, as you stated, that the Pre-scaler = 1).

JC

But since the top value is 0x100, won't the the interrupt interval be 0.03125us * 256 = 8us?

I guess I wasn't paying attention.
I saw the Overflow interrupt, which in the language I'm using means the full size of the counter is used, and the interrupt is triggered on the overflow.

CTC Mode, is, (in the language I'm familar with), not called overflow. In this mode one sets the TOP value to trigger the interrupt.

CTC obviously gives one much finer precision in determining the interrupt rate.

I did not look at the specific set up provided, but I can...

JC

thanks guys, although in my setup, as previous well said setting the TCC0.PER =0x100 would result in 8us period , so intervals in a timming interrupted matter. I am getting on the scope 8,48us, i guess i am close

Any more ideas , are welcome ,
Have fun.

For 8us overflow time, TCC0.PER must be 0x0100-1=0x00FF. This is due to one additional clock for reset the timer from 0x00FF to 0X0000.
Also

PMIC.CTRL |= 0x07; //Enable high level interrupts only

should be

PMIC.CTRL = 0x04; //Enable high level interrupts only

Ozhan KD
Knowledge is POWER