XMEGA16D4 frequency generator mode on the wrong pin

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



I'm using an ATXMEGA16D4 in my project, where I would like to hqve a LED blinking.


This LED is connected to the pin PE2, and I'm using this code:

	TCE0.CTRLB = 0x40 | TC_WGMODE_FRQ_gc;
	TCE0.CCC = 31250;
	TCE0.CNT = 0;

But nothing out on the pin PE2.


If I use the CCA register instead it is working fine, 





This topic has a solution.
Last Edited: Mon. Sep 25, 2017 - 10:48 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Confusing, yes, but the truth lays in the datasheet.


Heres the formula


Freq = CLKper / (2 * PRESCALER * (CCA + 1))


The timer is clocked by CLKper divided by your prescaler value, 64 in your case, giving how fast the timer counts, i.e. counts pr. second. But the frequency as seen on the output compare pin, in your case OC0C, is also defined by the TOP value for the timer, i.e. when does the timer flip and thus update the output pin? For Timer0, in this particular mode, the TOP value of the timer is ALWAYS, no matter which OC0x pin you wanna use on that particular timer, defined by CCA. AlwaysSo you have to set CCA to be able to define a frequency to be seen on OC0C


So what does CCC do? In this mode. Nothing. Has no meaning..

This has the effect that all OC0x on TimerE0, in your case OC0C, would, if being enabled, tickle tackle away with the same frequency as defined by CCA.


So when do u use CCC?

CCC is for example used in other modes to define the duty cycle of an output frequency, or to set the PWM factor so to say. In Single-slope PWM Generation the PER register defines the frequency, not CCA (together with CLKper and the prescaler offcourse) and the CCx registers defines the d.c. for the corresponding OC0x output. If you where using this in the above example, you would be able to not only blink a LED by the desired frequency (defined by PER), but also adjusting the brightness by altering CCC.





Vidar (Z)


"The fool wonders, the wise man asks"

Last Edited: Sun. Jul 31, 2016 - 04:10 AM