An oPWM Object uses the PIC's PWM Module (PICPWMM) by configuring the I/O Line specified by the IOLine property as an output. Once configured, the registers of the PICPWMM are set according to the values of the oPWM Object's properties. The DutyCycle property is copied to the PICPWMM DutyCycle register which controls the Pulse-Width of the logic-high portion of the clock cycle output. The Period property is copied to the PICPWMM Period register which controls the resolution of the clock cycle. The PreScale property is copied to PIC Timer2's Prescale register which controls the base frequency of the Period property. The Operate property controls the PICPWMM enable bit which specifies if the High going PWM pulse is generated. When the Operate property is set to 1, the PIC's PWM Module starts generating PWM pulses. When the Operate property is set to 0, the PWM pulses are discontinued and the specified I/O Line is set to 0-Volts. If a current PWM pulse was in progress it is cut short and the I/O line is immediately set to 0-Volts. When enabled, the PICPWMM outputs a clock signal which has a variable width high going pulse. At the beginning of each PWM clock cycle the output is set to 5-Volts. As the clock cycle progresses, an internal Period-Counter (Timer2) is incremented which is compared to the value specified by the DutyCycle. When Timer2 reaches the value specified by the DutyCycle, the I/O Line is set to 0-Volts. When Timer2 reaches the value specified by the Period, Timer2 is reset to 0 and the process repeats. The Period property specifies the resolution of the clock cycle by specifying when to repeat the PWM cycle. For example, if the Period property is set to 255 then the DutyCycle property's range is 0 - 255. Likewise if the Period property is set to 10 then the DutyCycle property's effective range is 0 - 10 because any value above 10 will never be reached by the Period-Duration Counter. The PreScale property specifies the frequency that the Period-Counter (Timer2) counts by specifying how many times to divide a 5-Mhz clock which is used to increment Timer2. The PreScale property can be set to divide the 5-Mhz clock by 1, 4, or 16 giving frequencies of 5-Mhz, 1.25-Mhz, and 312.5-Khz. Two physical Pulse-Width-Modulators are implemented within the PIC. The oPWM object uses the value of the IOLine property to determine which of the two PICPWMMs to use. |