Jan,

I wrote my own pwm controller for a different microcontroller without using any built in pwm module using the following method:-

1. set up an interrupt to generate 50*255 times per second. - so that you can time every 1/50th of a second in 255 little time slices.

2. use a counter variable to count the interrupts as they happen and reset every 50 interrupts.

3. use another counter variable then to count from 1 to 255 interrrupts in that 1/50th of a second.

4. when the first counter resets to zero then set the pwm output to high. then, when the second counter hits your target width (by comparing its count with the pot input (suitably scaled to fit 1-255 range) you set the pwm output low.

so, every 1/50th of a second the output goes high and then after a period determined by your pot value it will go low until the end of that 1/50 of a second when it will go high again etc etc.

hope that helps.

cheers

jakers dad