There seems to be two ways to do your own pwm generation, and I was

wondering if anyone had any comments on the suitability of them in various

situations.

To simplify things, let's suppose the duty cycle is represented as a value

between 0 and 256. Also, each pwm channel will have a counter, c, which holds

a non-negative integer. The pwm update routine will be executed at some

frequency f. The update routines for each method is as follows:

Method 1: Increment c by 1 on each pwm cycle. If c < d, set the output for the

channel to 1; otherwise set it to 0.

Method 2: Increment c by d. If c >= 256, set the output to 1; otherwise set it

to 0. Reduce c modulo 256.

Is there any reason to choose one method over the other? How about if you're

driving LEDs vs. a motor?