xMega 8E5 pwm doesn't pwm?

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

Let's see:

1. My LED is connected to Pin 23, and that's PD5 and that's OC5B.

2. I have all Port d pins set to output, except for PD4. I can put the pin high and low by code.

3. My timer seems to be working. I put a line to toggle another pin in the interrupt routine, and that pin is toggling.

4. My PD5 pin is always low.

I need to understand this as I plan to have 4 servos on PC0 through PC3.

My code:

#include "config.h"

void InitPMIC(void)
{
	PMIC.CTRL = 1 ; // Enable low level interrupts in application section without round-robin
}

void StartTimer5()
{
	TCC5.CTRLA = 0 ; // stop tcc5
	TCC5.CTRLB = TC45_BYTEM_BYTEMODE_gc | TC45_WGMODE_SINGLESLOPE_gc ;
	TCC5.CTRLC = 0 ;
	TCC5.CTRLD = 0 ; // No events, for the time being
	TCC5.CTRLE = TC45_CCBMODE_COMP_gc ; // Output compare and capture B
	TCC5.INTCTRLA = 1 ; // Low level interrupt on overflow
	TCC5.INTCTRLB = TC45_OVFINTLVL_LO_gc ;
	TCC5.CTRLGCLR = 255 ; // Clear all the bits in this register
	TCC5.PER = 255 ;  // The manual says it's LPER
	TCC5.CCB = 128 ;  // The manual says it's LCCB
	TCC5.CTRLA = 1 ;  // Start timer at 2MHz
}

ISR(TCC5_OVF_vect)
{
	TCC5.INTFLAGS = TCC5.INTFLAGS ;
	TCC5.CCB -= 1 ;
	PORTD.OUTTGL = (1<<6) ; // Toggle a bit so we can see if the interrupt is hitting.
}

int main(void)
{
	BoardInit();
	InitPMIC();
	StartTimer5();
	sei(); 
    while(1)
    {
       PORTD.OUTTGL = (1<<7) ; //Toggle a bit crazily so we can see if anything's happening
    }
}

The config.h file:

/*
 * config.h
 *
 * Created: 7/31/2013 7:46:36 PM
 *  Author: Tom
 */ 


#ifndef CONFIG_H_
#define CONFIG_H_

#define F_CPU 2000000
#include 
#include 
#include 


#define IntroPort PORTD
#define IntroPin 4

#define LEDPort PORTD
#define LEDPin 5
// LEDPin is also OC5B

void BoardInit(void);



#endif /* CONFIG_H_ */

And the config.C file that does boardinit

void BoardInit(void)
{
	PORTA.DIR = PORTC.DIR = PORTD.DIR = 255 ;
	PORTA.OUT = PORTC.OUT = PORTD.OUT = 0 ;
	
	IntroPort.DIRCLR = (1<<IntroPin) ;
	IntroPort.OUTSET = (1<<IntroPin);
	
}

I think CTRLE register enables the compare output to the pin, but my compare output to the pin is apparently not enabled.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

Since you are using TCC5, have you had a look at PC5?

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

You mean I should be finagling with TCD5? I thought TCC5 was the TCC on port D.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

Quote:
You mean I should be finagling with TCD5?
Yes.
TCC5 have PWM on PC4 and PC5, TCD5 on PD4 and PD5, TCC4 on PC0, PC1, PC2 and PC3. With TCC4 you can remap the PWM pins to the upper half of PORTC.

So the third letter tells which port the timer has it's PWM pins on and the number tells which timer type it is.

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

Well, now who thought up something that makes so much sense?

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut.