Can't get the PWM output to work, what am I missing?

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

Been reading the timer section of the manual about five times now, but I can't figure out how to get the PWM output to work. Here's my code:

 

PORTD.DIRSET = 0xFF; //PORTD set as output

TCC0.CTRLA = 0b111; //Prescaler=1024

TCC0.CTRLB = 0b11110011; //All CC enabled. Single slope PWM enabled 

TCC0.CTRLD = 0; //All events off

TCC0.PER = 512; //Frequency set to clk/512

TCC0.CCD = 256; //50% duty cycle

A LED is connected to PD0, it glows when simply setting the OUTSET register there are no hardware errors. When in single slope PWM mode, the output should be set at compare match and cleared at TOP, but I'm not sure wich of the four CC registers I should use, or perhaps all of them could be used to get a more complex waveform. PD0 is constantly LOW regardless of setting though, what am I doing wrong? Main clock frequency is set to 32Mhz.

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

Can't get the PWM output to work, what am I missing?

Been reading the timer section of the manual about five times now 

How do you expect help if you don't tell what you are using? What manual? ...now you know what is missing 

 

When working with PWM always use a scope,  to see exactly what is going on & the exact waveform you are getting.  Just staring at an LED can be  rather misleading.

When in the dark remember-the future looks brighter than ever.

Last Edited: Sun. Feb 4, 2018 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are enabling outputs on port D, but setting up a timer that is associated with port C.

Try TCD0 instead of TCC0.

 

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

Also, may need to enable / power up the Timer/counter, if not already doing so.

 

JC