Phase/Frequency Correct PWM

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

I am trying to use PWM "mode 8"; Phase and Frequency Correct PWM on an ATmega168. OCR1 for this device is PB1. I am not seeing a pulsed output. Here is my exact code:

void main(void)
{
  DDRB = (1<<PB1);

  TCCR1A = 0;
  TCCR1A = (1 << COM1A1) | (1 << COM1B1);
  TCCR1B = (1 << WGM13) | (1 << CS10);

  ICR1 = 1024;

  while (1)
  {
  };
}

I can generate PWM in other modes, but this is the first time I have tried to the Phase/Frequency Correct mode. I need to be able to vary the frequency of the PWM output.

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

1) Why set COM1B1?
2) Without setting OCR1A the value is 0. In this mode, is this equivalent to "0% duty cycle"?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

You are right, COM1B1 is unnecessary, but does no harm.

OCR1A is indeed the pulse width. Stupid mistake on my part. Setting OCR1A appropriately for the value of ICR1 solves the problem.

Thanks.