Since the 2-KHz PWM period (500-usecs) and duty cycle interval (50-usecs) is an exact multiple of the 20-KHz PWM period (50-usecs), I don't see why you couldn't use the PWM Timer 2 interrupt to update both PWM streams. That is unless interrupt code overhead becomes a significant portion of the 100 instruction cycles available between interrupts (using an 8-MHz clock).
Please forgive me for the pseudo C example (I don't have PBP).
Regards, Mike
Code:;****************************************************************** ; // setup PWM for a 50-usec period (8-MHz INTOSC, Timer 2 ; // prescale 1:1, and PR2 = 99) ; ; char duty1 = 50; // 20-KHz duty cycle, 25 or 50 ; char duty2 = 1; // 2-KHz duty cycle, 1..9 (10%..90%) ; char pwm2 = 9; // preset 2-KHz duty cycle counter ; ; void interrupt() // 50-usec interrupt intervals ; { pir1.TMR2IF = 0; // clear timer 2 interrupt flag ; ccpr1l = duty1; // update PWM1 (20-KHz) duty cycle ; pwm2++; // increment PWM2 period counter ; if(pwm2 == 10) // if end of 500-usec period ; { pwm2 = 0; gpio.1 = 1; // reset counter, turn output "on" ; } // ; if(duty2 == pwm2) // if PWM2 duty cycle match ; gpio.1 = 0; // turn PWM2 output "off" ; } // ;




Bookmarks