Timer issue

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

Hi
I am trying to put a 38khx frequency on PD pin 3 of a Xmega128D3. I am using 32Mhz internal clock. The code is below. What I am doing wrong?

Thank You.

Charles

Here is the code that initialize it:

//==================================================================================================
void init_IR_38khz(void)
//==================================================================================================
{
	
	
PORTD.DIR = 0x01;					//Freq configured as output
TCD0.CTRLB = 0x81;					//Enable channel D & set div/1
TCD0.CCDH = 0x01;					//Count msb = 420
TCD0.CCDL = 0xA4;					//Count lsb
TCD0.CTRLA  = 0x01;					//Input clock select
	
}

What

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

PORTD.DIR = 0x08;

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

Thank you. I fixed that and I am still having some problem.In debug mode, the CNT is not changing.

Any ideas?

Thanks

Charles

Here is the code:

//==================================================================================================
void init_IR_38khz(void)
//==================================================================================================
{
	
	
PORTD.DIR = 0x08;					//Freq configured as output
TCD0.CTRLB = 0x81;					//Enable channel D & freq
TCD0.CCDH = 0x01;					//Count msb = 420 
TCD0.CCDL = 0xA5;					//Count lsb
TCD0.CTRLA  = 0x01;					//Input clock select div/1
	
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've set 1st bit of CTRLB, so it's in "FRQ" mode and TOP is done using CCA, NOT CCD. So, setup to use PD0 => OC0A of the TCD0 system.

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

You lost me there. I tought that TCD0 can use channel A, B, C or D and the associate top registers are CCA, CCB, CCC & CCD respectively.For the frequency to go out to portD pin 3 should'nt the register CCD be used? (page 3 of AVR1306 figure3-1)
What is 0C0A?

Thank You.
Charles

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

guggech wrote:
You lost me there. I tought that TCD0 can use channel A, B, C or D and the associate top registers are CCA, CCB, CCC & CCD respectively.For the frequency to go out to portD pin 3 should'nt the register CCD be used? (page 3 of AVR1306 figure3-1)
What is 0C0A?

Thank You.
Charles

Charles, what you wrote is correct, and so is what I wrote. It depends on the configuration. Look in Manual D, timer section for reg. description of CTRLB, "FRQ" bit, which you set. Then go read about the FRQ mode of WG in that section of the timers and tie the 2 sections info together to see what I mean ( Might as well find out about definiton of "TOP" too ). OC0A is the pin to to used with CCA ( see pinout & pin function section of the 'D3 PRELIMINARY datasheet ).

Edit: It looks like you can do one-stop shopping using avr1306 for all points!

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

Thank you for your input indianajones.
I read all these and I am still confused. I did get it to work to put out a 38khz on portD pin 3 but by trial and error I discovered that I need to set CCA register to 1. I have no idea why.

Charles

Here is the latest code:[quote
//==================================================================================================
void init_IR_38khz(void)
//==================================================================================================
{

PORTD.DIR = 0x08; //Freq configured as output
TCD0.CTRLB = 0x81; //Enable channel D & freq
TCD0.CCDH = 0x01; //Count msb = 420
TCD0.CCDL = 0xA5; //Count lsb
TCD0.CCAH = 0x01; //*** ???***neeeded to work****????
TCD0.CCAL = 0x00; //***

TCD0.CTRLA = 0x01; //Input clock select div/1

}

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

Quote:
I have no idea why.
Because you set the FRQ bit, so TOP is set by TCD0.CCA, NOT TCD0.CCD, like I told you before. Look at the reg. description for CTRLB. So it's involved in setting the output frequency. There's an eq'n. for what that freq. will be, didn't you see it?
Manual D wrote:
Frequency (FRQ) Waveform Generation:
For frequency generation the period time (T) is controlled by the CCA register instead of PER,
which in this case is not in use. The Waveform Generation (WG) output is toggled on each compare
match between the CNT and CCA registers as shown in Figure 12-12 on page 132.
I had thought that one could only use the pin => CCA which is OC0, but I now see that any of the 4 OCx pins would work. I don't know how it works right when CCD value's > CCA ( TOP = freq. ) value ...but you work that one out. :)

Edit: Well, no mention of doing PWM in that mode, so I guess only CCA needs to be set. Try it w/o setting the CCD register and see what happens.

Writes to 16 bit regs. should be done like this:

TCD0.CCD = 0x01A5;

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