LOGO
PIC DiscussionBy. Eng Tamar Jomaa
Eng. Tamar Jomaa
lab#12:ADC
Pulse width modulation
lab#11:PM
C programming-part4
Outlines:
Eng. Tamar Jomaa
PWM:Pulse width modulation
Temperature
sensor
Microcontroller
PIC16F877A
Cooling fan
Analog value Analog value
The analog
values will
convert to
digital values
by ADC in PIC
The digital
values will
return as
analog values
by PWM and
it’s out from
16,17 pin’s
Eng. Tamar Jomaa
PWM:Pulse width modulation
Analog signal
Digital signal
Analog signal
ADC PWM
Analog signal
Digital signal
Eng. Tamar Jomaa
PWM:Pulse width modulation
Analog signal
Digital signal
Analog signal
ADC PWM
Analog signal
Digital signal
Eng. Tamar Jomaa
PWM:Pulse width modulation
We benefit from PWM that we can control the analog values by digital values.For example: we control the volt by duty cycle.
Eng. Tamar Jomaa
PWM:Pulse width modulation
Vout=D x VinAnalog value Digital value
The value of D always less than 1.
Eng. Tamar Jomaa
PWM:Pulse width modulation
Example:We can control the speed of DC motor by PWM, like that:
The output of PIC is 5V,
but by change the PWM
we can control the speed of
DC motor:
Vout=D x Vin
Vout=0.5 X 5=2.5V
Eng. Tamar Jomaa
PWM:Pulse width modulation
CCP : Capture, Compare and PWM
These 2 pin’s are responsible to
control the PWM.
Eng. Tamar Jomaa
PWM:Pulse width modulation
Micro C Libraries to deal with PWM
Eng. Tamar Jomaa
PWM:Pulse width modulation
Micro C Libraries to deal with PWM
1)
If you don’t write this command the PIC will consider
pin’s 16 & 17 as input and output pin’s.
5000 is the frequency of the wave and you can change
it to any value.
Eng. Tamar Jomaa
PWM:Pulse width modulation
Micro C Libraries to deal with PWM
2)
By this command we can change the duty cycle.
192: this number make the duty cycle=75%
We choose 192 as number between 0 to 255.
0 acts 0% and 255 acts 100%, any number we
calculate it’s value as the following:
Eng. Tamar Jomaa
PWM:Pulse width modulation
Control the speed of DC motor by PWM:
Eng. Tamar Jomaa
PWM:Pulse width modulation
Solution:
Eng. Tamar Jomaa
PWM:Pulse width modulation
Solution:
Duty cycle=
(256/256)X100%=100%
Vout= D X Vin
Vout=1 X (5)=5
Maximum voltage
Eng. Tamar Jomaa
PWM:Pulse width modulation
Solution:
Duty cycle=
(256/256)X100%=100%
Vout= D X Vin
Vout=1 X (5)=5
Maximum voltage
Duty cycle=
(128/256)X100%=50%
Vout= D X Vin
Vout=0.5 X (5)=2.5
Eng. Tamar Jomaa
PWM:Pulse width modulation
We can control the speed of motors by 3 methods:
(1) Using Potentiometer” bad design””
(2) Using Transistor
(3) Using PWM (form Microcontroller or
555)”best design”:
12 3
LOGO
Prepare yourself to final exam.
Hard luck
IUG