0% found this document useful (0 votes)
14 views

Application of Microcontroller

Uploaded by

Adem Abdela
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Application of Microcontroller

Uploaded by

Adem Abdela
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Application Of Microcontrollers

Based on the information from the outside world through sensor,


a microcontroller can make a decision as per the rule that is pre-
set.

But the signal from the sensors is analog and MCU does not
understand it.

Therefore for the signal to be converted to digital, there must be

1. External ADC Module

2. Inbuilt ADC Module


PIC16f877a has inbuilt ADC module, It
can be accessed by the CPU by
manipulating the special function registers
ADCON0,
ADCON1,
ADRESL, and
ADRESH registers.
To do an A/D Conversion, follow these steps:
1. Configure the A/D module:
2. Configure analog pins/voltage reference and digital I/O (ADCON1)
Select A/D input channel (ADCON0)
Select A/D conversion clock (ADCON0)
Turn on A/D module (ADCON0)
3. Configure A/D interrupt (if desired):
Clear ADIF bit
Set ADIE bit
Set PEIE bit
Set GIE bit
4. Wait the required acquisition time.
5. Start conversion:
Set GO/DONE bit (ADCON0)
6. Wait for A/D conversion to complete by either:
Polling for the GO/DONE bit to be cleared (interrupts disabled); OR
Waiting for the A/D interrupt
7. Read A/D Result register pair (ADRESH:ADRESL), clear bit ADIF if required.
8. For the next conversion, go to step 1 or step 2 as required. The A/D conversion time
per bit is defined as TAD.
Resolution or Step Size = Vref / 2n
Dout= Vin/Resolution=V /(
in Vref / 2n ) =Vin*(2n/ Vref )
Where n- is number of output channel
The smaller the resolution the more sensitive the ADC is to the small change in
the analog signal.
To display the
analog reading
Or
Vin = Vout*Vref/2n
n=10
Vout = adc_rd
Vin = tlong
Temperature Controller using LM35

Note: 1) Refer to the data sheet of LM35 and write theory


on temperature sensor
2) For all output control use Solid State Relay
• The control is ON and OFF control
• The Output/Heater gets ON when Temperature
reaches below Lower Limit
• The Output/Heater gets OFF when Temperature
reaches above Lower Limit
• Sampling Time is assumed to be 15 secs
• You may use inbuilt or external ADC module.
PIC16F877a
40

Pa.2 P b.0
to LM
Pe.2 p b.7 35D
Osc1 Pd.0
Osc2
pd.7
20 To
Solid
state
relay

Hardware schematic of Temperature Controlling system


Flow chart
Start

Initialize, I/O
PORTs,
LCd, ADC ,
Variables,

Conversion
once in 15s

No
Is No
Act.Value> Is Act.Value Is Act.Value
SP <SP ==SP

Yes Yes Yes

Off Heater & On Fan ON Heater & Off Fan Off Heater & Off Fan
Material Required:

Pic Microcontroller

FAN-DC/ Simple Dc-motor

LM35 Temperature Sensor

Heater/ Oven/ Lamp

Bipolar Transistor

Relay

Capacitor

Crystal

Resistor

Diode
void main() {
unsigned int temp;
float mV, ActualTemp;
const float SET_POINT = 30.0; // Set point temperature
PORTD = 0;
TRISD.f0=TRISD.f2=0;
INTCON = 0; // All interrupts disabled
ADCON0 = 0x40; // Pin RA2 is configured as an analog
input
TRISA = 0x04; while (1) {
ADCON1 = 0x80; // Rest of pins are configured as digital temp = ADC_Read(0); // A/D conversion. Pin RA0 is an
TRISA = 0xFF; // All port A pins are configured as inputs input.
ADCON0.F0=1;//ADC module on mV = temp * 5000.0 / 1023.0; // convert to millivolt
PIR1.F6 = 0; // interrupt setting ActualTemp = mV / 10.0; // convert to degree celcius
PIE1.F6 = 0; if (ActualTemp > SET_POINT) {
INTCON.F6 = INTCON.F7 = 1; portd.f0 = 1;
Delay_ms(2000); portd.f2 = 0;
ADCON0.F2 = 1; }
else if (ActualTemp < SET_POINT) {
portd.f0 = 0;
portd.f2 = 1;
}
else {
portd.f2 = 0;
portd.f0 = 0;
}
delay_ms(1000);
}
}
Material Required:

Pic Microcontroller

FAN-DC/ Simple Dc-motor

LM35 Temperature Sensor

Heater/ Oven/ Lamp

Bipolar Transistor

Relay

Capacitor

Crystal

Resistor

Diode
Example: Temperature Reading and Control
LM35 temperature
sensor converts
temperature into its
proportional analog
voltage value.
LM35 is three terminal
device.
Pin number one and
three are for 5- volt
voltage supply.
Pin two is analog voltage
output with respect to
temperature value.
Relation between
measured temperature
and analog output
voltage is: 1 oC = 10m volt
Select A/D input channel (ADCON0)

Select A/D conversion clock (ADCON0)

Turn on A/D module (ADCON0)


Configure A/D interrupt (if desired):

Data to LCD
MCU’s guide
on how to
control the
temperature
To
Solid PIC16F84a
state 40
relay EA Vcc
Vin
Pa.2 P b.0 D0
to D7 A/D
p b.7
Osc1 Pa.1 OE
Osc2 LM
pa.0 SOC
20 35D

Hardware schematic of Temperature Controlling system with External ADC Module


Flow chart
Start Soc start of conversion,` ADC_Start

Initialize SoC, Issue Start of


OE, Temp OE (Output enable signal)
Conversion
limits

Wait for
conv. time
Call ADC
Issue OE
signal
No
Is No
Is Act.Value Ret
Act.Value>
UL <LL

Yes Yes
Off ON
Heater Heater
Water Level Controller using e-level sensor

Note: 1) Refer to the data sheet of e-level sensor . and write theory on level sensor
(Resistance inverse to Level)

2) For all output control use Solid State Relay


• The control is ON and OFF control
• The Output/Motor gets ON when level reaches below Lower Limit
• The Output/Motor gets OFF when level reaches above Lower Limit
• Sampling Time is assumed to be 15 secs
• 8 bit A/D with conversion time of 100us is used for data conversion
• Use the Hardware schematic of Temp.control and replace LM35D with level
sensor
• Use the Flow chart of Temp.control and replace heater with motor and
temperature limits as liquid level limits
• Use the program of Temperature control and replace the temp. limits with
Liquid level limit values
Timer /Counter Interrupt
In all the time delays are provided using loops, the microcontroller is ‘captive’ and does

nothing. It simply waits for some time to pass. Such waste of time is an unacceptable

luxury and some other method should be applied therefore.

Do you remember the story about timers? Interrupts?

 Timer TMR0 with assigned prescaler is used for this purpose.

 An interrupt is generated on every timer register overflow and every interrupt routine

automatically increments the cnt variable by 1.

 When it’s value reaches 400, the port B is incremented by 1. The whole procedure is

performed ‘behind the scenes’, which enables the microcontroller to do something else.
Further Read C-Programming for PIC
Assignment

DC MOTOR SPEED
CONTROL
Using Microcontroller!

You might also like