Setup for PWM Operation to Other Device Peripherals

Follow the next steps when configuring the module for PWM operation to be used by other device peripherals:

  1. 1.Disable the PWMx pin output driver(s) by setting the associated TRIS bit(s).
  2. 2.Clear the PWMxCON register.
  3. 3.Load the TxPR register with the PWM period value.
  4. 4.Load the PWMxDCH register and bits [7:6] of the PWMxDCL register with the PWM duty cycle value.
  5. 5.Configure and start Timerx:
    • Clear the TMRxIF Interrupt Flag bit of the PIRx register.(1)
    • Select the timer clock source to be as FOSC/4 using the TxCLKCON register. This is required for correct operation of the PWM module.
    • Configure the CKPS bits of the TxCON register with the Timerx prescale value.
    • Enable Timerx by setting the ON bit of the TxCON register.
  6. 6.Wait until Timerx overflows; the TMRxIF bit of the PIRx register is set.(1)
  7. 7.Configure the PWM module by loading the PWMxCON register with the appropriate values.
Note:
  1. 1.To send a complete duty cycle and period on the first PWM output, the above steps must be included in the setup sequence. If it is not critical to start with a complete PWM signal on the first output, then step 6 may be ignored.