Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng....

18
LOGO PIC Discussion By. Eng Tamar Jomaa

Transcript of Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng....

Page 1: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

LOGO

PIC DiscussionBy. Eng Tamar Jomaa

Page 2: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

lab#12:ADC

Pulse width modulation

lab#11:PM

C programming-part4

Outlines:

Page 3: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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

Page 4: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Analog signal

Digital signal

Analog signal

ADC PWM

Analog signal

Digital signal

Page 5: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Analog signal

Digital signal

Analog signal

ADC PWM

Analog signal

Digital signal

Page 6: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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.

Page 7: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Vout=D x VinAnalog value Digital value

The value of D always less than 1.

Page 8: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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

Page 9: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

CCP : Capture, Compare and PWM

These 2 pin’s are responsible to

control the PWM.

Page 10: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Micro C Libraries to deal with PWM

Page 11: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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.

Page 12: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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:

Page 13: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Control the speed of DC motor by PWM:

Page 14: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

Eng. Tamar Jomaa

PWM:Pulse width modulation

Solution:

Page 15: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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

Page 16: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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

Page 17: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

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

Page 18: Discussionsite.iugaza.edu.ps/tjomaa/files/C-programming-part4.pdfC programming-part4 Outlines: Eng. Tamar Jomaa PWM: Pulse width modulation Temperature sensor Microcontroller PIC16F877A

LOGO

Prepare yourself to final exam.

Hard luck

IUG