Building Error w/ ATTiny 402 using PWM provided example listed on "Getting Started with TCA"

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
 
I'm relatively new to AVR programming, so I wanted to take an existing example that I found on through the Microchip website (document is called "Getting Started with TCA" - TB3217) & program the ATTiny 402 using the PIC Kit 4 so I could get familiar with the device and hardware programming (PK 4 works - verified it doing a simple blink test on one of the pins). Specifically I want to program two pins with separate frequencies and duty cycles using PWM, so I used the example provided in the sheet as reference.
 
However, I was getting a compiling error with example 7-3 ("Generating Two PWM Signals in Split Mode Full Code Example") when I copied it from the document into MPLAB (I tried Studio 7 as well & I had the same error). The error I was getting was with the "PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;" line (I attached a screenshot for reference). I also provided the example code in the document below.
 
I'm sure it's something I'm missing, but any help would be much appreciated.
 
 
Thanks,
Ankit Patel

#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_hardRest(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)
{
;
}
}

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TB3217 is using a mega4809 for the example, you have an ATTiny 402- not the same.

 

The tiny 402 uses CTRLC in portmux to set the tca0x default/alternate outputs-

PORTMUX.CTRLC |= PORTMUX_TCA00_bm;

if you wanted the alternate pin for TCA00, or

PORTMUX.CTRLC &= ~PORTMUX_TCA00_bm;

if default pin wanted (reset value, so no need unless changed it previously)

 

Get the datasheet for the 402, find the iotn402.h header file, keep them both open for reference

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, much appreciated. I'll work on your suggestions this weekend, & hopefully everything runs smoothly.