EC7451: MICROPROCESSOR AND … V- Microcontroller...Dr. V. SATHIESH KUMAR Department of Electronics...
Transcript of EC7451: MICROPROCESSOR AND … V- Microcontroller...Dr. V. SATHIESH KUMAR Department of Electronics...
EC7451: MICROPROCESSOR AND MICROCONTROLLER
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 1
Presentation Slides:
www.sathieshkumar.com/tutorials
Unit V: MICROCONTROLLER BASED SYSTEM DESIGN 1. Interfacing to: matrix display 2. (16x2) LCD 3. High power devices 4. Optical motor shaft encoder 5. Stepper Motor 6. DC Motor speed Control using PWM 7. RTC and EEPROM interface using I2C protocol TEXT BOOK Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinley, "The 8051 Microcontroller and Embedded Systems", Second Edition, Pearson Education 2008. Fifth impression 2011
Presented By,
Dr. V. Sathiesh Kumar Department of Electronics Engg.,
MIT-Anna University
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 2
8051 Microcontroller: Stepper Motor Interfacing
Translates electrical pulses into mechanical movement.
Applications: Disk drives, Dot matrix printers, robotics
Shaft is a permanent magnet rotor, surrounded by a four stator windings that are
paired with a centre-tapped common. This type of motors are termed as four phase or
unipolar stepper motors.
The center tap allows a change of current direction in each of two coils when a
winding is grounded, thereby resulting in a polarity change of the stator.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 3
8051 Microcontroller: Stepper Motor Interfacing
A
B
A
B
Control Word (Clockwise)
0 1 1 1 0x07
1 0 1 1 0x0B
1 1 0 1 0x0D
1 1 1 0 0x0E
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 4
8051 Microcontroller: Stepper Motor Interfacing
A
B
A
B
Control Word (Clockwise)
0 0 1 1 0x03
1 0 0 1 0x09
1 1 0 0 0x0C
0 1 1 0 0x06
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 5
8051 Microcontroller: Stepper Motor Interfacing
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 6
8051 Microcontroller: Stepper Motor Interfacing
Step angle is determined by the internal construction of the motor, in particular the
number of teeth on the stator and the rotor.
The step angle is the minimum degree of rotation associated with a single step.
Steps per revolution is the total number of steps needed to rotate one complete
rotation or 360 degrees.
rpm Steps per revolution Steps per second=
60
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 7
8051 Microcontroller: Stepper Motor Interfacing
In a 4-step switching sequence, after four steps the same two windings will be “ON”.
How much movement is associated with these four steps?
After completing every four steps, the rotor moves only one tooth pitch.
Therefore, in a stepper motor with 200 steps per revolution, the rotor has 50
teeth because 4x50=200 steps are needed to complete one revolution.
Minimum step angle is always a function of the number of teeth on the rotor.
In other words, the smaller the step angle, the more teeth the rotor passes.
Motor Speed: Measured in steps per second (steps/s), is a function of switching rate
(By changing the length of the time delay loop, we can achieve various rotation speeds).
Holding torque: With the motor shaft at standstill or zero rpm condition, the amount
of torque, from an external source, required to break away the shaft from its holding
position. This is measured with rated voltage and current applied to the motor. The unit
of torque is ounce-inch or kg-cm.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 8
8051 Microcontroller: Stepper Motor Interfacing
Three common types of stepper motor interfacing: universal, unipolar and bipolar.
They can be identified by the number of connections to the motor.
A universal stepper motor has eight, while the unipolar has six and the bipolar
has four.
The universal stepper motor can be configured for all three modes, while the
unipolar can be either unipolar or bipolar. Obviously the bipolar cannot be
configured for universal nor unipolar mode.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 9
8051 Microcontroller: Stepper Motor Interfacing
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 10
8051 Microcontroller: Stepper Motor Interfacing – 4 Step Sequence/Biphase
ORG 0000H
MOV A, #66H ; load step sequence
BACK: MOV P1, A ; issue sequence to motor
RR A ; rotate right clockwise
ACALL DELAY ; wait
SJMP BACK ; continue loop
DELAY: MOV R2, #100
H1: MOV R3, #255
H2: DJNZ R3, H2
DJNZ R2, H1
RET
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 11
8051 Microcontroller: Stepper Motor Interfacing – 8 Step Sequence
ORG 0000H
START: MOV R0, #08H ; initialize count for data
MOV DPTR, #0200H ; Load DPTR with 0200H
RPT: CLR A ; clear A
MOVC A, @A+DPTR ; load data to A
MOV P1, A ; send value to port 1
CALL DELAY ; wait
INC DPTR ; increment DPTR to next data
DJNZ R0, RPT ; decrement count
SJMP START ; continue loop
ORG 0200H
DB 09H, 08H, 0CH, 04H, 06H, 02H, 03H, 01H
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 12
8051 Microcontroller: Stepper Motor Interfacing – 8 Step Sequence
DELAY: MOV R2, #100
H1: MOV R3, #255
H2: DJNZ R3, H2
DJNZ R2, H1
RET
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 13
ADC0808 Interface with 8051
•It is a monolithic CMOS device with an 8-bit analog to digital convertor.
•It has 8 channel multiplexer to interface with the microprocessor.
• The 8-bit A/D convertor uses successive approximation as the conversion technique.
•The ADC0808, ADC0809 offers high speed, high accuracy, minimal temperature
dependence, excellent long-term accuracy, repeatability, and consumes minimal
power.
•One of the main advantage of this chip is that it does not require any external zero
and full scale adjustment, only +5V DC supply is sufficient.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 14
ADC0808 Interface with 8051: Architecture
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 15
ADC0808 Interface with 8051: Pin Details
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 16
ADC0808 Interface with 8051:
• The device contains an 8-channel single-ended analog signal multiplexer.
•A particular input channel is selected by using the address decoder.
•The address is latched into the decoder on the low-to-high transition of the address
latch enable (ALE) signal.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 17
ADC0808 Interface with 8051: Typical Application
Potentiometer connected to IN1
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 18
ADC0808 Interface with 8051:
ALE BIT P2.4
OE BIT P2.5
SC BIT P2.6
EOC BIT P2.7
ADDR_A BIT P2.0
ADDR_B BIT P2.1
ADDR_C BIT P2.2
MYDATA EQU P1
ORG 0000H
MOV MYDATA, #0FFH ; make P1 an input
SETB EOC ; make EOC an input
CLR ALE ; clear ALE - output
CLR SC ; clear WR - output
CLR OE ; clear OE - output
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 19
ADC0808 Interface with 8051:
BACK: CLR ADDR_C ; C=0
CLR ADDR_B ; B=0
SETB ADDR_A ; A=1 (Select Channel 1)
ACALL DELAY ; Wait till address becomes stable
SETB ALE ; latch address
ACALL DELAY ;
SETB SC ; Start the Conversion
ACALL DELAY ;
CLR ALE ;
CLR SC ;
HERE1: JNB EOC, HERE1 ; wait until conversion complete
SETB OE ; enable RD
ACALL DELAY ; wait
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 20
ADC0808 Interface with 8051:
MOV A, MYDATA ; read data
CLR OE ; clear RD for next acquisition
SJMP BACK
DELAY: MOV CX, 07FFH //Delay Subroutine
LOOP1: NOP
NOP
DEC CX
JNE LOOP1
RET
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 21
DAC0808 Interface with 8051:
DAC 0808 is a 8-bit Digital to Analog Convertor.
Binary weighted DAC and R/2R ladder type
DAC0808 (8-bit) provides 256 discrete voltage or current levels of output
7 6 5 3 04 2 1( )2 4 8 16 32 64 128 256
out ref
D D D D DD D DI I
2refI mA
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 22
DAC0808 Interface with 8051:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 23
DAC0808 Interface with 8051:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 24
DAC0808 Interface with 8051: Square waveform generation
START: MOV A, #00H // Low logic level
MOV P1, A
CALL DELAY
MOV A, #FFH // High logic level
MOV P1, A
CALL DELAY
JMP START
DELAY: MOV CX, 07FFH //Delay Subroutine
LOOP1: NOP
NOP
DEC CX
JNE LOOP1
RET
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 25
DAC0808 Interface with 8051: Sawtooth waveform generation
MOV A, #00H // Low logic level
MOV P1, A
BACK: INC A
SJMP BACK
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 26
16X2 LCD Displays:
LCD replacing LEDs (Seven-segment LEDs or other multi-segment LEDs) due to
following reasons:
1. Declining prices of LCDs
2. The ability to display numbers, characters and graphics. This is in contrast to LEDs,
which are limited to numbers and few characters.
3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the
task of refreshing the LCD. IN contrast, the LED must be refreshed by the CPU (or in
some other way) to keep displaying the data.
4. Ease of programming for characters and graphics.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 27
16X2 LCD Displays:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 28
16X2 LCD Displays:
Vcc and Vss provide +5V and ground respectively.
VEE is used for controlling the LCD contrast.
Register Select (RS) is used to select the command code register or data register
(RS=0: command code register, RS=1: data register).
Read/Write (R/W) input allows the user to write information to the LCD or read
information from it (R/W=0: Write, R/W=1: Read).
Enable (E) pin is used by the LCD to latch information presented to its data pin.
When data is supplied to data pins, a high-to-low pulse must be applied to the E pin
in order for the LCD to latch in the data present at the data pins. This pulse must be a
minimum of 450 ns wide.
D0-D7 is 8-bit data pins are used to send information to the LCD or read the contents
of the LCD’s internal registers.
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 29
16X2 LCD Displays:
To display letters and numbers, we send ASCII codes for the letters A-Z, a-z and
numbers 0-9 to these pins while making RS=1.
There are two ways to send characters (command/data):
1. use a delay before sending the next one
2. use the busy flag (D7 bit of command register, R/W=1, E=L to H pulse) to see if
the LCD is ready for the next one.
Code(Hex) Function Code(Hex) Function
1 Clear display screen C Display on, Cursor off
4 Decrement Cursor E (or) F Display on, Cursor Blinking
6 Increment Cursor 80 Beginning of 1st line
5 Shift Display Right C0 Beginning of 2nd line
7 Shift Display Left 90 Beginning of 3rd line
8 Display off, Cursor off D0 Beginning of 4th line
A Display off, Cursor on 2 Return Home
LCD command codes
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 30
16X2 LCD Displays:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 31
16X2 LCD Displays:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 32
16X2 LCD Displays:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 33
40X2 LCD Displays: Addressing
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 34
16X2 LCD Displays:
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 35
16X2 LCD Displays:
P1.0 – P1.7 are connected to LCD data pins D0 – D7
P2.0 is connected to RS pin of LCD
P2.1 is connected to R/W* pin of LCD
P2.2 is connected to E pin of LCD
ORG 0000H
MOV A, #38H ; initialize LCD 16 X 2
ACALL COMD ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #0EH ; display on, cursor on
ACALL COMD ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #01H ; clear LCD
ACALL COMD ; call command subroutine
ACALL DELAY ; give LCD some time
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 36
16X2 LCD Displays:
MOV A, #06H ; shift cursor right
ACALL COMD ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #84H ; cursor at line 1, position 4
ACALL COMD ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #’N’ ; display letter N
ACALL DATA ; call display subroutine
ACALL DELAY ; give LCD some time
MOV A, #’O’ ; display letter O
ACALL DATA ; call display subroutine
AGAIN: SJMP AGAIN ; stay here
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 37
16X2 LCD Displays:
COMD: MOV P1, A ; copy reg A to port 1
CLR P2.0 ; RS=0 for command
CLR P2.1 ; R/W*=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for High to Low pulse
RET
DATA: MOV P1, A ; copy reg A to port 1
SETB P2.0 ; RS=1 for data
CLR P2.1 ; R/W*=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for High to Low pulse
RET
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 38
16X2 LCD Displays:
DELAY: MOV R3, #50 ; 50 or higher for fast CPUs
HERE2: MOV R4, #255 ; R4=255
HERE: DJNZ R4, HERE ; stay until R4 becomes 0
DJNZ R3, HERE2 ;
RET
END
MICROPROCESSOR AND MICROCONTROLLER UNIT V – Microcontroller Based System Design
Dr. V. SATHIESH KUMAR Department of Electronics Engg., MIT 39
Summary
1.Stepper Motor Interfacing
2.ADC and DAC interfacing
3.LCD Interfacing
MICROPROCESSOR AND MICROCONTROLLER UNIT IV & V – Microcontroller & it Applications