CONFIG TCXX

Top  Previous  Next

Action

Configures the Xmega TIMER.

 

 

Syntax

CONFIG TCxx = wg , PRESCALE=pre, COMPAREA=ca, COMPAREB=cb, COMPAREC=cc, COMPARED=cd, EVENT_SOURCE= event, EVENT_ACTION=act, EVENT_DELAY=ed, RESOLUTION=res

 

 

Remarks

Depending on the Xmega processor of your choice, there are one or more timers. The Xmega uses the name of the port as part of the name. The first port that has a timer is portC. The first timer is named TCC0. Most timer ports have 2 timers. The next timer is named TCC1. Xmega timers are 16 bit but can be cascaded to 32 bit timers or be set to 8 but mode.

The possible timer names are : TCC0, TCC1, TCD0, TCD1, TCE0, TCE1, TCF0 and TCF1.

 

 

 

WG

This options sets the Timer and/or Wave Generation mode.

Possible values :

- NORMAL, no wave generation

- FREQ , frequency generation

- PWM , pulse width modulation single slope

- PWM_TOP, pwm dual slope

- PWM_BOT, pwm dual slope

- PWM_TOPBOT, pwm dual slope

- A value between 0-7 will load the mode. See table 2.

PRESCALE

The presclaler can divide the system clock that is applied to the timer. The prescaler will only divide the system clock. Possible values :

- 1 , 2, 4, 8, 64, 256, 1024

- OFF, timer is disabled

- E0, E1, E2, E3, E4, E5, E6, E7 . Event channel 0-7

- value between 0-15. This will write the value to the CTRLA register.

COMPAREx

Where x is A, B, C, or D. This is the COMPARE or CAPTURE register setup.

You may use either COMPARE or CAPTURE since the same registers are used. Each COMPARE/CAPTURE pin must be enabled if the input/output pin is used. By default they are disabled. Each TCx0 timer has 4 compare registers/pins. The TCx1 timer has two capture registers/pins.

Possible values :

ENABLED : this will enable the capture/compare register

DISABLED : this will disable the capture/compare register

0 : this will set the logic level of the compare output pin to 0.

1 : this will set the logic level of the compare output pin to 1.

 

In FREQ and PWM modes the compare pins will be set to output mode.

In CAPTURE mode, the capture pin will be set to input mode.

EVENT_SOURCE

The event channel source. Possible values :

- OFF (default)

- E0-E7

- A value between 0-15

EVENT_ACTION

The event action the timer will perform. Possible values :

- OFF

- CAPTURE, input capture

- UPDOWN, external controlled up/down count

- QDEC, quadrature decode

- RESTART , restart waveform period

- FREQ, frequency capture

- PWC, pulse width capture

EVENT_DELAY

Enabled, or disabled(default).

When this bit is set, the selected event source is delayed by one peripheral clock cycle. This feature

is intended for 32-bit input capture operation. Adding the event delay is necessary for

compensating for the carry propagation delay that is inserted when cascading two counters via

the Event System.

RESOLUTION

Timer resolution is 16 by default. A value of 8 will set the timer to 8 bit resolution. 32 is reserved for future use.(cascading timers)

 

Table 2.

Value

Mode

TOP

UPDATE

EVENT

0

NORMAL

PER

TOP

TOP

1

FREQ

CCA

TOP

TOP

2

reserved




3

PWM, single slope

PER

BOTTOM

BOTTOM

4

reserved




5

PWM, dual slope

PER

BOTTOM

TOP

6

PWM, dual slope

PER

BOTTOM

TOP and BOTTOM

7

PWM, dual slope

PER

BOTTOM

BOTTOM

 

 

A CONFIG TCxx statement will update the timer control registers immediately.  A pre scale value other than OFF will also START the timer at once.

 

 

 

Example

'-----------------------------------------------------------------
'                  (c) 1995-2010, MCS
'                  xm128-TIMER-S1.bas
'  This sample demonstrates the TIMER sample 1 from AVR1501
'  This sample uses TIMER TCD0 since TCC0 isused for the UART
'-----------------------------------------------------------------
 
$regfile = "xm128a1def.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 64
$framesize = 64
'include the following lib and code, the routines will be replaced since they are a workaround
$lib "xmega.lib"
$external _xmegafix_clear
$external _xmegafix_rol_r1014
 
'First Enable The Osc Of Your Choice , make sure to enable 32 KHz clock or use an external 32 KHz clock
Config Osc = Enabled , 32mhzosc = Enabled
 
'configure the systemclock
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
 
Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
 
'connect portE bit 0 and 1 to some LED
Config Porte = Output
 
'config timer to normal mode
Config Tcd0 = Normal , Prescale = 64
Tcd0_per = &H30                                             ' period register
 
Do
If Inkey() <> 0 Then
    Tcd0_per = Tcd0_per + 100                             ' increase period
    Print "period:" ; Tcd0_per                             ' you will see that a larger PERIOD value will cause the TIMER to overflow later and this generating a bigger delay
End If
Bitwait Tcd0_intflags.0 , Set                             ' wait for overflow
 Tcd0_intflags.0 = 1                                       ' clear flag by writing 1
Toggle Porte                                             ' toggle led
Loop