PWM with TC2 on ATXMEGA not working

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

I want to enable PWM on 7 out of 8 I/O pins on PORTC using TC2 on an ATXMEGA64A1U rev H, and I simply can't get it working.

 

The lower byte is alive (pin 0-2), but the high byte (pin 4-7) is dead.

 

 

When looking at the IO registers in the debugger, I noticed that despite setting LPER and HPER, only LPER were written. The same goes for LCNT and HCNT.

It seems like the TC is still operating as TC0 despite being set in split mode.

 

After changing this to a single write to TCC0_PER, I were able to set both LPER and HPER, but with no change to the end result (still no PWM on pin 4-7).

 

 

 

The code is quite short:

 

void TimerPwmInit(void)
{
    // Split TCC0 in two 8-bit timers.
    TCC2_CTRLE = 0b00000010;
        
    // Enable compare output and override port output register for the corresponding OCn output pin.
    TCC2_CTRLB = 0b11110111;

 

    // Reset counter
    TCC2_HCNT = 0;
    TCC2_LCNT = 0;
    
    // Set period.
    TCC0_PER = 0x7F7F;

    //TCC2_HPER = 127;
    //TCC2_LPER = 200;
    
    // Set compare value
    TCC2_HCMPD = 32;
    TCC2_HCMPC = 32;
    TCC2_HCMPB = 32;
    TCC2_HCMPA = 32;

    TCC2_LCMPD = 32;
    TCC2_LCMPC = 32;
    TCC2_LCMPB = 32;
    TCC2_LCMPA = 32;

 

    // Enable clock to timer.

    TCC2_CTRLA = 0b00000110;
}

This topic has a solution.

Last Edited: Thu. May 12, 2022 - 06:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


I tried it.

I used ATxmega128A1U.

Only PC3 does not output waveforms.



This is the waveform of PC0 and PC7.

 

This is a test code.

#include <avr/io.h>

void TimerPwmInit(void){
    // Split TCC0 in two 8-bit timers.
    TCC2_CTRLE = 0b00000010;
        
    // Enable compare output and override port output register for the corresponding OCn output pin.
    TCC2_CTRLB = 0b11110111;

    // Reset counter
    TCC2_HCNT = 0;
    TCC2_LCNT = 0;
    
    // Set period.
    //TCC0_PER = 0x7F7F;
    TCC2_HPER = 127;
    TCC2_LPER = 200;
    
    // Set compare value
    TCC2_HCMPD = 32;
    TCC2_HCMPC = 32;
    TCC2_HCMPB = 32;
    TCC2_HCMPA = 32;

    TCC2_LCMPD = 32;
    TCC2_LCMPC = 32;
    TCC2_LCMPB = 32;
    TCC2_LCMPA = 32;

    // Enable clock to timer.
    TCC2_CTRLA = 0b00000110;
}

int main(void){
    PORTC.DIRSET = 0xFF;
    TimerPwmInit();
    while (1);
}

 

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

Thank you very much for trying the code. I will create a new minimal project and try yours.

Last Edited: Mon. May 9, 2022 - 10:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've tried your code on the ATXMEGA64A1U, and it is not working. I get a PWM on pin 0..3, but with incorrect period (very slow).

 

However, when I tried the same code on an ATXMEGA192A3U, everything works as expected.

 

This is very weird, and I'm not able to switch MCU, as the boards are already produced.

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

You do not have an ATXMEGA64A1U. They were released at revision L.

 

You have an ATXMEGA64A1. The latest is revision H.

 

 

There are over 40 published errata for revision H. Who knows how many additional unpublished errata may exists.

Last Edited: Wed. May 11, 2022 - 09:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,  I thought that it was an ATxmega64A1 too.

 

Surely a datecode of 2052 would be marked Microchip and not Atmel.

 

David.

Last Edited: Wed. May 11, 2022 - 09:46 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Comparing the A1 & A1U datasheets, Table 33-3 of A1U in note 2 says all 8 pins available while Table 30-3 of A1 has no such indication.

 

Comparing the A & AU manuals, the AU has a TC2 section while the A does not.

 

The only mention I see in the A manual of the split mode is a single sentence in section 14.2. Copy/paste/proofreading mistakes are in most Atmel datasheet.s

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

Thanks a million to all of you for sorting this out.