Top Banner
1 Temperature Controlled DC Fan using PIC18F452 Microcontroller Project Report Submitted for the award of the degree of Bachelor of Technology in Electrical and Electronics Engineering By NAME REG. NO. Prem Shankar B080425EE Prashant Jaiswal B080433EE Vikash Kumar B080449EE Department of Electrical And Electronics Engineering NATIONAL INSTITUTE OF TECHNOLOGY CALICUT April 2011
28
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Report

1

Temperature Controlled DC Fan using PIC18F452 Microcontroller

Project Report

Submitted for the award of the degree of

Bachelor of Technology

in

Electrical and Electronics Engineering

By

NAME REG. NO.

Prem Shankar B080425EE

Prashant Jaiswal B080433EE

Vikash Kumar B080449EE

Department of Electrical And Electronics Engineering

NATIONAL INSTITUTE OF TECHNOLOGY CALICUT

April 2011

Page 2: Report

2

CERTIFICATE

This is to certify that the report entitled “Temperature Controlled DC Fan using PIC18F452

Microcontroller” is a bonafide record of the Mini Project done by Prem Shankar (Roll No:

B080425EE), Prashant Jaiswal (Roll No: B080433EE) and Vikash Kumar (Roll No: B080449EE)

under my supervision, in partial fulfillment of the requirements for the award of the degree of

Bachelor of Technology in Electrical And Electronics Engineering from National Institute of

Technology Calicut, and this work has not been submitted elsewhere for the award of a degree.

DR . Jeevamma Jacob

(Guide)

Dept. of Electrical Engineering

Mr. P. Ananthakrishnan Dr. R. Sreeram Kumar

Associate Professor Professor and Head

Dept. of Electrical Engineering

Place : NIT Calicut

Date : 03 May 2011

Department seal

Page 3: Report

3

ACKNOWLEDGEMENT

We express our sincere gratitude to our Guide, Dr. Jeevamma Jacob, Professor, Department Of

Electrical Engineering for her continuous support without which this project would not have

been a success.

We would also like to thank our Course Coordinator, Mr. Ananthakrishnan, Associate

Professor, Electrical Engineering Department, NITC for his timely advices without which this

project would be incomplete.

This project would have been impossible without the guidance of Mr. Jagdanand, Assistant

Professor .We thank him for his timely advice rendered in guiding us throughout the Project.

Last but not the least we thank our Parents and Lord Almighty.

Prem Shankar

Prashant Jaiswal

Vikash Kumar

Page 4: Report

4

ABSTRACT

This project targets on designing, simulating, prototyping and controlling the speed of a dc

motor fan which can be used to keep the temperature of computer’s processor within specified

limits. The primary aim of our project is to control the speed of a dc motor fan according to the

temperature sensed by a temperature sensor using a pic microcontroller.

Page 5: Report

5

CONTENTS

1. Introduction 6

1.1Why use microcontroller?

1.2Methodology

1.3Project Objective

2. Components and Hardware 7

2.1 Components Used

2.2 Hardware

2.2.1 PIC Microcontroller

2.2.2 Temperature Sensor

2.2.3 Optoisolator

2.2.4 N-Channel MOSFET

2.2.5 DC Motor

3. Implementation 14

3.1 Circuit diagram

3.2 Flow Chart

3.3 Configuring ADC

3.4 Program Code

3.5 Simulation Result

4. Results and Conclusion 28

5. References 28

Page 6: Report

6

Chapter 1

INTRODUCTION

In today’s hi-tech world computers have become part and partial of life. But temperature of the

processor inside the computing system needs to be controlled for proper functioning of the

semiconductor devices. Thus it is important to keep the temperature within the prescribed

limits.

1.1 Why use microcontroller?

To control the temperature it must be sensed and check in what range it lies according to which

the speed of the cooling fan is decided. These tasks can be performed very easily using a

microcontroller. It involves decision making steps, which can be easily achieved by using a

microcontroller instead of complex IC circuits.

1.2 Methodology

First of all the temperature will be sensed by a temperature sensor, which works as a

transducer and gives voltage equivalent of the sensed temperature. This analog signal will

be fed to the ADC of PIC microcontroller. Thereafter the adc will take the analog input and

convert it to digital domain. Now the digital data will be compared to the prespecified

conditions in the program. According to result of comparison, desired duty ratio will be

generated.

1.3 Project Objective

This project targets on designing, simulating, prototyping and testing of a temperature

controlled dc motor fan that is practically used for cooling the processor in computers.

The primary aim of our project is to control dc motor, fan in our project, using a pic micro

controller. The fan will be given an input duty ratio which increases in steps of 25% for

every 10 degree rise in temperature, starting from 25 degrees. The fan will be kept off for

temperature less than 25 degree and will run maximum speed for temperature above 55

degrees.

Page 7: Report

7

For controlling the temperature we need

values and types of components pre designed and the pic configured. So to start with

the circuit will be very complicated understand. Thus a block diagram representation of

the circuit is presented.

represented as shown in figure 2.1

Figure 2.1 Block diagram representation of the circuit

Chapter 2

Components and Hardware

For controlling the temperature we need to assemble the required circuit with all the

values and types of components pre designed and the pic configured. So to start with

the circuit will be very complicated understand. Thus a block diagram representation of

the circuit is presented. To achieve the objective of the project, the syst

shown in figure 2.1

Block diagram representation of the circuit

to assemble the required circuit with all the

values and types of components pre designed and the pic configured. So to start with

the circuit will be very complicated understand. Thus a block diagram representation of

ve the objective of the project, the system can be

Page 8: Report

8

2.1 Components used

A 12v DC motor driven fan.

PIC18F452

Temperature Sensor: LM35D

Optoisolator: ILD74

N-Channel MOSFET : IRF520

LM 7805 Regulator IC

Crystal - 20 MHz

40 pin DIP IC base

General Purpose PCB

IN4004 Diode

Zener diode 6.24

22pf capacitors – 2Nos.

100uf, 25V Electrolytic Capacitor.

0.1 uf ceramic capacitor. : 2 nos

Reset Switch

10k, ¼ W resistor. : 2 nos

100k resistor

330 ohm resistor

12V Battery connector.

Page 9: Report

9

2.2 Hardware

2.2.1 PIC Microcontroller

For this project, we are using PIC18F452. PIC18 XXX is an 8 bit microcontroller. The other PIC

families are 10xxx ,12xxx ,14xxx & 17xxx. They all are 8 bit processors, meaning that the CPU

can work on only 8 bit data at a time. The data larger than 8 bit has to be broken into 8 bit

pieces to be processed by CPU. The PIC18f has an instruction size of 16 bit wide.

PIC18f is available in 18-80 pin packages makes it ideal for new designs.

PIC18 features:

PIC18 has a RISC architecture that comes with some standard features such as on-chip program

ROM, data RAM, data EEPROM, TIMERS, ADC, and USART and I/O ports. Using these features,

various tasks can be performed. Block diagram representation is shown in fig 2.2.

Figure 2.2 Block Diagram of PIC microcontroller

Page 10: Report

10

PIC18F452 has 10 bit inbuilt ADC, which converts the analog input data fed to it through PORTA

pins. ADCs are mainly used for data acquisition. Here a physical quantity like temperature,

pressure is converted to electrical (voltage, current) signals using a device called a transducer.

Transduces are also referred to as ‘sensors’ . Sensors for temperature, velocity and many other

physical quantities produce an output that is voltage (or current). Therefore, we need an

analog-to-digital converter to translate the analog signals to digital numbers so that the

microcontroller can read and process that. While configuring an ADC one must focus on certain

parameters like RESOLUTION, CONVERSION TIME, INPUT VOLTAGE (Vref) etc.

Figure 2.3 An 8 bit ADC Block Diagram

Dual Inline Package of PIC18F452 that is being used for our project is shown in

figure 2.4.

Figure 2.4 DIP package of PIC18F452

Page 11: Report

11

For the 40 pin DIP structure, 33 pins are set aside for five ports PORTA, PORTB, PORTC,

PORTD and PORTE. The rest of the pins are designated as Vdd(power supply pin), Vss(ground),

OSC1,OSC2,MCLR(reset), and another set of Vdd and Vss.

A powerful feature of PIC I/O ports is their capability to access individual bits of the port

without altering the rest of the bits in that port. This can be used if we need to access only 1 or 2

bits of the port instead of the entire 8 bits.

2.2.2 Temperature Sensor

A sensor is a device that measures a physical quantity and converts it into a signal which can be

read by an observer or by an instrument. Simple and widely used linear temperature sensors used

include the LM34 and LM35 series from National Semiconductor Corporation.

The sensors of LM34 series are precision integrated-circuit temperature sensors whose output

voltage is linearly proportional to the Fahrenheit temperature. But In common practice degree

Celsius is more in use than Fahrenheit scale. Therefore LM35 is a better option.

Table 2.1 Temperature Sensor Series Selection Guide

LM35 series sensors are precision integrated-circuit temperature sensors whose output voltage is

linearly proportional to the Celsius temperature. It requires no external caliberation because it is

internally caliberated . The table above sufficiently explains the need of using LM35D in our

project.

Page 12: Report

12

Fig 2.5 LM35D Fig 2.6 block

representation

2.2.3 Optoisolator

Fig 2.7 Optoisolator Schematic Fig 2.8 MCT2E

This is an electronic device designed to transfer electrical signals by utilizing light waves to

provide coupling with electrical isolation between its input and output. It is also known as

optocoupler and is used to isolate two parts of a system.

An optoisolator has an LED transmitter and a photosensor receiver, separated from each other

by a gap. When current flows through the diode, it transmits a signal applied across the gap and

receiver produces the same signal with the same phase but a different current and amplitude.

We are using MCT2E as optocoupler in our project.

2.2.3 N-Channel MOSFET

Page 13: Report

13

The metal–oxide–semiconductor field-effect transistor (MOSFET, MOS-FET, or MOS

FET) is a transistor used for amplifying or switching electronic signals.

In this project we have used IRF 520 as the n-channel MOSFET.

Figure 2.9 N- Channel MOSFET-IRF520

Figure 2.10 Characterstic curve for n-channel MOSFET

The advantages of using MOSFET as switch are:

1. Low gate signal power requirement. No gate current can flow into the gate after the small gate

oxide capacitance has been charged.

Page 14: Report

14

2. Fast switching speeds because electrons can start to flow from drain to source as soon as the

channel opens. The channel depth is proportional to the gate volage and pinches closed as soon

as the gate voltage is removed, so there is no storage time effect as occurs in bipolar transistors.

2.2.5 DC Motor

Direct current motor is a widely used device to translate electrical pulses in to mechanical

movement. In our project we are using Brushless DC motors. Brushless DC motors (BLDC

motors, BL motors) also known as electronically commutated motors (ECMs, EC motors) are

synchronous electric motors powered by direct-current (DC) electricity and having electronic

commutation systems, rather than mechanical commutators and brushes. The current-to-

torque and frequency-to-speed relationships of BLDC motors are linear. A sample brushless DC

motor is shown in figure 2.11.

Figure 2.11 Brushless DC motor

Page 15: Report

15

3.1 Circuit Diagram:

As per the block diagram shown in figure 2.1, now we are in a position to assemble the

complete circuit diagram. We have to design the resistors, capicators, switching components

sensors, and at last all parts of the PIC. The motor should be connected usin

The modeled circuit is as shown in figure 3.1.

Chapter-3

Implementation

As per the block diagram shown in figure 2.1, now we are in a position to assemble the

complete circuit diagram. We have to design the resistors, capicators, switching components

sensors, and at last all parts of the PIC. The motor should be connected using an optoisolator.

shown in figure 3.1.

Figure 3.1 Circuit Diagram

As per the block diagram shown in figure 2.1, now we are in a position to assemble the

complete circuit diagram. We have to design the resistors, capicators, switching components

g an optoisolator.

Page 16: Report

16

3.2 Configuring ADC.

Following parameters must be kept in mind while configuring the ADC

3.2.1 Resolution

ADC has n-bit resolution, where n can be 8, 10, 12, 16, or even 24 bits. The

higher-resolution ADC provides a smaller step size, where step size is the smallest

change that can be discerned by an ADC.

3.2.2 Conversion Time

Conversion time is defined as the time it takes the ADC to convert the analog input to a digital

(binary) number. The conversion time is dictated by the clock source connected to the ADC.

3.2.3 Vref

Vref is an input voltage used for the reference voltage. The voltage connected to this pin, along

with the resolution of the ADC chip, dictate the step size. For an 8-bit ADC, the step size is

Vref/256 because it is an 8-bit ADC, and 2 to the power of 8 gives us 256 steps. For example, if

the analog input range needs to be O to 4 volts, Vref is connected to 4 volts. That gives 4 V/256

=15.62 mV for the step size of an 8-bit ADC.

3.2.4 Digital Data O/P

For 10-bit ADC the data output is DO—D9. To calculate the output voltage, we use the following

formula:

Dout=Vin/Step Size

where Dout = digital data output (in decimal), Vin = analog input voltage, and step size

(resolution) is the smallest change, which is Vref/1024 for a 10-bit ADC. This data is brought out

of the ADC chip either one bit at a time (serially), or in one chunk, using a parallel line of

outputs.

3.2.5 Control registers associated with ADC

i) ADCON0

The ADCONO register is used to set the conversion time and select the analog input channel

among other things. Figure 13-6 shows the ADCONO register. In order to reduce the power

consumption of the PIC 18, the ADC feature is turned

off when the microcontroller is powered up. We turn on the ADC with the ADON bit of the

ADCONO register, as shown in Figure 13-6. The other important bit is

the GO/DONE bit. We use this bit to start conversion and monitor it to see if conversion has

ended. Notice in ADCCONO that not all family members have all the 8 analog input channels.

Page 17: Report

17

The conversion time is set with the ADCS bits. While ADCS 1 and ADCSO are held by the ADCONO register, ADCS2 is part of the ADCON 1 register.

Table 3.1 ADCON0 Configuration Table

ii) ADCON1

The ADCON 1 register is used to select the Vref voltage among other things. It is shown in

Figure below. After the A/D conversion is complete, the result sits in registers ADRESL (A/D

Result Low Byte) and ADRESH (AID Result High Byte).The ADFM bit of the ADCON1 is used

for making it right-justified or left-justified because we need only 10 bits of the 16.

Page 18: Report

18

Table 3.2 ADCON1 Configuration Table

Page 19: Report

19

3.3 Flow Chart

Figure 3.2 Flow Chart

Page 20: Report

20

3.4 Program Code

LIST P=PIC18F452, F=INHX32, MM=OFF, N=0, ST=OFF, R=HEX

#include P18F452.INC

CONFIG OSC=HS, OSCS=OFF

CONFIG WDT=OFF

CONFIG DEBUG=OFF, LVP=OFF, STVR=OFF

ORG 00H

BSF TRISA,0 ;Make pin RA0 an input pin

BCF TRISC,CCP1 ;Make pin RC2/CCP1 output pin

MOVLW 81H ;Configuring the control register 0 of ADC

MOVWF ADCON0

MOVLW 8FH ;Configuring the control register 1 of ADC

MOVWF ADCON1

CALL DELAY ;Tacq~12.86 uSec

BSF ADCON0,GO ;Starting conversion

BACK BTFSC ADCON0,DONE ;Checking if the conversion is complete

BRA BACK ;Polling

REFRESH MOVFF ADRESL, 01H ;Copy the converted digital value to file

register 01h

MOVFF ADRESH, 02H

CALL DELAY ;CALL Q_SEC_DELAY

BSF ADCON0,GO

;--------------------------------------------------------------------------------------------------------------------

---------------------------------------------

MOVLW D'50'

CPFSLT 01H

GOTO CHECK

DR_0 BCF PORTC,2

GOTO REFRESH

BRA DR_0

CHECK MOVLW D'70'

Page 21: Report

21

CPFSLT 01H

GOTO CHECKA

CALL DR_25

GOTO REFRESH

CHECKA MOVLW D'90'

CPFSLT 01H

GOTO CHECKB

CALL DR_50

GOTO REFRESH

CHECKB MOVLW D'110'

CPFSLT 01H

BRA X1

BRA X2

X1 GOTO DR_100

GOTO REFRESH

X2 CALL DR_75

GOTO REFRESH

ORG 310H

DELAY MOVLW 48H ;TIMER0 8 BIT MODE, INT CLK, NO

PRESCALE

MOVWF T0CON ;LOAD T0CON REGISTER

MOVLW 9CH

MOVWF TMR0L ;TMROL=9CH

BCF INTCON, TMR0IF ;CLEAR TIMER0 INTERRUPT FLAG BIT

BSF T0CON, TMR0ON ;START THE TIMER0

D1 BTFSS INTCON, TMR0IF ;MONITOR TIMER0 FLAG

BRA D1 ;UNTIL IT ROLLS OVER

BCF T0CON, TMR0ON ;STOP TIMER0

RETURN ;RETURN TO MAIN PROGRAM

ORG 410H

DR_25 NOP

D25 BSF PORTC,2 ;CLEAR THE CONTROL REGISTER OF CCP

Page 22: Report

22

CALL DELAY_DR

BCF PORTC,2

CALL DELAY_DR

CALL DELAY_DR

CALL DELAY_DR

MOVWF 01H, W ;COPY CONTENT OF 01H TO WREG

CPFSEQ ADRESL ;SKIP THE NEXT INSTRUCTION IF VALUE

OF ADRESL REGISTER IS EQUAL TO WREG

BRA B1 ;JUMP TO REFRESH

GOTO D25 ;JUMP TO D25

B1 NOP

RETURN

ORG 520H

DR_50 NOP ;CLEAR CCP1CON REGISTER

D50 BSF PORTC,2 ;CLEAR THE CONTROL REGISTER OF CCP

CALL DELAY_DR

CALL DELAY_DR

BCF PORTC,2

CALL DELAY_DR

CALL DELAY_DR

MOVWF 01H, W ;CHECK FOR ANY CHANGE IN ADC OUTPUT

CPFSEQ ADRESL

BRA B2 ;IF THERE IS CHANGE TAKE NEW VALUE ELSE

CONTINUE

GOTO D50

B2 NOP

RETURN

ORG 620H

DR_75 NOP

D75 BSF PORTC,2 ;CLEAR THE CONTROL REGISTER OF CCP

CALL DELAY_DR

CALL DELAY_DR

Page 23: Report

23

CALL DELAY_DR

BCF PORTC,2

CALL DELAY_DR

MOVWF 01H, W ;CHECK FOR ANY CHANGE IN ADC OUTPUT

CPFSEQ ADRESL

BRA B3 ;IF THERE IS CHANGE TAKE NEW VALUE ELSE

CONTINUE

GOTO D75

B3 NOP

RETURN

ORG 720H

DR_100 NOP

D100 BSF PORTC,2

GOTO REFRESH

ORG 820H

DELAY_DR MOVLW D'31'

MOVWF 05H

AGAIN NOP

DECF 05H,F

BNZ AGAIN

RETURN

END

Page 24: Report

24

3.5 Simulation Result:

To check if the code will work on the fabricated model we need to simulate and check if the

codes are giving the desired results. For this purpose, the circuit was connected in proteus as

shown in figure 3.3

Figure 3.3 The circuit in PROTEUS

Page 25: Report

25

Channel A is connected to pin 17 of the PIC and channel B is connected through the n-Channel

Mosfet acting as the switch.

The output for temperature below 25 degree celcius is as shown in figure 3.4

Figure 3.4 Output at 20 degree celcius

Page 26: Report

26

We can see that the output is zero as expected. Now For temperature range 26 to 35 degree, the

output is as shown in figure 3.5

Figure 3.5 Output at 30 degree celcius

We can see that the output is a pulse with duty ratio 25% as expected. Now For temperature

range 36 to 45 degree, the output is as shown in figure 3.6

Figure 3.5 Output at 38 degree celcius

We can see that the output is a pulse with duty ratio 50% as expected. Now For temperature

range 46 to 55 degree, the output is as shown in figure 3.6

Page 27: Report

27

Figure 3.6 Output at 52 degree celcius

We can see that the output is a pulse with duty ratio 75% as expected. Now For temperature

greater than 55 degree, the output is as shown in figure 3.7

Figure 3.7 Output at 62 degree celcius

We can see that the output is a pulse with duty ratio 100% as expected.

Page 28: Report

28

Chapter 4

Results and Conclusion

The prototype of the Temperature controlled DC fan using PIC18F452 microcontroller was simulated

and fabricated. The sensor was successfully interfaced with the microcontroller using ADC the

desired output pulses were observed in the simulation using PROTEUS software.

References

1. Muhammad Ali Mazidi, PIC Microcontroller and Embedded System, Pearson Education

inc.

2. http://extremeelectronics.co.in/microchip-pic-tutorials/interfacing-lm35-temperature-

sensor-with-pic-microcontroller/

3. http://www.makingthings.com/teleo/teleo/cookbook/autofan/index.htm

4. Datasheets of PIC18F452, LM35D, IRF520