Having trouble with OC1A output on ATMEGA168

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

Hi - I'm seeing no output from the OC1A pin on an ATMEGA168. It just sits at low.

Here is the relevant code:

DDRB =  0b00101010;
PORTB = 0b11000111;
//Initialize PWM
//timer 1, output on OC1A
//COM1A1 = 1, COM1A0 =10 (clear OC1A at bottom, set it on compare match)
//WGM13:0 = 1110, Fast PWM, top = ICR1
//clock = IO clock/1
TCCR1A = (1<<COM1A1) | (1<<COM1A0) | (1<<WGM11);
TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS10);
TCNT1 = 31; //8E6 / 250E3 = 32
OCR1A = 16; //start out with a very small number

I suspect I'm missing a bit somewhere. Any suggestions? I'm expecting a 250KHz PWM with 50% duty cycle.

Thanks!

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

You didn't set ICR1 .

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

If all you want is a 50% duty cycle, why not use CTC mode?

Regards,
Steve A.

The Board helps those that help themselves.

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

indianajones11 wrote:
You didn't set ICR1 .

Ah - you're exactly right. I was writing to TCNT1 instead. Works now!
Koshchi wrote:
If all you want is a 50% duty cycle, why not use CTC mode?

The 50% duty cycle is just for testing purposes :)