PWM on xmega: What am I missing?

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

Hi,

I've used PWM a lot on the regular megas, but fail to make it work on an xmega. I'm using the ATxmega128A1, running at 30 MHz.

I've read the relevant values (those I think are relevant) directly from the registers, so I'm sure that the values are as listed below:

PORTC_DIR=0x9B; // PC7, PC4, PC3, PC1 and PC0 set as outputs
PR_PRPC=0x0C; // SPI and HIRES disabled on port C
TCC1_CTRLB=0x13; // Single slope PWM; CCA compare output enabled
TCC1_CTRLC=0;
TCC1_CTRLD=0; // All event stuff off
TCC1_CTRLE=0; // Byte mode off
TCC1_PER=0x0BB7; // Period register set to 2999
TCC1_CCA=0x001F; // Compare register set to 31
TCC1_CTRLA=0x01; // Timer enabled, no prescaling

I expected to get a 10 kHz signal on PC4, with a pulse width of a little more than 1 µs. Instead, I get a constant low. I've studied the Xmega A manual and several posts here, including this one:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=103575&highlight=xmega+pwm

So far, no result. Am I missing something obvious?

ErikT

You're absolutely right. This member is stupid. Please help.

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

I should add, that PC4 works nicely as an output when I control it directly, so it is not a hardware error.

Have a nice weekend!

ErikT

You're absolutely right. This member is stupid. Please help.

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

Here are a couple snippets of one of my pwm timer setups:

    PORTF.DIRSET   = 0xff;                 // setup pout, relay outputs
    PORTF.OUTSET   = 0x0f;


void setuptimerf0 (void)                   // portf timer0 PWM outputs
{                                          //
    TCF0.PER      = 4220;                  //
    TCF0.CCA      = 4000;                  //
    TCF0.CCB      = 3000;                  // compareB 15ms
    TCF0.CCC      = 1000;                  // compareC  5ma
    TCF0.CCD      = 2000;                  // compareD 25%
    TCF0.CTRLA    =  0x01;                 // Work from CPUCLK/1 11.0592mhz
    TCF0.CTRLB    =  0xf3;                 // enable compare A,B,C,D for single slope pwm
//  TCF0.INTCTRLA =  0x01;                 // Enable overflow interrupt
}

Tom Pappano
Tulsa, Oklahoma

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

I'm an Xmega newbie so examined this thread with interest.

I traced down the original code and Tom's code, and understand the register settings.

Then I noticed

Quote:

I'm using the ATxmega128A1

Aha--check the errata list for this beastie. And indeed

Quote:
8. Setting HIRES PR bit makes PWM output unavailable

Setting the HIRES Power Reduction (PR) bit for PORTx will make any Frequency or PWM output for the corresponding Timer/Counters (TCx0 and TCx1) unavailable on the pin even if the Hi-Res is not used.

Problem fix/Workaround
Do not write the HIRES PR bit on PORTx when frequency or PWM output from TCx0/1 is used.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hi Theusch,

Thanks a lot for the work you've put into it! Actually, I did read the whole errata list before the chip was even selected for the project - and then I've obviously forgotten about that one. :oops:

And, dammit, my daughter is ill today, so I can't even get to work to try it!

Thanks again! :)

You're absolutely right. This member is stupid. Please help.

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

3 days ago i was search for timer/pwm with xmega and i bookmark this link

- EVAL-04-MOTOR Xmega Development Board
http://www.bostonandroid.com/man...

- Aplication note a Code
http://www.atmel.com/devices/atx...

- ASF
http://asf.atmel.com/docs/3.5.1/...