Justin Lipton wrote: > I am new to the PIC device family and am looking to program a > PIC16C74. > > My application requires 3 PWM outputs (all with adjustable duty > cycles). Obviously I will use CCP1 for one PWM output leaving me > bothered about the remaining two. > > The other two outputs have frequencies of 30Hz and 70Hz respectively > and need duty cycles (which will not change very often) of 50% or > 10%. > > Can anyone suggest a neat method for implementing these outputs? > > Note that the processor is also required to be an I2C bus master (I > found these routines) and other than monitoring the bus has very > little else to do. Justin: How precise do those two frequencies have to be? If a 1% error is ok, you could do something like this: Setup TMR0 to generate an overflow interrupt in 90 microseconds. Initialize a register called TIME30 to 37; 37 is the number of 90-microsecond periods in 3330 microseconds (approximately one-tenth of a 30Hz signal's period). Initialize a register called TIME70 to 16; 16 is the number of 90-microsecond periods in 1440 microseconds (approximately one-tenth of a 70Hz signal's period). Two other registers, called DUTY30 and DUTY70, set the duty cycle of each waveform. Set them to 1 for a 10% duty cycle, or to 5 for a 50% duty cycle... Your main program can modify them as needed during its execution. Initialize two more registers, called COUNT30 and COUNT70, to 10. When the TMR0-overflow interrupt occurs: Reset the TMR0 register to generate another interrupt in 90 microseconds. Decrement TIME30. If it's at 0, reset it to 37 and: Decrement COUNT30. If it's less than DUTY30, pull the 30Hz output pin high; otherwise, pull that pin low. If COUNT30 is at 0, reset it to 10. Decrement TIME70. If it's at 0, reset it to 16 and: Decrement COUNT70. If it's less than DUTY70, pull the 70Hz output pin high; otherwise, pull that pin low. If COUNT30 is at 0, reset it to 10. This'll produce a 30.03Hz signal on one pin and a 69.44Hz signal on the other, with the duty cycle of each signal independently adjustable in 10% steps from 0 to 100%. A couple of notes: 1. When your main program changes DUTY30 or DUTY70, there may be a brief glitch on the corresponding output pin. 2. All the numbers above are in decimal. 3. All of this is just off the top of my head, so no guarantees... But it's pretty simple; I'm confident that it'll work just fine. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499 (personal) === http://www.netcom.com/~fastfwd (business)