>I need to generate PWM on a 12C508. What is the >best way of generating a high frequency PWM >signal, with say 32 steps. I don't want it to take up >too much processing time. Gavin, Do it this way instead: 1) Determine what PWM frequency you want. Let's pick 10KHz, for math sake. 2) Compute how many CPU instructions that means between edges. For instance, a PIC running at 4 MHz executes 1,000,000 instructions per second. 1,000,000 / 10,000 = 100 instructions wide for each cycle. 3) Compute the number of steps desired between the limits. At 10 KHz, if you want it to be deadly accurate and 32 steps, you have to change 10KHz to something which is an integer multiple of 32. 312 * 32 = 9984 (.16%under) and 313*32 = 10016 (.16%over). I like even numbers, so I'll chose 312. You could also change to 25 or 50 steps very nicely (50 would be pretty tight programming, though). Another way to approach this is to use a PWM and OSC which would let you use 256, so you can naturally roll over a counter without having to reload it. This is the _better_ way. 4) Write your program so that you have exactly 100 (which means in practice probably 99 or 101 ) instructions between the rising edges. If you want 32 steps, you are going to have to pick some of a different value than the rest. The best way to handle this, if you are driving a motor, for instance, is to have a certain threshold which is your minimum pulse width. I suggest that you go with each PWM step being 3 instructions wide. Then 100 - (3*32) = 4 steps minimum non-zero PWM. This is going to be pretty tight code, so I would be tempted to change to a faster osc and/or possibly changing the PWM frequency and/or number of steps across the range. Can you take it from here? You need your code to do two things at once - count and PWM at the same time. Do it by using certain instructions which don't affect the status bits DECFSZ followed by NOP, for instance. Andy ================================================================== Andy Kunz - Statistical Research, Inc. - Westfield, New Jersey USA ==================================================================