PWM16, need to understand how to use it

There's a library written to be able to use pwm at lower than standard frequencies easily, but I don't understand how to use it.

First, I am not an experienced C programmer, and so I have to sit and study examples. But I can find no examples for this.

https://code.google.com/p/tc4-shield/source/browse/applications/Catuai/aCatuai/branches/TRY-Bhante/libraries/PWM16/?r=775

The author kindly suggested I look at it, and it appears to do what I need it to do, but I have no idea how.

Could someone please provide me with an example of how to set the pwm frequency and duty cycle using this? I realize I am asking someone to do what I should know how to do. However, a couple hours of reading still doesn't give me the clues as to how to use it from reading the PWM16.h file.

Thanks for any help.

It is rather a mass of code that doesn’t do much but set magic registers, isn’t it?

The AVR has one 16bit timer, “timer1.” It is driven from the “prescaler” at the system clock rate divided by some amount (normally 1024), and it counts from 0 to “top” and then resets. Setting “top” changes the period of the counter cycle.

On the way, it compares the timer value with two “compare” registers. When it hits the first one, it changes pin 9. When it hits the other, it changes pin 10. So setting these registers changes the duty cycle of the outputs on pins 9 and 10. The library lets you specify the duty cycle as a percentage instead.

#include <PWM16.h>

PWM16 t16;

void setup()
{
  t16.Setup(pwmN50Hz);   // Set top so that we're about 50Hz over al.
}

int duty1 = 0;

void loop()
{
  duty1 += 1;
  if (duty1 > 100)
    duty1 = 0;
  t16.Out(duty1, 0);   // Set duty cycle on pin 9.  Leave pin10 off.
}

THANK YOU!

That helps a lot.