Using Periodic Interrupt Mode Full
Code Example
#define PERIOD_EXAMPLE_VALUE (0x0CB6)
#include <avr/io.h>
#include <avr/interrupt.h>
void TCA0_init(void);
void PORT_init(void);
void TCA0_init(void)
{
TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;
TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
TCA0.SINGLE.PER = PERIOD_EXAMPLE_VALUE;
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV256_gc
| TCA_SINGLE_ENABLE_bm;
}
void PORT_init(void)
{
PORTA.DIR |= PIN0_bm;
}
ISR(TCA0_OVF_vect)
{
PORTA.OUTTGL = PIN0_bm;
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
}
int main(void)
{
PORT_init();
TCA0_init();
sei();
while (1)
{
;
}
}
Generating a Dual-Slope PWM Signal
Full Code Example
#define PERIOD_EXAMPLE_VALUE (0x01A0)
#define DUTY_CYCLE_EXAMPLE_VALUE (0x00D0)
#include <avr/io.h>
void TCA0_init(void);
void PORT_init(void);
void TCA0_init(void)
{
PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm
| TCA_SINGLE_WGMODE_DSBOTTOM_gc;
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
TCA0.SINGLE.PERBUF = PERIOD_EXAMPLE_VALUE;
TCA0.SINGLE.CMP0BUF = DUTY_CYCLE_EXAMPLE_VALUE;
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV4_gc
| TCA_SINGLE_ENABLE_bm;
}
void PORT_init(void)
{
PORTA.DIR |= PIN0_bm;
}
int main(void)
{
PORT_init();
TCA0_init();
while (1)
{
;
}
}
Generating Two PWM Signals in
Split Mode Full Code Example
#define PERIOD_EXAMPLE_VALUE_L (0xCF)
#define PERIOD_EXAMPLE_VALUE_H (0x44)
#define DUTY_CYCLE_EXAMPLE_VALUE_L (0x68)
#define DUTY_CYCLE_EXAMPLE_VALUE_H (0x11)
#include <avr/io.h>
void TCA0_init(void);
void PIN_init(void);
void TCA0_hardReset(void);
void TCA0_init(void)
{
PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;
TCA0.SPLIT.CTRLD = TCA_SPLIT_SPLITM_bm;
TCA0.SPLIT.CTRLB = TCA_SPLIT_HCMP0EN_bm
| TCA_SPLIT_LCMP0EN_bm;
TCA0.SPLIT.LPER = PERIOD_EXAMPLE_VALUE_L;
TCA0.SPLIT.LCMP0 = DUTY_CYCLE_EXAMPLE_VALUE_L;
TCA0.SPLIT.HPER = PERIOD_EXAMPLE_VALUE_H;
TCA0.SPLIT.HCMP0 = DUTY_CYCLE_EXAMPLE_VALUE_H;
TCA0.SPLIT.CTRLA = TCA_SPLIT_CLKSEL_DIV16_gc
| TCA_SPLIT_ENABLE_bm;
}
void PIN_init(void)
{
PORTA.DIR |= PIN0_bm
| PIN3_bm;
}
void TCA0_hardReset(void)
{
TCA0.SINGLE.CTRLA &= ~(TCA_SINGLE_ENABLE_bm);
TCA0.SINGLE.CTRLESET = TCA_SINGLE_CMD_RESET_gc;
}
int main(void)
{
PIN_init();
TCA0_init();
while (1)
{
;
}
}