Clock in xmega

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

Please, help

 

 

How to remake the mega code for Xmega?

void clock_init()
{
	cli(); // disable all interrupts
	TCCR1B = 0; // disable ticking
	TIMSK = (TIMSK & ~(0x3c)) | 0x04; // enable overflow interrupt
	TCNT1H = 0; // reset counter
	TCNT1L = 0;
	ICR1H = 40000U >> 8; // set overflow value
	ICR1L = 40000U & 0xff;
	TCCR1A = 0xfe; // 11 11 11 10, set channel config
	TCCR1B = 0x1a; // 00011010 start ticking
	sei(); // reenable interrupts
	
}

 

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

You do that by carefully reading the datasheets of both chips. Find out what the given code makes the timer do and then figure out how you make the xmega's timer do the same. No one will write the code for you if you ask that bluntly.

But here's a hint: This code seems to enable the overflow interrupt. If you actually need that, you need to know that the xmegas have three interrupt levels that need to be activated individually. sei() still needs to be called but this is not sufficient. You have to set up the PMIC registers, too.

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

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

pawi777 wrote:
Find out what the given code makes the timer do

Which would be a lot easier without all those Magic Numbers !

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I understand what you're talking about. I'm not asking you to write a code for me. I'm asking you to help understand how this works for mega, and how it should work for Xmega.
Read the datasheets and got confused.

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

sashakbr wrote:
I'm asking you to help understand how this works for mega

So why didn't you say that in your opening post, then?

 

Read the datasheets and got confused.

So what part(s) do you find confusing?

 

We can't help you when we don't know what help you need!

 

Apart from the datasheets, what other research/study have you done?

 

 

See also: https://www.avrfreaks.net/forum/findpost-your-online-c-books-tools-here

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Сan you estimate whether I did the right thing?

 

void clock_init()

{

cli(); // disable all interrupts

TCC0.CTRLA = TC_CLKSEL_DIV8_gc; // Presacler 8

TCC0.CTRLB = 0x00; //  normal

TCC0.PER = 25-1; //10 kHz when the frequency frequency is 2 MHz

TCC0.CNT = 0x00; //reset the counter

TCC0.INTCTRLA = 0b00000011; //high level for interrupts

PMIC.CTRL |= PMIC_HILVLEN_bm |PMIC_MEDLVLEN_bm|PMIC_LOLVLEN_bm;

sei();//enable all interrupts

}