5.61. PWM
PWM Pin,Duty,
Cycle
Outputs a pulse width modulated pulse train on Pin. Each cycle of PWM consists of 256 steps. The Duty cycle for each PWM cycle ranges from 0 (0%) to 255 (100%). This PWM cycle is repeated Cycle times. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
The Cycle time of PWM is dependent upon the oscillator frequency.
If a 4MHz oscillator is used, each Cycle is about 5ms long. If a 20MHz oscillator is used, each Cycle is about 1ms in length. Defining an OSC value has no effect on PWM.
The Cycle time always changes with the actual oscillator speed.
If you want continuous PWM output and the PICmicro MCU has PWM hardware, HPWM may be used instead of PWM. Pin is made an output just prior to pulse generation and reverts to an input after generation stops. The PWM output on a pin looks like so much
garbage, not a beautiful series of square waves. A filter of some sort is necessary to turn the signal into something useful. An RC circuit can be used as a simple D/A converter
Bookmarks