> I'm just starting to experiment with the PIC16F877 using the HITECH C > compiler. I am running the PIC at 10 Mhz and want a 50 MHz PWM period > with a 7.5% duty cycle. However this means that I need the PR2 to be > 3124 which is too large (max is 255 right?). Is there a way around > this? am I doing something wrong? or do I have to use a 4MHz clock > instead? or maybe create my own pulse using TIMER0 which would allow > a prescalar of 256? Thanks in advance! Are you sure you mean 50 MHz?? Running the pic at 10 Mhz, you can only execute instructions at 10/4 = 2.5 MHz, let alone run the built-in pwm. The formula for pwm frequency in this case is: pwm freq = 2.5E06 / ((PR2 + 1) * pre-scale) if PR2 = 1 and pre-scale = 1, your pwm freq = 1.25 MHz. However, you only have 1 bit of resolution! (off and 50%) The formula for resolution is: bits of resolution = log(2.5E06/pwm freq) / log(2) which = 1 for pwm freq = 1.25 MHz This also shows why PR2 = 0 won't work: pwm freq theoretically = 2.5 MHz, but the resolution = 0 bits! If PR2 = 3124 and the pre-scale = 16, the pwm freq = 50 Hz, so I'm guessing that is actually the speed you're looking for?? One problem with the built-in pwm is that there is a definite minimum speed. In this case, it is with PR2 = 255 (the max as you pointed out) and pre-scale = 16 (max available): pwm freq = 2.5E06 / (256 * 16) = 610 Hz So you can't get to 50 Hz with this clock speed. If you switch to a 4 MHz clock, the minimum pwm freq is: pwm_freq = 1E06 / (256 * 16) = 244 Hz So you're still not there! The max clock you can run = 256 * 16 * 50 * 4 = 819.2 KHz So the ever popular 32.768 watch crystal would work, although you wouldn't be able to hit 50 **exactly** - you could get 49.95 Hz. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu