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

Machine Design

The document discusses interfacing a DAC and stepper motor with an 8051 microcontroller. It provides circuit diagrams and programs to generate waveform outputs like staircase, ramp, sawtooth and triangular using an interfaced DAC. It also discusses the working of a stepper motor, the need for a driver IC like ULN2003 to control the motor, and provides the logic to control stepper motor movement in full step mode.

Uploaded by

Amit Dipankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Machine Design

The document discusses interfacing a DAC and stepper motor with an 8051 microcontroller. It provides circuit diagrams and programs to generate waveform outputs like staircase, ramp, sawtooth and triangular using an interfaced DAC. It also discusses the working of a stepper motor, the need for a driver IC like ULN2003 to control the motor, and provides the logic to control stepper motor movement in full step mode.

Uploaded by

Amit Dipankar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Microcontroller & Embedded Prog.

(MU-Sem 5-IT) 5-4 8051 Interfacing and Applications

! Interfacing of ADC with 8051

Fig. 5.1.3 : Interfacing of ADC with 8051

! 5.2 8051 | 8-bit DAC Interfacing

! 5.2.1 Interface DAC 0808 to 8051

DAC is an 8 bit Digital to Analog Converter.


It can convert an 8 bit digital data input into an analog voltage output.
Reference voltage for conversion is provided using +Vref and –Vref.
The output of the DAC is actually in current form.
This can be converted into voltage using an op-amp IC 741.
DACs are used in various applications such as PWM, Motor control Applications, DSP etc.
For waveform displays, we connect the output to a display device like a CRO.
By simple programming we can generate several types of wave forms like
Ramp, Saw-tooth, Triangular waveform etc.

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-5 8051 Interfacing and Applications

Fig. 5.2.1 : DAC 0808 interfacing with 8051

! 5.2.2 Program to Generate Staircase Waveform

! Interface

Refer Previous Section, draw the exact same diagram.

Fig. 5.2.2 : Staircase waveform

! Algorithm

Initialise A as 00H
Send A on P1
Call delay (100 milliseconds)
Increment A
Loop till A crosses FFH and rolls back to 00H.

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-6 8051 Interfacing and Applications

! Program

MOV A, #00H ; A ç 00H


Back : MOV P1, A ; P1 ç A register
ACALL Delay ; Call a delay of 100 milliseconds
INC A ; Increment A
JNZ Back ; Loop till A rolls back to 00H.
Here : SJMP Here ; End the program
" Please Note
! This is truly a fun program to do in practical sessions. For taller steps, increment A by 2 (or even higher).
! For wider or narrower steps, increase or reduce the delay duration respectively.

! All these waveforms like staircase, ramp, saw-tooth, triangle etc. sound very boring when you only treat them as
just waveforms. But if you imagine controlling external devices using these waveforms, you will understand WHY
you are required to learn these programs.

! Imagine if this output was connected to a bulb. It will turn on with increasing levels of brightness on each step.
Smoothen the output and now you will get theatre dimming and glowing effect.

! Connect the output to the spout of a fountain and you will see the water jet rising higher and higher with increasing
intensity, and so on.

! 5.2.3 Program to generate Ramp waveform

Same as a staircase, just reduce the delay to 5-10 milliseconds


Program : Same as a staircase, just reduce the delay to 5-10 milliseconds

Fig. 5.2.3 : Ramp waveform

! 5.2.4 Program to generate Saw-tooth waveform

! Algorithm

Initialise A as 00H
Send A on P1
Call delay (10 milliseconds)
Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture
Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-7 8051 Interfacing and Applications

Increment A
Loop infinitely, so that the output goes from
00H gradually to FFH then drops to 00H and repeats

! Program

MOV A, #00H ; A ç 00H


Back: MOV P1, A ; P1 ç A register
ACALL Delay ; Call a delay of 10 milliseconds
INC A ; Increment A
SJMP Back ; Loop back, infinitely

Fig. 5.2.4 : Saw tooth waveform

! 5.2.5 Program to Generate Triangular Waveform

Q. Write an assembly language program to generate triangular wave using DAC

interfacing with 8051 micro controller. (Q. 4(A), Dec. 18, 10 Marks)

Q. Write a program to generate a triangular waveform using DAC and 8051. Draw the

interfacing circuit diagram. (Q. 4(B), Dec. 19, 10 Marks)

! Algorithm

Initialise A as 00H
Send A on P1
Call delay (10 milliseconds)
Increment A gradually from 00H…FFH and stop
Repeat the process decrementing A from FEH…01H.
Repeat the whole process, infinitely.

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-8 8051 Interfacing and Applications

! Program

MOV A, #00H ; A ç 00H


Back1 : MOV P1, A ; P1 ç A register
ACALL Delay ; Call a delay of 10 milliseconds
INC A ; Increment A
JNZ Back1 ; Loop till A rolls back to 00H.
MOV A, #0FEH ; A ç FEH
Back2 : MOV P1, A ; P1 ç A register
ACALL Delay ; Call a delay of 10 milliseconds
DEC A ; Decrement A
JNZ Back2 ; Loop till A reduces to 00H (outputs 01H).
SJMP Back1 ; Loop back, infinitely

Fig. 5.2.5 : Triangular waveform

! 5.3 8051 | Stepper Motor

Q. Discuss working of stepper motor. (Q. 1(B), Dec. 18, 5 Marks)

! Introduction to Stepper Motor

Stepper motors are high precision devices that can rotate


in tiny accurate steps, controlled by the program.
Applications where step wise rotation is required like
Robotic arm, Printer etc. prefer Stepper motors instead of
DC motors.
They are very easy to interface and program.
Besides, they can easily switch between clockwise and
anticlockwise motion. Fig. 5.3.1
A Stepper motor is formed by four stator magnets and one rotor magnets.

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-9 8051 Interfacing and Applications

We need to control the four stator by giving a sequence of 0s and 1s. that decides the movement of the
rotor, and hence the stepper motor on the whole.
For this we simply need to connect four lines of a Port of 8051 say P1.

! Need for a driver – ULN2003

Stepper motors are controlled by our µC 8051.


8051 however sources/sinks current around 15mA at voltage 5V.
A Stepper motor however requires much higher current and voltages to drive real world appliances. For
this purpose we use drivers.
A typical Driver like ULN2003 can provide a max current around 500mA at voltage up to 50V. We
could also use a relay driver like L293D.

! Interface

Fig. 5.3.2

! Working

Pins P1.0… P1.3 of 8051 are used to control the motor via ULN2003.
By sending values on these pins we rotate the motor in clockwise and anti-clockwise direction. The
motor is connected at the output of ULN2003.
The logic table for controlling the motor movement is given below.

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-10 8051 Interfacing and Applications

! Wave Step mode

Here we activate only one stator. This uses less power but also produces low torque in the rotor’s
movement as only one end of the magnet is pulled.
This mode is rarely used due to its low torque.

! Full Step mode

This is the most commonly used mode. Here we activate only two stators at a time. This uses more
power but also produces double the torque in the rotor’s movement as both ends of the magnet are
pulled.
The Excitation sequence for the stators is as shown :

P1.3 (D) P1.2 (C) P1.1 (B) P1.0 (A) Value

0 0 1 1 3H

0 1 1 0 6H

1 1 0 0 CH

1 0 0 1 9 H

" Please Note


! Though we are interested in only 4 lines of P1, if we connect the other four lines to ground then we can obtain these
patterns by simply rotating the number.

P1.7 P1.6 P1.5 P1.4 P1.3 P1.3 P1.3 P1.3


Value Rotate Left
(X) (X) (X) (X) (D) (D) (D) (D)

0 0 1 1 0 0 1 1 33 H

0 1 1 0 0 1 1 0 66 H

1 1 0 0 1 1 0 0 CC H

1 0 0 1 1 0 0 1 99 H

These are irrelevant Just observe these bits

! Half Step mode

This mode is used when we want better accuracy and more steps in the movement. Full step
produces 4 steps in the cycle but half step produces 8 steps.
Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture
Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-11 8051 Interfacing and Applications

Here we activate two stators, then only one stator then two stators and so on.
This allows half steps as in the rotor not only stops at every stator’s position but also stops in in-
between the stators, being pulled (or repelled) by both stators equally.
The Excitation sequence for the stators is as shown:
P1.3 (D) P1.2 (C) P1.1 (B) P1.0 (A) Value

0 0 0 1 1H
0 0 1 1 3H
0 0 1 0 2H

0 1 1 0 6H
0 1 0 0 4H
1 1 0 0 CH

1 0 0 0 8H
1 0 0 1 9H

" Please note

! In some other literature you may find the four stator lines, ABCD connected in a different way and hence the
numbers may appear different but the logic remains the same. The idea is, in one excitation we must activate one
stator, in the next we must activate the current and the next stator and repeat the process.

! Also, unlike full step, these codes cannot be derived by simply rotating one of the numbers. Hence we must first
store these codes in memory in the form of a… yes you guessed it right! A look up table at 0400H.

Org 0400H
Table DB 01H, 03H, 02H, 06H, 04H, 0CH, 08H, 09H

! 5.3.1 Program to Rotate a Stepper Motor

# Write a program to rotate the Stepper motor continuously using half step 8 sequence.
Assume look up table at 0400H …

! Algorithm

Initialise DPTR = 0400H to point to look up table


Initialise R7 = 08H as step counter of 8
Initialise R6 = 00H as index in the table
Take index into A from R6
Get excitation code from look up table into A register
Put the code into P1 from A register

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture


Microcontroller & Embedded Prog. (MU-Sem 5-IT) 5-12 8051 Interfacing and Applications

Call a delay of 1 second


Increment R6 for next index
Decrement R7 and loop till 8 counts
Now Initialise everything again and loop continuously

! Program

Again : MOV DPTR, #0400H ; Pointer to look up table


MOV R7, #08H ; Count of 8
MOV R6, #00H ; Index of 0
Back : MOV A, R0 ; Take Index into A
MOVC A, @A+DPTR ; Get excitation code from look up table into A
MOV P1, A ; Put excitation code on P1
ACALL Delay ; Refer previous chapter for a 1 second delay program
INC R6 ; Next index
DJNZ R7, Back ; Loop 8 times
SJMP Again ; Repeat the whole process to rotate the motor continuously
# Assume 1 step causes a rotation of 1.8 degrees. Rotate the stepper motor to 117 degrees.

! Use full step mode.

Calculation :

1 step = 1.8 degrees


x steps = 117 degrees.
x = (117/1.8) = 65d = 41H. This is our loop count.

! Algorithm:

Initialise R7 = 41H as loop count of 65d

Initialise A register as 33H (any one of the four excitation codes to be used in full step mode)

Put the code into P1 from A register

Call a delay of 10 milliseconds

Rotate A to form the next code

Decrement R7 and loop till 65 counts

Tech-Neo Publications...........Where Authors inspire innovation .....A SACHIN SHAH Venture

You might also like