Interface Different Hardwares with 8051 Microcontroller

Preview:

DESCRIPTION

In this paper presentation you can easily get information about different peripheral devices on how to interface them with 8051 Microcontroller and its Family

Citation preview

INTERFACING HARDWARE WITH

MICROCONTROLLER

http://electronicsbasedprojects4u.blogspot.in

Naveen SrivastavaFinal Yr ECE

http://electronicsbasedprojects4u.blogspot.in

What is a Microcontroller ?

A microcontroller (or MCU) is a computer-on-a-chip. It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). The only difference between a microcontroller and a microprocessor is that a microprocessor has three parts - ALU, Control Unit and registers (like memory), while the microcontroller has additional elements like ROM, RAM etc.

http://electronicsbasedprojects4u.blogspot.in

ATMEGA32/ATMEGA32L High-performance, Low-power AVR 8-bit Microcontroller Up to 16 MIPS Throughput at 16 MHz 32K Bytes of In-System Self-Programmable Flash 1024 Bytes EEPROM 2K Byte Internal SRAM Two 8-bit Timer/Counters, One 16-bit Timer/Counter In-System Programming by On-chip Boot Program Four PWM Channels 8-channel, 10-bit ADC Programmable Serial USART Internal Calibrated RC Oscillator External and Internal Interrupt Sources Power-on Reset 32 Programmable I/O Lines

http://electronicsbasedprojects4u.blogspot.in

ATMEGA32/32L ATMEGA16/16L

32K Bytes of Flash memory

1024 Bytes EEPROM

2K Byte Internal SRAM

16K Bytes of Flash memory

512 Bytes EEPROM

1K Byte Internal SRAM

http://electronicsbasedprojects4u.blogspot.in

ATMEGA32/16 ATMEGA32L/16L

Operating Voltage 4.5 - 5.5 V

Speed Grades 0 – 16 MHz

Operating Voltage 2.7 - 5.5 V

Speed Grades 0 – 8 MHz

http://electronicsbasedprojects4u.blogspot.in

Pin Diagram

c

http://electronicsbasedprojects4u.blogspot.in

C - CODE COMPILERHEX - CODE

COMPUTER

MICRO CONTROLLER

STK200 Cable

http://electronicsbasedprojects4u.blogspot.in

Configuring PORT PINS

Each PORT consists of three registers

DDRX (Data Direction Register)

PORTX

PINX

Where X = A, B, C, D

http://electronicsbasedprojects4u.blogspot.in

DDRX

The DDXn bit in the DDRx Register selects the direction of pin n. If DDXn is written logic one, PXn is configured as an output pin. If DDXn is written logic zero, PXn is configured as an input pin. Where n = 0,1,2 - - - ,7

For Example If DDRA = 0x0F ( 0000 1111)

The Lower bytes of PORTA are configured as output pins The Higher bytes of PORTA are configured as input pins

http://electronicsbasedprojects4u.blogspot.in

PORTX

When PORTXn is configured as Input Pin Writing logic ONE to this pin, activates pull-up resistor. Writing logic ZERO to this pin, deactivates pull-up resistor

When PORTXn is configured as Output Pin

Writing logic ONE to this pin, drives the port pin HIGH Writing logic ZERO to this pin, drives the port pin LOW

http://electronicsbasedprojects4u.blogspot.in

PINX

PINXn is used to read the value of particular port pin

Independent of the setting of Data Direction bit DDRXn, the port pin can be read through the PINXn Register bit

http://electronicsbasedprojects4u.blogspot.in

ICCAVR

ICCAVR, the ImageCraft’s C Development Environment is a program for developing AVR microcontroller applications using the ANSI standard C language

Full featured 30-day demo program can be downloaded from the ImageCraft web site

www.image-craft.com

http://electronicsbasedprojects4u.blogspot.in

Getting Started with ICCAVR

1. Project>New2. Project name and path3. Project>Options4. In the Compiler options, check “Accept C++ Comments” and “Intel HEX” as the “output format”5. In the Target options, select “ATmega32/Atmega16” under “Device Configuration”6. Write the source code7. Add the source file to the project by selecting “Project>Add File(s)” and select the file just written8. Compile by selecting “Project>Make Project” or by clicking on the “build” icon9. Open AVR ISP and download the hex file generated by ICCAVR , It is stored under the project name.

http://electronicsbasedprojects4u.blogspot.in

Sample program to generate Square wave on PORTA of ATMEGA32#include<iom32v.h>#include<macros.h>Void delay(unsigned int i) { unsigned int k; While(i--) For(k=0;k<=500;k++); }Void main() { DDRA = 0xFF; // Configures PORTA Pins as Output pins While(1) { PORTA=0xFF; Delay(500); PORTA=0x00; Delay(500);} }

http://electronicsbasedprojects4u.blogspot.in

Interfacing with Microcontroller

LED

Switches

DC Motor

Sensors

Stepper Motor

http://electronicsbasedprojects4u.blogspot.in

LED – Light Emitting Diode

Maximum potential drop across LED will be approximately 2V.

Maximum current tat can be allowed through am LED is approximately 30ma.

Resistor should be added in series with LED to limit the current through it.

http://electronicsbasedprojects4u.blogspot.in

Calculating LED resistor value

R = (Vs – VL )/I

Vs = supply voltage VL = Voltage drop across LED ( around 2V) I = 15 to 30 ma

LED’s connected to 1. PORTA0 2.PORTB0

LED BLINK PROGRAM

http://electronicsbasedprojects4u.blogspot.in

http://electronicsbasedprojects4u.blogspot.in

DC Motor

DC Motors are small, inexpensive and powerful motors used widely.

These are widely used in robotics for their small size and high energy out.

A typical DC motor operates at speeds that are far too high speed to be useful, and torque that are far too low.

Gear reduction is the standard method by which a motor is made useful .

Gear’s reduce the speed of motor and increases the torque

http://electronicsbasedprojects4u.blogspot.in

Choosing a DC Motor

DC Motor with Gear head Operating voltage 12V Speed Depends on our applicationSome available speeds in market

30 RPM 60 RPM 100 RPM 150 RPM 350 RPM 1000 RPM

http://electronicsbasedprojects4u.blogspot.in

Drive basics of DC Motor

Red wire Black wire Direction of rotation

Positive Negative Clock wise

Negative Positive Anti clock wise

Logic Logic Direction

1 0 Clock

0 1 Anti clock

http://electronicsbasedprojects4u.blogspot.in

Direction Pulse to

Clock wise A and C

Anti Clock wise B and D

Bi-Direction control of DC Motor

H-Bridge Ckt using transistors for bidirectional driving of DC motor

http://electronicsbasedprojects4u.blogspot.in

H-Bridges in IC’s to reduce the drive circuit complexity

The most commonly used H-Bridges are L293D and L298 L293D has maximum current rating of 600ma L298 has maximum current rating of 2A Both has 2 H-Bridges in them These are designed to drive inductive loads such as relays, solenoids Can be used to drive 2 DC motors or 1 stepper motor

DRIVING OF DC MOTOR

http://electronicsbasedprojects4u.blogspot.in

http://electronicsbasedprojects4u.blogspot.in

Switches

Active Low When pressed shorts the corresponding pin to ground

Active highWhen pressed shorts the corresponding pin to Vcc

Active low Active

high

INTERFACING SWITCHES

http://electronicsbasedprojects4u.blogspot.in

http://electronicsbasedprojects4u.blogspot.in

Sensors

Commonly used sensors in the field of robotics are

IR Digital sensors

IR analog sensors

http://electronicsbasedprojects4u.blogspot.in

IR Digital sensors

Transmitter IR led connected to 38KHz oscillator

Receiver TSOP1738

IR Analog sensors

Transmitter IR LED

Receiver IR Photodiode

http://electronicsbasedprojects4u.blogspot.in

IR Analog sensor

http://electronicsbasedprojects4u.blogspot.in

STEPPER MOTOR STEPPER MOTOR is a brushless DC motor whose rotor rotates in discrete angular increments when its stator windings are energized in a programmed manner. Rotation occurs because of magnetic interaction between rotor poles and poles of sequentially energized stator windings. The rotor has no electrical windings, but has salient and/or magnetized poles.

http://electronicsbasedprojects4u.blogspot.in

4 – Lead stepper 5 – Lead stepper

6 – Lead stepper 8 – Lead stepper

http://electronicsbasedprojects4u.blogspot.in

Full Step driving of Stepper Motor

Full step wave drive

4 3 2 1

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

http://electronicsbasedprojects4u.blogspot.in

Full Step driving of Stepper Motor

Full step 2 phases active

4 3 2 1

1 1 0 0

0 1 1 0

0 0 1 1

1 0 0 1

http://electronicsbasedprojects4u.blogspot.in

Half Step driving of stepper motor

4 3 2 1

1 0 0 0

1 1 0 0

0 1 0 0

0 1 1 0

0 0 1 0

0 0 1 1

0 0 0 1

1 0 0 1

http://electronicsbasedprojects4u.blogspot.in

Choosing a Stepper motor

12 V operating voltage 1.8 degree step 6 Lead 250 t0 500 ma of current or Coil resistance of 20 ohms to 40 ohms Size and shape depends on application In most of the robotics cube shaped motors are preferred with frame size of 3.9 to 4 cm

http://electronicsbasedprojects4u.blogspot.in

Commonly used IC’s for driving Stepper motor

ULN2803• It has 8 channels• It channel has maximum current rating of

500ma• can be used to drive 2 unipolar stepper

motors

L293d

L297 & L298

http://electronicsbasedprojects4u.blogspot.in

ULN2803

http://electronicsbasedprojects4u.blogspot.in

A B C D

1 1 0 0

0 1 1 0

0 0 1 1

1 0 0 1

Bi – Polar driving of Stepper Motor

DRIVING STEPPER MOTOR

http://electronicsbasedprojects4u.blogspot.in

http://electronicsbasedprojects4u.blogspot.in

Microcontroller

sensor1

sensor3

sensor2

L293D

LeftmotorRigh

tMoto

r

Line Follower