4-channels pwm generation

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

Hi

I use ATXMEGA128A1 and the following code for 4-channels pwm generation:

void pwmSet(u08 channel, u16 value)
{

// Setup timer
TCC0_CTRLA = 0x01; // divide clock by 1
TCC0_PER = 0x0FFF; // set resolution to 12 bits
switch(channel){
case 0:
TCC0_CCA = value; // duty cycle A
break;
case 1:	
TCC0_CCB = val;   // B
break;
case 2:	
TCC0_CCC = val;   // C
break;
case 3:	
TCC0_CCD = val;   // D
}	
TCC0_CTRLB = 0xF3; /* enable frequency generation for all 4 Channels */

}

there is a problem. it is only channel D (PE3) does not work!
all for pins has set as outputs.
PE4 & PE5 are used as inputs and PE6 & PE7 as Rx1/Tx1 uart.

have I to replace ATXMEGA128A1 ? or it is a software issue ?

regards

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

navidnavid wrote:

there is a problem. it is only channel D (PE3) does not work!
PE4 & PE5 are used as inputs and PE6 & PE7 as Rx1/Tx1 uart.


TCC0 outputs are on PORTC and PE3 is a pwm output for TCE0.

Ozhan KD
Knowledge is POWER

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

sorry
I use both 4-pwm-channels of TCC0 and TCE0
TCC0 is good and the problem is only in channel D of TCE0

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

I cannot see any reason for your problem. Did you see the PE3 output by a scope?

Ozhan KD
Knowledge is POWER

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

no,
did you successfully drive all 16 pwm channels?
my issue is not a bug in xmega128a1 ?

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

ATXMEGA128A1 has 24 pwm outputs. What do you mean about "all 16 pwm channels"?

Ozhan KD
Knowledge is POWER

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

I see 28 OCxx/ns pins on ATXMEGA128A1 part but I mean those four quad ones (4x4=16).

Has anybody successfully driven all four pwm channels of PE0-PE3 ?

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

Only in your last post do you make clear you want PE0-PE3 as PWM !
You don't set ANY channels on PortE in the code you gave ! Do the same thing you did for PORTC.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

yes
TCC0_xxx has replaced with TCE0_xxx

--------
AVR Studio 5.0
MKII ISP model 2009

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

I don't understand your last post, but is it working now ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

no

Here,
Has anybody successfully driven all four pwm channels of PE0-PE3 ?

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

navidnavid wrote:

Has anybody successfully driven all four pwm channels of PE0-PE3 ?

I did it and it works fine.

#include"avr_compiler.h"
#include"TC_driver.h"

void main()
{
 PORTE_DIRSET=PIN3_bm|PIN2_bm|PIN1_bm|PIN0_bm;
 TC_SetPeriod(&TCE0,256);
 TC0_ConfigWGM(&TCE0,TC_WGMODE_SS_gc);  
 TC_SetCompareA(&TCE0,128);
 TC_SetCompareB(&TCE0,64);
 TC_SetCompareC(&TCE0,32);
 TC_SetCompareD(&TCE0,16);
 TC0_EnableCCChannels(&TCE0,TC0_CCAEN_bm|TC0_CCBEN_bm|TC0_CCCEN_bm|TC0_CCDEN_bm);
 TC0_ConfigClockSource(&TCE0,TC_CLKSEL_DIV1_gc);
 while(1); 
}

Ozhan KD
Knowledge is POWER

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

navidnavid, 'designer's code is one way, but you can also do for PORTE what you did for PORTC, as I've stated in a post. WHY haven't you tried that ( that's my impression from how you post ) ?! I've written code for TEN PWM channels on an XMEGA, code looks JUST like your PORTC code and it all works right. Show YOUR code for PORTE .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

tanx
It seems that I have to replace chip