riccardo
Member
Hello,
I am trying to set up an adjustable PWM signal on the ATMega4808. It's fairly new and the register config and features are a little unfamiliar. I have followed the "Getting started with TCA" app note, and I can see the output on the pin in the example. I am a little unsure how to use other pins..
The datasheet has "20.3.3.4.5 Port Override for Waveform Generation" and in the app note example it sas to set the pin as output where the wave should appear. The code below is the example code, but I also set a few more pins as outputs. I see nothing on these outputs however.
I think I am not quite understanding the description of how to use it. For example, if I wanted PA3 as a normal output for an LED, but was using the WGM, it sounds like PA3 will end up with the waveform on it, but I don't think this is the case. What am i missing?
I am trying to set up an adjustable PWM signal on the ATMega4808. It's fairly new and the register config and features are a little unfamiliar. I have followed the "Getting started with TCA" app note, and I can see the output on the pin in the example. I am a little unsure how to use other pins..
The datasheet has "20.3.3.4.5 Port Override for Waveform Generation" and in the app note example it sas to set the pin as output where the wave should appear. The code below is the example code, but I also set a few more pins as outputs. I see nothing on these outputs however.
I think I am not quite understanding the description of how to use it. For example, if I wanted PA3 as a normal output for an LED, but was using the WGM, it sounds like PA3 will end up with the waveform on it, but I don't think this is the case. What am i missing?
C++:
#define PERIOD_EXAMPLE_VALUE (0x01A0)
#define DUTY_CYCLE_EXAMPLE_VALUE (0x00D0)
#include <avr/io.h>
/*Using default clock 3.33MHz */ //AFAIK my chip is running at 20MHz
void TCA0_init(void);
void PORT_init(void);
void TCA0_init(void)
{
/* set waveform output on PORT A */
PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm /* enable compare
channel 0 */
| TCA_SINGLE_WGMODE_DSBOTTOM_gc; /* set dual-slope PWM
mode */
/* disable event counting */
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
/* set PWM frequency and duty cycle (50%) */
TCA0.SINGLE.PERBUF = PERIOD_EXAMPLE_VALUE;
TCA0.SINGLE.CMP0BUF = DUTY_CYCLE_EXAMPLE_VALUE;
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV4_gc /* set clock source
(sys_clk/4) */
| TCA_SINGLE_ENABLE_bm; /* start timer */
}
void PORT_init(void)
{
/* set pin 0 of PORT A as output */
PORTA.DIR |= PIN0_bm; // I see a 1kHz signal on this pin
PORTA.DIR |= PIN1_bm; // Nothing on this pin
PORTA.DIR |= PIN2_bm; // Nothing on this pin
PORTA.DIR |= PIN3_bm; // Nothing on this pin
}
int main(void)
{
PORT_init();
TCA0_init();
/* Replace with your application code */
while (1)
{
}
}