PWM and clock frequency

Thread Starter


Joined Dec 6, 2006

I'm doing a sonar sensor(2MHz) circuit and would like to generate a 2 MHz PWM signal for the sensor using PIC16F873. The resonator is 20MHz. I read through the PICmicro Mid-Range MCU Family datasheet, i saw the equation
PWM period = [(PR2) + 1] • 4 • TOSC • (TMR2 prescale value),
frequency = 1 / period.

I know the PWM period, TOSC and the TMR2 is 1, can i simply put in all the known values to calculate the PR2 and produce this 2MHz PWM? If this is wrong, can you give some suggestion to generate this signal with the PIC16F873. Thank you


Joined Feb 24, 2006
You can try it, but I'm sure you will be disappointed with the results. If you look at table 8-3 on page 62 of the datasheet (DS30292C) you will note the frequency of 208 kHz with 5.5 bits of resolution. This is almost a decade below your target frequency which, even if you could get there will limit the duty cycle choices to a very small number. You need to find an alternate approach.


Joined Jan 17, 2007
How finely do you want to adjust the PWM duty cycle?
Which PIC C compiler are you using?
Which transducers are you using? (Just curious.)