interfacing hardware with microcontrollerrobotika.yweb.sk/skola/avr/avr projekty/workshop.pdf ·...
TRANSCRIPT
INTERFACING HARDWARE WITH
MICROCONTROLLER
P.Raghavendra PrasadFinal Yr EEE
www.raghu.co.nr
What is a Microcontroller ?What is a Microcontroller ?
A i t ll ( MCU) i t hi ItA microcontroller (or MCU) is a computer-on-a-chip. Itis a type of microprocessor emphasizing self-sufficiency and cost-effectiveness in contrast to asufficiency and cost effectiveness, in contrast to ageneral-purpose microprocessor (the kind used in aPC). The only difference between a microcontroller anda microprocessor is that a microprocessor has threeparts - ALU, Control Unit and registers (like memory),
h l h ll h dd l l l kwhile the microcontroller has additional elements likeROM, RAM etc.
www.raghu.co.nr
ATMEGA32/ATMEGA32Lh f A 8 b M llHigh-performance, Low-power AVR 8-bit Microcontroller
Up to 16 MIPS Throughput at 16 MHz32K Bytes of In-System Self-Programmable Flashy y g1024 Bytes EEPROM2K Byte Internal SRAMTwo 8-bit Timer/Counters One 16-bit Timer/CounterTwo 8-bit Timer/Counters, One 16-bit Timer/CounterIn-System Programming by On-chip Boot ProgramFour PWM Channels8 h l 10 bi ADC8-channel, 10-bit ADCProgrammable Serial USARTInternal Calibrated RC OscillatorExternal and Internal Interrupt SourcesPower-on Reset32 Programmable I/O Lines
www.raghu.co.nr
32 Programmable I/O Lines
ATMEGA32/32L ATMEGA16/16LATMEGA32/32L ATMEGA16/16L
32K Bytes of Flash memory 16K Bytes of Flash memory
1024 Bytes EEPROM
2K Byte Internal SRAM
512 Bytes EEPROM
1K Byte Internal SRAM2K Byte Internal SRAM 1K Byte Internal SRAM
www.raghu.co.nr
ATMEGA32/16 ATMEGA32L/16LATMEGA32/16 ATMEGA32L/16L
Operating Voltage 4.5 - 5.5 V
Operating Voltage 2.7 - 5.5 V
Speed Grades Speed GradesSpeed Grades0 – 16 MHz
Speed Grades0 – 8 MHz
www.raghu.co.nr
Pin Diagram
www.raghu.co.nr
COMPUTER
cC - CODE COMPILER HEX - CODE
MICRO CONTROLLER
www.raghu.co.nr
STK200 CableSTK200 Cable
Configuring PORT PINS
Each PORT consists of three registers
DDRX (Data Direction Register)
PORTX
PINXPINX
Where X = A, B, C, D
www.raghu.co.nr
DDRX
The DDXn bit in the DDRx Register selects the direction of pin n.g pIf 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 7Where 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
www.raghu.co.nr
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 HIGHWriting logic ZERO to this pin, drives the port pin LOW
www.raghu.co.nr
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
www.raghu.co.nr
ICCAVR
ICCAVR, the ImageCraft’s C Development Environment is aprogram for developing AVR microcontroller applications usingthe ANSI standard C language
Full featured 30-day demo program can be downloaded from the ImageCraft web site
fwww.image-craft.com
www.raghu.co.nr
Getting Started with ICCAVR
1. Project>New2 Project name and path2. Project name and path3. Project>Options4. In the Compiler options, check “Accept C++ Comments” and “Intel HEX” as the “output format”the output format5. 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.
www.raghu.co.nr
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 pinsDDRA 0xFF; // Configures PORTA Pins as Output pins
While(1){PORTA=0xFF;D l (500)Delay(500);PORTA=0x00;Delay(500);
} }
www.raghu.co.nr
} }
Interfacing with Microcontrollerg
LED
Switches
DC Motor
Sensors
S MStepper Motor
www.raghu.co.nr
LED – Light Emitting Diode
M i t ti l d LED 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 h l h h hwith LED to limit the current through it.
www.raghu.co.nr
Calculating LED resistor value g
R = (Vs – VL )/I
Vs = supply voltage VL = Voltage drop across LED VL = Voltage drop across LED
( around 2V)I = 15 to 30 ma
www.raghu.co.nr
LED’s connected to 1. PORTA02.PORTB0
LED BLINK PROGRAMLED BLINK PROGRAM
www.raghu.co.nr
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 .useful .
Gear’s reduce the speed of motor and increases the torque
www.raghu.co.nr
Choosing a DC Motor
DC Motor with Gear headOperating voltage 12VSpeed Depends on our applicationDepends on our application
Some available speeds in market30 RPM60 RPM60 RPM
100 RPM150 RPM350 RPM1000 RPM
www.raghu.co.nr
Drive basics of DC MotorDrive basics of DC Motor
Red wire Black wire Direction of rotation
Positive Negative Clock wise
Negative Positive Anti clock wiseg
Logic Logic Direction
1 0 Clock
0 A0 1 Anti clock
www.raghu.co.nr
Bi Direction control of DC MotorBi-Direction control of DC Motor
H-Bridge Ckt using transistors for bidi ti l d i i f DC t
Direction Pulse to
bidirectional driving of DC motor
Clock wise A and C
Anti Clock wise B and D
www.raghu.co.nr
H-Bridges in IC’s to reduce the drive circuit complexity H Bridges in IC s to reduce the drive circuit complexity
Th t l d H B id L293D d The most commonly used H-Bridges are L293D and L298L293D has maximum current rating of 600maL293D has maximum current rating of 600maL298 has maximum current rating of 2ABoth has 2 H-Bridges in themThese are designed to drive inductive loads such as relays, solenoids
C b d d 2 CCan be used to drive 2 DC motors or 1 stepper motor
www.raghu.co.nr
DRIVING OF DC MOTORDRIVING OF DC MOTOR
www.raghu.co.nr
Switches
Active LowWhen pressed shorts the corresponding pin to ground
Active highWhen pressed shorts the corresponding pin to Vcc
www.raghu.co.nr
Active lowActive lowActive high
INTERFACING SWITCHES
www.raghu.co.nr
Sensors
Commonly used sensors in the field of robotics areCommonly used sensors in the field of robotics are
IR Digital sensors
IR analog sensors
www.raghu.co.nr
IR Digital sensors
TransmitterIR led connected to 38KHz oscillator
ReceiverTSOP1738
IR Analog sensors
TransmitterIR LED
ReceiverReceiverIR Photodiode
www.raghu.co.nr
IR Analog sensor
www.raghu.co.nr
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 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.
www.raghu.co.nr
4 – Lead stepper 5 – Lead stepper
6 – Lead stepper 8 – Lead stepper
www.raghu.co.nr
Full Step driving of Stepper Motor
Full step wave drive
4 3 2 14 3 2 1
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
www.raghu.co.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 10 0 1 1
1 0 0 1
www.raghu.co.in
Half Step driving of stepper motor
4 3 2 1
1 0 0 0
1 1 0 0
0 1 0 00 1 0 0
0 1 1 0
0 0 1 0
0 0 1 1
0 0 0 1
1 0 0 11 0 0 1
www.raghu.co.nr
Choosing a Stepper motor
12 V operating voltage1 8 degree step1.8 degree step6 Lead 250 t0 500 ma of current
orCoil resistance of 20 ohms to 40 ohmsSize and shape depends on applicationp p ppIn most of the robotics cube shaped motors are
preferred with frame size of 3.9 to 4 cm
www.raghu.co.nr
Commonly used IC’s for driving Stepper motor
ULN2803• It has 8 channels• It has 8 channels• It channel has maximum current rating of 500ma• can be used to drive 2 unipolar stepper motors
L293d
L297 & L298
www.raghu.co.nr
ULN2803
www.raghu.co.nr
Bi – Polar driving of Stepper Motor
A B C D
1 1 0 0
0 1 1 0
0 0 1 10 0 1 1
1 0 0 1
www.raghu.co.nr
DRIVING STEPPER MOTOR
www.raghu.co.nr
Line Follower
sensor1L2
Leftmotorsensor1
sensor2
293D
motor
RightM t
Microcontrollersensor3
Motor
www.raghu.co.nr
You can download this presentation atYou can download this presentation atwww.raghu.co.nr
www.raghu.co.nr