BLDC control on ATAVRMC303 with ATxMega128A1
TC_driver.h File Reference

XMEGA Timer/Counter driver header file. More...

#include "avr_compiler.h"
Include dependency graph for TC_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TC_ClearCCAFlag(_tc)   ( (_tc)->INTFLAGS = TC0_CCAIF_bm )
 Clears the Timer/Counter compare or capture A interrupt flag. More...
 
#define TC_ClearCCBFlag(_tc)   ( (_tc)->INTFLAGS = TC0_CCBIF_bm )
 Clears the Timer/Counter compare or capture B interrupt flag. More...
 
#define TC_ClearCCCFlag(_tc)   ( (_tc)->INTFLAGS = TC0_CCCIF_bm )
 Clears the Timer/Counter compare or capture C interrupt flag. More...
 
#define TC_ClearCCDFlag(_tc)   ( (_tc)->INTFLAGS = TC0_CCDIF_bm )
 Clears the Timer/Counter compare or capture D interrupt flag. More...
 
#define TC_ClearErrorFlag(_tc)   ( (_tc)->INTFLAGS = TC0_ERRIF_bm )
 Clears the Timer/Counter error flag. More...
 
#define TC_ClearOverflowFlag(_tc)   ( (_tc)->INTFLAGS = TC0_OVFIF_bm )
 Clears the Timer/Counter overflow flag. More...
 
#define TC_DisableEventDelay(_tc)   ( (_tc)->CTRLD &= ~TC0_EVDLY_bm )
 This macro disables the event delay for this TC. More...
 
#define TC_EnableEventDelay(_tc)   ( (_tc)->CTRLD |= TC0_EVDLY_bm )
 Enables the event delay for this TC. More...
 
#define TC_ForceUpdate(_tc)   ( (_tc)->CTRLFSET = TC_CMD_UPDATE_gc )
 Force an update of the output compare and period registers. More...
 
#define TC_GetCaptureA(_tc)   ( (_tc)->CCA )
 Reads the first available input capture value for channel A. More...
 
#define TC_GetCaptureB(_tc)   ( (_tc)->CCB )
 Reads the first available input capture value for channel B. More...
 
#define TC_GetCaptureC(_tc)   ( (_tc)->CCC )
 Reads the first available input capture value for channel C. More...
 
#define TC_GetCaptureD(_tc)   ( (_tc)->CCD )
 Reads the first available input capture value for channel D. More...
 
#define TC_GetCCAFlag(_tc)   ( (_tc)->INTFLAGS & TC0_CCAIF_bm )
 Get the status for Compare or Capture channel A. More...
 
#define TC_GetCCBFlag(_tc)   ( (_tc)->INTFLAGS & TC0_CCBIF_bm )
 Get the status for Compare or Capture channel B. More...
 
#define TC_GetCCCFlag(_tc)   ( (_tc)->INTFLAGS & TC0_CCCIF_bm )
 Get the status for Compare or Capture channel C. More...
 
#define TC_GetCCDFlag(_tc)   ( (_tc)->INTFLAGS & TC0_CCDIF_bm )
 Get the status for Compare or Capture channel D. More...
 
#define TC_GetErrorFlag(_tc)   ( (_tc)->INTFLAGS & TC0_ERRIF_bm )
 Test whether an error has occurred. More...
 
#define TC_GetOverflowFlag(_tc)   ( (_tc)->INTFLAGS & TC0_OVFIF_bm )
 Test whether an overflow has occurred. More...
 
#define TC_LockCompareUpdate(_tc)   ( (_tc)->CTRLFSET = TC0_LUPD_bm )
 Locks automatic updating of compare and period registers. More...
 
#define TC_Restart(_tc)   ( (_tc)->CTRLFSET = TC_CMD_RESTART_gc )
 Restart the Timer/Counter. More...
 
#define TC_SetCompareA(_tc, _compareValue)   ( (_tc)->CCABUF = (_compareValue) )
 Set new compare value for compare channel A. ( Double buffered ) More...
 
#define TC_SetCompareB(_tc, _compareValue)   ( (_tc)->CCBBUF = (_compareValue) )
 Set new compare value for compare channel B. ( Double buffered ) More...
 
#define TC_SetCompareC(_tc, _compareValue)   ( (_tc)->CCCBUF = (_compareValue) )
 Set new compare value for compare channel C. ( Double buffered ) More...
 
#define TC_SetCompareD(_tc, _compareValue)   ( (_tc)->CCDBUF = (_compareValue) )
 Set new compare value for compare channel D. ( Double buffered ) More...
 
#define TC_SetCount(_tc, _count)   ( (_tc)->CNT = (_count) )
 Manually set the count. More...
 
#define TC_SetPeriod(_tc, _period)   ( (_tc)->PER = (_period) )
 Sets the timer period. More...
 
#define TC_SetPeriodBuffered(_tc, _period)   ( (_tc)->PERBUF = (_period) )
 Sets the timer period ( double buffered ). More...
 
#define TC_UnlockCompareUpdate(_tc)   ( (_tc)->CTRLFCLR = TC0_LUPD_bm )
 Unlocks automatic updating of compare and period registers. More...
 

Functions

void TC0_ConfigClockSource (volatile TC0_t *tc, TC_CLKSEL_t clockSelection)
 Configures clock source for the Timer/Counter 0. More...
 
void TC0_ConfigInputCapture (volatile TC0_t *tc, TC_EVSEL_t eventSource)
 Configures the Timer/Counter 0 for input capture operation. More...
 
void TC0_ConfigWGM (volatile TC0_t *tc, TC_WGMODE_t wgm)
 Configures the Waveform Generation Mode for the Timer/Counter 0. More...
 
void TC0_DisableCCChannels (volatile TC0_t *tc, uint8_t disableMask)
 Disables compare/capture channels on Timer/Counter 0. More...
 
void TC0_EnableCCChannels (volatile TC0_t *tc, uint8_t enableMask)
 Enables compare/capture channels for Timer/Counter 0. More...
 
void TC0_Reset (volatile TC0_t *tc)
 Resets the Timer/Counter 0. More...
 
void TC0_SetCCAIntLevel (volatile TC0_t *tc, TC_CCAINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel A interrupt. More...
 
void TC0_SetCCBIntLevel (volatile TC0_t *tc, TC_CCBINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel B interrupt. More...
 
void TC0_SetCCCIntLevel (volatile TC0_t *tc, TC_CCCINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel C interrupt. More...
 
void TC0_SetCCDIntLevel (volatile TC0_t *tc, TC_CCDINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel D interrupt. More...
 
void TC0_SetErrorIntLevel (volatile TC0_t *tc, TC_ERRINTLVL_t intLevel)
 Sets the Error interrupt level. More...
 
void TC0_SetOverflowIntLevel (volatile TC0_t *tc, TC_OVFINTLVL_t intLevel)
 Sets the overflow interrupt level. More...
 
void TC1_ConfigClockSource (volatile TC1_t *tc, TC_CLKSEL_t clockSelection)
 Configures clock source for the Timer/Counter 1. More...
 
void TC1_ConfigInputCapture (volatile TC1_t *tc, TC_EVSEL_t eventSource)
 Configures the Timer/Counter 1 for input capture operation. More...
 
void TC1_ConfigWGM (volatile TC1_t *tc, TC_WGMODE_t wgm)
 Configures the Waveform Generation Mode for the Timer/Counter 1. More...
 
void TC1_DisableCCChannels (volatile TC1_t *tc, uint8_t disableMask)
 Disables compare/capture channels on Timer/Counter 1. More...
 
void TC1_EnableCCChannels (volatile TC1_t *tc, uint8_t enableMask)
 Enables compare/capture channels for Timer/Counter 1. More...
 
void TC1_Reset (volatile TC1_t *tc)
 Resets the Timer/Counter 1. More...
 
void TC1_SetCCAIntLevel (volatile TC1_t *tc, TC_CCAINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel A interrupt. More...
 
void TC1_SetCCBIntLevel (volatile TC1_t *tc, TC_CCBINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel B interrupt. More...
 
void TC1_SetCCCIntLevel (volatile TC1_t *tc, TC_CCCINTLVL_t intLevel)
 
void TC1_SetCCDIntLevel (volatile TC1_t *tc, TC_CCDINTLVL_t intLevel)
 
void TC1_SetErrorIntLevel (volatile TC1_t *tc, TC_ERRINTLVL_t intLevel)
 Sets the Error interrupt level. More...
 
void TC1_SetOverflowIntLevel (volatile TC1_t *tc, TC_OVFINTLVL_t intLevel)
 Sets the overflow interrupt level. More...
 

Detailed Description

XMEGA Timer/Counter driver header file.

This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA Timer/Counter driver.

The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA Timer/Counter module.

For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.

Application note:
AVR1306: Using the XMEGA Timer/Counter
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)


Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file TC_driver.h.

Macro Definition Documentation

◆ TC_ClearCCAFlag

#define TC_ClearCCAFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_CCAIF_bm )

Clears the Timer/Counter compare or capture A interrupt flag.

Parameters
_tcTimer/Counter 0 or 1 module instance.

Definition at line 264 of file TC_driver.h.

◆ TC_ClearCCBFlag

#define TC_ClearCCBFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_CCBIF_bm )

Clears the Timer/Counter compare or capture B interrupt flag.

Parameters
_tcTimer/Counter 0 or 1 module instance.

Definition at line 286 of file TC_driver.h.

◆ TC_ClearCCCFlag

#define TC_ClearCCCFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_CCCIF_bm )

Clears the Timer/Counter compare or capture C interrupt flag.

This macro clears the Timer/Counter compare or capture C interrupt flag.

Note
The CCC channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.

Definition at line 314 of file TC_driver.h.

◆ TC_ClearCCDFlag

#define TC_ClearCCDFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_CCDIF_bm )

Clears the Timer/Counter compare or capture D interrupt flag.

This macro clears the Timer/Counter compare or capture D interrupt flag.

Note
The CCD channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.

Definition at line 342 of file TC_driver.h.

◆ TC_ClearErrorFlag

#define TC_ClearErrorFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_ERRIF_bm )

Clears the Timer/Counter error flag.

This macro clears the Timer/Counter error flag.

Parameters
_tcTimer/Counter module instance.

Definition at line 242 of file TC_driver.h.

◆ TC_ClearOverflowFlag

#define TC_ClearOverflowFlag (   _tc)    ( (_tc)->INTFLAGS = TC0_OVFIF_bm )

Clears the Timer/Counter overflow flag.

This macro clears the Timer/Counter overflow flag.

Parameters
_tcTimer/Counter module instance.

Definition at line 224 of file TC_driver.h.

◆ TC_DisableEventDelay

#define TC_DisableEventDelay (   _tc)    ( (_tc)->CTRLD &= ~TC0_EVDLY_bm )

This macro disables the event delay for this TC.

Parameters
_tcThe Timer/Counter to disable delay on.

Definition at line 80 of file TC_driver.h.

◆ TC_EnableEventDelay

#define TC_EnableEventDelay (   _tc)    ( (_tc)->CTRLD |= TC0_EVDLY_bm )

Enables the event delay for this TC.

This macro enables a one clock cycle delay of event sources for this TC. Mainly used for the high word TC when two TCs are cascaded to form a 32-bit TC.

Parameters
_tcThe Timer/Counter to enable delay on.

Definition at line 74 of file TC_driver.h.

◆ TC_ForceUpdate

#define TC_ForceUpdate (   _tc)    ( (_tc)->CTRLFSET = TC_CMD_UPDATE_gc )

Force an update of the output compare and period registers.

This macro will trigger a transfer from the output compare and period buffer registers ( CCxBUF and PERBUF ) to the output compare and period registers ( CCx and PER ). Calling this macro has the same effect as an update condition.

Parameters
_tcTimer/Counter module instance.

Definition at line 114 of file TC_driver.h.

◆ TC_GetCaptureA

#define TC_GetCaptureA (   _tc)    ( (_tc)->CCA )

Reads the first available input capture value for channel A.

This macro returns the first available input capture value for capture channel A.

Parameters
_tcTimer/Counter 0 or 1 module instance.
Returns
The first available input capture value for channel A.

Definition at line 354 of file TC_driver.h.

◆ TC_GetCaptureB

#define TC_GetCaptureB (   _tc)    ( (_tc)->CCB )

Reads the first available input capture value for channel B.

This macro returns the first available input capture value for capture channel B.

Parameters
_tcTimer/Counter 0 or 1 module instance.
Returns
The first available input capture value for channel B.

Definition at line 365 of file TC_driver.h.

◆ TC_GetCaptureC

#define TC_GetCaptureC (   _tc)    ( (_tc)->CCC )

Reads the first available input capture value for channel C.

This macro returns the first available input capture value for capture channel C.

Note
The CCC channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
Returns
The first available input capture value for channel C.

Definition at line 378 of file TC_driver.h.

◆ TC_GetCaptureD

#define TC_GetCaptureD (   _tc)    ( (_tc)->CCD )

Reads the first available input capture value for channel D.

This macro returns the first available input capture value for capture channel D.

Note
The CCD channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
Returns
The first available input capture value for channel D.

Definition at line 391 of file TC_driver.h.

◆ TC_GetCCAFlag

#define TC_GetCCAFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_CCAIF_bm )

Get the status for Compare or Capture channel A.

When the TC is in Input Capture mode, the return value of this macro indicates whether there is an unread input capture value available for capture channel A.

When the TC is in any other mode, the return value of this macro indicates whether there has been a compare match between channel A and the counter.

Parameters
_tcTimer/Counter 0 or 1 module instance.
Returns
Non-zero if Compare or capture has occured, zero otherwise.

Definition at line 258 of file TC_driver.h.

◆ TC_GetCCBFlag

#define TC_GetCCBFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_CCBIF_bm )

Get the status for Compare or Capture channel B.

When the TC is in Input Capture mode, the return value of this macro indicates whether there is an unread input capture value available for capture channel B.

When the TC is in any other mode, the return value of this macro indicates whether there has been a compare match between channel B and the counter.

Parameters
_tcTimer/Counter 0 or 1 module instance.
Returns
Non-zero if Compare or capture has occured, zero otherwise.

Definition at line 280 of file TC_driver.h.

◆ TC_GetCCCFlag

#define TC_GetCCCFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_CCCIF_bm )

Get the status for Compare or Capture channel C.

When the TC is in Input Capture mode, the return value of this macro indicates whether there is an unread input capture value available for capture channel C.

When the TC is in any other mode, the return value of this macro indicates whether there has been a compare match between channel C and the counter.

Note
The CCC channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
Returns
Non-zero if Compare or capture has occured, zero otherwise.

Definition at line 304 of file TC_driver.h.

◆ TC_GetCCDFlag

#define TC_GetCCDFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_CCDIF_bm )

Get the status for Compare or Capture channel D.

When the TC is in Input Capture mode, the return value of this macro indicates whether there is an unread input capture value available for capture channel D.

When the TC is in any other mode, the return value of this macro indicates whether there has been a compare match between channel D and the counter.

Note
The CCD channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
Returns
Non-zero if Compare or capture has occured, zero otherwise.

Definition at line 332 of file TC_driver.h.

◆ TC_GetErrorFlag

#define TC_GetErrorFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_ERRIF_bm )

Test whether an error has occurred.

The return value of this macro indicates if an error has occurred.

Parameters
_tcTimer/Counter module instance.
Returns
Non-zero if the Timer error flag is set.

Definition at line 234 of file TC_driver.h.

◆ TC_GetOverflowFlag

#define TC_GetOverflowFlag (   _tc)    ( (_tc)->INTFLAGS & TC0_OVFIF_bm )

Test whether an overflow has occurred.

The return value of this macro indicates if an overflow has occurred.

Parameters
_tcTimer/Counter module instance.
Returns
Non-zero if overflow flag is set, zero otherwise.

Definition at line 216 of file TC_driver.h.

◆ TC_LockCompareUpdate

#define TC_LockCompareUpdate (   _tc)    ( (_tc)->CTRLFSET = TC0_LUPD_bm )

Locks automatic updating of compare and period registers.

This macro will lock automatic updates of compare registers from the corresponding buffer registers. To enable automatic updates again, use the TC_UnlockCompareUpdate macro.

Parameters
_tcTimer/Counter module instance.

Definition at line 90 of file TC_driver.h.

◆ TC_Restart

#define TC_Restart (   _tc)    ( (_tc)->CTRLFSET = TC_CMD_RESTART_gc )

Restart the Timer/Counter.

This macro will restart the timer. The effect of running this command is:

  • The CNT[H:L] register is cleared.
  • The direction (DIR ) is reset. (Next clock cycle will increase the counter )
  • All compare outputs are set to 0.
  • If a DTI module is connected to the timer, it will be reset as well.
Parameters
_tcTimer/Counter module instance.

Definition at line 126 of file TC_driver.h.

◆ TC_SetCompareA

#define TC_SetCompareA (   _tc,
  _compareValue 
)    ( (_tc)->CCABUF = (_compareValue) )

Set new compare value for compare channel A. ( Double buffered )

This macro sets a new compare value for compare channel A. The compare channel A buffer register is used, so the new period will be valid from the next update condition.

Parameters
_tcTimer/Counter 0 or 1 module instance.
_compareValueNew compare value for compare channel A.

Definition at line 169 of file TC_driver.h.

Referenced by mc_duty_cycle().

◆ TC_SetCompareB

#define TC_SetCompareB (   _tc,
  _compareValue 
)    ( (_tc)->CCBBUF = (_compareValue) )

Set new compare value for compare channel B. ( Double buffered )

This macro sets a new compare value for compare channel B. The compare channel B buffer register is used, so the new period will be valid from the next update condition.

Parameters
_tcTimer/Counter 0 or 1 module instance.
_compareValueNew compare value for compare channel B.

Definition at line 180 of file TC_driver.h.

Referenced by mc_duty_cycle().

◆ TC_SetCompareC

#define TC_SetCompareC (   _tc,
  _compareValue 
)    ( (_tc)->CCCBUF = (_compareValue) )

Set new compare value for compare channel C. ( Double buffered )

This macro sets a new compare value for compare channel C. The compare channel C buffer register is used, so the new period will be valid from the next update condition.

Note
The CCC channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
_compareValueNew compare value for compare channel C.

Definition at line 193 of file TC_driver.h.

Referenced by mc_duty_cycle().

◆ TC_SetCompareD

#define TC_SetCompareD (   _tc,
  _compareValue 
)    ( (_tc)->CCDBUF = (_compareValue) )

Set new compare value for compare channel D. ( Double buffered )

This macro sets a new compare value for compare channel D. The compare channel D buffer register is used, so the new period will be valid from the next update condition.

Note
The CCD channel is not available on TCx1.
Parameters
_tcTimer/Counter 0 module instance.
_compareValueNew compare value for compare channel D.

Definition at line 206 of file TC_driver.h.

◆ TC_SetCount

#define TC_SetCount (   _tc,
  _count 
)    ( (_tc)->CNT = (_count) )

Manually set the count.

This macro writes a new value to the CNT[H:L] register. Note that the CNT[H:L] register is not double buffered, so it is recommended that the timer is not running when this macro is used.

Parameters
_tcTimer/Counter module instance.
_countNew count value.

Definition at line 137 of file TC_driver.h.

◆ TC_SetPeriod

#define TC_SetPeriod (   _tc,
  _period 
)    ( (_tc)->PER = (_period) )

Sets the timer period.

This macro sets a new timer period. The period buffer register is not used, so the new period will be valid immediately after the 16-bit write is finished.

Parameters
_tcTimer/Counter module instance.
_periodNew Timer/Counter period.

Definition at line 148 of file TC_driver.h.

◆ TC_SetPeriodBuffered

#define TC_SetPeriodBuffered (   _tc,
  _period 
)    ( (_tc)->PERBUF = (_period) )

Sets the timer period ( double buffered ).

This macro sets a new timer period. The period buffer register is used, so the new period will be valid after the next update condition.

Parameters
_tcTimer/Counter 0 or 1 module instance.
_periodNew Timer/Counter period.

Definition at line 158 of file TC_driver.h.

◆ TC_UnlockCompareUpdate

#define TC_UnlockCompareUpdate (   _tc)    ( (_tc)->CTRLFCLR = TC0_LUPD_bm )

Unlocks automatic updating of compare and period registers.

This macro will unlock automatic updates of compare registers from the corresponding buffer registers. Note that the output compare registers will not be updated until an update event occurs, e.g. that the counter hits TOP or BOTTOM. To force an update of the compare register from the buffer register, use the TC_ForceUpdate macro.

Parameters
_tcTimer/Counter module instance.

Definition at line 102 of file TC_driver.h.

Function Documentation

◆ TC0_ConfigClockSource()

void TC0_ConfigClockSource ( volatile TC0_t *  tc,
TC_CLKSEL_t  clockSelection 
)

Configures clock source for the Timer/Counter 0.

This function clears the old clock source setting of the Timer/Counter and sets a new clock source according to the clockSelection parameter.

Parameters
tcTimer/Counter module instance.
clockSelectionTimer/Counter clock source setting.

Definition at line 79 of file TC_driver.c.

80 {
81  tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | clockSelection;
82 }

◆ TC0_ConfigInputCapture()

void TC0_ConfigInputCapture ( volatile TC0_t *  tc,
TC_EVSEL_t  eventSource 
)

Configures the Timer/Counter 0 for input capture operation.

This function sets the Timer/Counter in input capture mode and selects the event lines that will trigger the individual input capture channels.

Note
Output compare operation is disabled when input capture operation is enabled.
Parameters
tcTimer/Counter module instance.
eventSourceEvent source selection.

Definition at line 137 of file TC_driver.c.

138 {
139  tc->CTRLD = ( tc->CTRLD & ~( TC0_EVSEL_gm | TC0_EVACT_gm ) ) |
140  eventSource |
141  TC_EVACT_CAPT_gc;
142 }

◆ TC0_ConfigWGM()

void TC0_ConfigWGM ( volatile TC0_t *  tc,
TC_WGMODE_t  wgm 
)

Configures the Waveform Generation Mode for the Timer/Counter 0.

This function clears the old WGM setting of the Timer/Counter and sets a new WGM setting according to the wgm parameter.

Parameters
tcTimer/Counter module instance.
wgmWaveform generation mode.

Definition at line 106 of file TC_driver.c.

107 {
108  tc->CTRLB = ( tc->CTRLB & ~TC0_WGMODE_gm ) | wgm;
109 }

◆ TC0_DisableCCChannels()

void TC0_DisableCCChannels ( volatile TC0_t *  tc,
uint8_t  disableMask 
)

Disables compare/capture channels on Timer/Counter 0.

This function disables compare/capture channels according to the supplied disableMask. The disableMask can be obtained by ORing together the symbols

  • TC0_CCAEN_bm
  • TC0_CCBEN_bm
  • TC0_CCCEN_bm
  • TC0_CCDEN_bm

Example: TC0_DisableCCChannels( &TCC0, TC0_CCAEN_bm | TC0_CCCEN_bm ) will disable channels A and C.

Parameters
tcTimer/Counter module instance.
disableMaskMask of channels to disable.

Definition at line 232 of file TC_driver.c.

233 {
234  /* Make sure only CCxEN bits are set in disableMask. */
235  disableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
236 
237  /* Disable channels. */
238  tc->CTRLB &= ~disableMask;
239 }

◆ TC0_EnableCCChannels()

void TC0_EnableCCChannels ( volatile TC0_t *  tc,
uint8_t  enableMask 
)

Enables compare/capture channels for Timer/Counter 0.

This function enables compare/capture channels according to the supplied enableMask. The enableMask can be obtained by ORing together the symbols

  • TC0_CCAEN_bm
  • TC0_CCBEN_bm
  • TC0_CCCEN_bm
  • TC0_CCDEN_bm

Example: TC0_EnableCCChannels( &TCC0, TC0_CCAEN_bm | TC0_CCCEN_bm ) will enable channels A and C.

Note
No capture/compare channels are disabled by calling this function. Disabling is done by calling TC0_DisableCCChannels.
Parameters
tcTimer/Counter module instance.
enableMaskMask of channels to enable.

Definition at line 182 of file TC_driver.c.

183 {
184  /* Make sure only CCxEN bits are set in enableMask. */
185  enableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
186 
187  /* Enable channels. */
188  tc->CTRLB |= enableMask;
189 }

◆ TC0_Reset()

void TC0_Reset ( volatile TC0_t *  tc)

Resets the Timer/Counter 0.

This function will reset the Timer/Counter. After calling this function, the Timer/Counter will be in the same state as it would after a full reset of the device.

Parameters
tcTimer/Counter 0 module instance.

Definition at line 408 of file TC_driver.c.

409 {
410  /* TC must be turned off before a Reset command. */
411  tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
412 
413  /* Issue Reset command. */
414  tc->CTRLFSET = TC_CMD_RESET_gc;
415 }

◆ TC0_SetCCAIntLevel()

void TC0_SetCCAIntLevel ( volatile TC0_t *  tc,
TC_CCAINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel A interrupt.

This function sets the interrupt level for compare/capture channel A interrupt in Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel A interrupt level.

Definition at line 324 of file TC_driver.c.

325 {
326  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCAINTLVL_gm ) | intLevel;
327 }

◆ TC0_SetCCBIntLevel()

void TC0_SetCCBIntLevel ( volatile TC0_t *  tc,
TC_CCBINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel B interrupt.

This function sets the interrupt level for compare/capture channel B interrupt in Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel B interrupt level.

Definition at line 352 of file TC_driver.c.

353 {
354  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCBINTLVL_gm ) | intLevel;
355 }

◆ TC0_SetCCCIntLevel()

void TC0_SetCCCIntLevel ( volatile TC0_t *  tc,
TC_CCCINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel C interrupt.

This function sets the interrupt level for compare/capture channel C interrupt in Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel A interrupt level.

Definition at line 380 of file TC_driver.c.

381 {
382  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCCINTLVL_gm ) | intLevel;
383 }

◆ TC0_SetCCDIntLevel()

void TC0_SetCCDIntLevel ( volatile TC0_t *  tc,
TC_CCDINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel D interrupt.

This function sets the interrupt level for compare/capture channel D interrupt in Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel A interrupt level.

Definition at line 394 of file TC_driver.c.

395 {
396  tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCDINTLVL_gm ) | intLevel;
397 }

◆ TC0_SetErrorIntLevel()

void TC0_SetErrorIntLevel ( volatile TC0_t *  tc,
TC_ERRINTLVL_t  intLevel 
)

Sets the Error interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew error interrupt level.

Definition at line 297 of file TC_driver.c.

298 {
299  tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_ERRINTLVL_gm ) | intLevel;
300 }

◆ TC0_SetOverflowIntLevel()

void TC0_SetOverflowIntLevel ( volatile TC0_t *  tc,
TC_OVFINTLVL_t  intLevel 
)

Sets the overflow interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 0.

Parameters
tcTimer/Counter module instance.
intLevelNew overflow interrupt level.

Definition at line 271 of file TC_driver.c.

272 {
273  tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_OVFINTLVL_gm ) | intLevel;
274 }

◆ TC1_ConfigClockSource()

void TC1_ConfigClockSource ( volatile TC1_t *  tc,
TC_CLKSEL_t  clockSelection 
)

Configures clock source for the Timer/Counter 1.

This function clears the old clock source setting of the Timer/Counter and sets a new clock source according to the clockSelection parameter.

Parameters
tcTimer/Counter module instance.
clockSelectionTimer/Counter clock source setting.

Definition at line 92 of file TC_driver.c.

93 {
94  tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | clockSelection;
95 }

◆ TC1_ConfigInputCapture()

void TC1_ConfigInputCapture ( volatile TC1_t *  tc,
TC_EVSEL_t  eventSource 
)

Configures the Timer/Counter 1 for input capture operation.

This function sets the Timer/Counter in input capture mode and selects the event lines that will trigger the individual input capture channels.

Note
Output compare operation is disabled when input capture operation is enabled.
Parameters
tcTimer/Counter module instance.
eventSourceEvent source selection.

Definition at line 156 of file TC_driver.c.

157 {
158  tc->CTRLD = ( tc->CTRLD & ~( TC1_EVSEL_gm | TC1_EVACT_gm ) ) |
159  eventSource |
160  TC_EVACT_CAPT_gc;
161 }

◆ TC1_ConfigWGM()

void TC1_ConfigWGM ( volatile TC1_t *  tc,
TC_WGMODE_t  wgm 
)

Configures the Waveform Generation Mode for the Timer/Counter 1.

This function clears the old WGM setting of the Timer/Counter and sets a new WGM setting according to the wgm parameter.

Parameters
tcTimer/Counter module instance.
wgmWaveform generation mode.

Definition at line 120 of file TC_driver.c.

121 {
122  tc->CTRLB = ( tc->CTRLB & ~TC1_WGMODE_gm ) | wgm;
123 }

◆ TC1_DisableCCChannels()

void TC1_DisableCCChannels ( volatile TC1_t *  tc,
uint8_t  disableMask 
)

Disables compare/capture channels on Timer/Counter 1.

This function disables compare/capture channels according to the supplied disableMask. The disableMask can be obtained by ORing together the symbols

  • TC1_CCAEN_bm
  • TC1_CCBEN_bm

Example: TC1_DisableCCChannels( &TCC1, TC1_CCAEN_bm | TC1_CCBEN_bm ) will disable channels A and B.

Parameters
tcTimer/Counter module instance.
disableMaskMask of channels to disable.

Definition at line 255 of file TC_driver.c.

256 {
257  /* Make sure only CCxEN bits are set in disableMask. */
258  disableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
259 
260  /* Disable channels. */
261  tc->CTRLB &= ~disableMask;
262 }

◆ TC1_EnableCCChannels()

void TC1_EnableCCChannels ( volatile TC1_t *  tc,
uint8_t  enableMask 
)

Enables compare/capture channels for Timer/Counter 1.

This function enables compare/capture channels according to the supplied enableMask. The enableMask can be obtained by ORing together the symbols

  • TC1_CCAEN_bm
  • TC1_CCBEN_bm

Example: TC1_EnableCCChannels( &TCC1, TC1_CCAEN_bm | TC1_CCBEN_bm ) will enable channels A and B.

Note
No capture/compare channels are disabled by calling this function. Disabling is done by calling TC1_DisableCCChannels.
Parameters
tcTimer/Counter module instance.
enableMaskMask of channels to enable.

Definition at line 207 of file TC_driver.c.

208 {
209  /* Make sure only CCxEN bits are set in enableMask. */
210  enableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
211 
212  /* Enable channels. */
213  tc->CTRLB |= enableMask;
214 }

◆ TC1_Reset()

void TC1_Reset ( volatile TC1_t *  tc)

Resets the Timer/Counter 1.

This function will reset the Timer/Counter. After calling this function, the Timer/Counter will be in the same state as it would after a full reset of the device.

Parameters
tcTimer/Counter 1 module instance.

Definition at line 426 of file TC_driver.c.

427 {
428  /* TC must be turned off before a Reset command. */
429  tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
430 
431  /* Issue Reset command. */
432  tc->CTRLFSET = TC_CMD_RESET_gc;
433 }

◆ TC1_SetCCAIntLevel()

void TC1_SetCCAIntLevel ( volatile TC1_t *  tc,
TC_CCAINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel A interrupt.

This function sets the interrupt level for compare/capture channel A interrupt in Timer/Counter 1.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel A interrupt level.

Definition at line 338 of file TC_driver.c.

339 {
340  tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCAINTLVL_gm ) | intLevel;
341 }

◆ TC1_SetCCBIntLevel()

void TC1_SetCCBIntLevel ( volatile TC1_t *  tc,
TC_CCBINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel B interrupt.

This function sets the interrupt level for compare/capture channel B interrupt in Timer/Counter 1.

Parameters
tcTimer/Counter module instance.
intLevelNew compare/capture channel B interrupt level.

Definition at line 366 of file TC_driver.c.

367 {
368  tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCBINTLVL_gm ) | intLevel;
369 }

◆ TC1_SetCCCIntLevel()

void TC1_SetCCCIntLevel ( volatile TC1_t *  tc,
TC_CCCINTLVL_t  intLevel 
)

◆ TC1_SetCCDIntLevel()

void TC1_SetCCDIntLevel ( volatile TC1_t *  tc,
TC_CCDINTLVL_t  intLevel 
)

◆ TC1_SetErrorIntLevel()

void TC1_SetErrorIntLevel ( volatile TC1_t *  tc,
TC_ERRINTLVL_t  intLevel 
)

Sets the Error interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 1.

Parameters
tcTimer/Counter module instance.
intLevelNew error interrupt level.

Definition at line 310 of file TC_driver.c.

311 {
312  tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_ERRINTLVL_gm ) | intLevel;
313 }

◆ TC1_SetOverflowIntLevel()

void TC1_SetOverflowIntLevel ( volatile TC1_t *  tc,
TC_OVFINTLVL_t  intLevel 
)

Sets the overflow interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 1.

Parameters
tcTimer/Counter module instance.
intLevelNew overflow interrupt level.

Definition at line 284 of file TC_driver.c.

285 {
286  tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_OVFINTLVL_gm ) | intLevel;
287 }