PWM and clock frequency

Discussion in 'Embedded Systems and Microcontrollers' started by tyc8159, May 7, 2007.

  1. tyc8159

    Thread Starter New Member

    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
  2. Papabravo


    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.
  3. kender

    Senior Member

    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.)
  4. Papabravo


    Feb 24, 2006
    Better than 5.5 bits I'll bet. That's just a bit over 32 choices.