Saturday, 24 August 2013

Pulse Width Modulation

Pulse Width Modulation (PWM) can be defined as the technique of  modulating or varying the width of the pulse of a square wave signal. Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with  digital outputs.

PWM founds a lot of applications in the following fields:-
- In communication systems, it is also known as pulse duration modulation (PDM). It's a digital modulation technique where the width of the modulation carrier is vary in accordance with the modulation voltage.  This results to encoding information for transmission.
- In electrical motor control system, it is an effective method of controlling the speed of a DC motor, this is achieved through delivering energy in a succession of pulses rather than a continuously varying (analog) signal. By increasing or decreasing pulse width, the controller regulates energy flow to the motor shaft.
- In inverter system, it helps in  giving a steady output voltage of 240V  AC irrespective of the load.

Within the analogue world, PWM can be implemented by applying modulated input voltage applied at the control voltage input of a 555 timer configured as a monostable multivibrator. The output pulse at the output pin 3 is modulated by the control voltage of the input pin 5. The output pulse width tw is governed by equation tw=1.1RaC as shown below.



 Also a simple comparator with a sawtooth carrier can also turn a sinusoidal command into a pulse-width modulated output, in general, the larger the command signal, the wider the
pulse.






PWM can be implemented in software using microcontroller.  By using a high-resolution counters, the duty cycle of a square wave is modulated to encode a specific analog signal level. The PWM signal is still digital because, at any given instant of time, the full DC supply is either fully on or fully off.


Microcontrollers are digital devices that understands binary signals, and the best representation of a binary signal is a square wave. The diagram below is a square wave showing the basic terminologies associated with a square wave signal. 


.

From the diagram above, it is  important to note that in a PWM signal  the TIME-PERIOD and hence the frequency is always fixed. Only the ON TIME and OFF TIME of the pulse i.e (duty cycle) varies. The term duty cycle describes the proportion of ON TIME to the regular interval or TIME PERIOD. With this, we modulate the given voltageThe difference between a square wave signal and PWM signal is that the square wave signal has same ON and OFF time (50% duty cycle), whereas a PWM signal has a variable duty cycle.
The square wave can be taken as a special case of the PWM signal which has 50% duty cycle (ON time = OFF time).
All microcontrollers features a set number of PWM pins. These are pins that have CCP (compare capture pwm).  PWM can be implemented using PIC MCU family. PIC 18F4458 is considered for the purpose of this write-up.


PWM Calculations

There are three crucial registers  must be taken into account for Pulse width modulation: PR2, and CCPRXL:CCPXCON[5:4]. Configuring the PR2 register, will allow you to configure the PWM period while selecting a proper the value for CCPRXL:CCPXCON[5:4] will allow you to choose the right duty cycle. For choosing the right value for the PR2 register, use the following equation…
PR2=\frac{PWM Period}{4*T_{osc}*TMR Prescale Value}-1
 Tosc is the the inverse of the frequency that your microcontroller is running at. Also, use a prescale of 16 . For CCPRXL:CCPXCON[5:4], we will use the following equation…
CCPRXL:CCPXCON[5:4]=\frac{PWM Duty Cycle}{T_{osc}*TMR Prescale}
CCPRXL:CCPXCON[5:4] is a 10 bit number. To make things easy make sure you convert your number to a 10 bit binary number. After you convert the number to a binary number, set your CCPRXL register to the first 8 MSB numbers. Finally, take the last 2 LSB and you use it for your CCPXCON[5:4]. Summary of the setup procedure for PWM operation  are found below:

1. Set the PWM period by writing to the PR2
register.
2. Set the PWM duty cycle by writing to the
CCPR1L register and CCP1CON<5:4> bits.
3. Make the CCP1 pin an output by clearing the
appropriate TRIS bit.
4. Set the TMR2 prescale value, then enable
Timer2 by writing to T2CON.
5. Configure the CCP1 module for PWM operation





No comments:

Post a Comment