Interfacing 8051
Interfacing 8051
UNIT-8
INTERFACING 8051
STEPPER MOTOR INTERFACING: Interfacing the Stepper motor to the 8051 is done to control of angle and direction of rotation A stepper motor is a !idel" #sed de$ice that translates electrical p#lses into mechanical mo$ement Applications As disc dri$es In dot matri% printers In ro&otics for position control T p!s o" st!pp!r #otor 1 , 'ermanent magnet (aria&le Rel#ctance 'ermanent magnet Stepper motor consists of t!o parts Rotor )shaft*+a permanent magnet Stator -s#rro#nds the rotor as sho!n in fig )a*
INTERFACING 8051 The most common steppers ha$e fo#r stator !indings that are paired !ith a center+tapped common as sho!n in fig)&* This t"pe of stepper motor is commonl" reffered to as a fo#r+phase or #nipolar stepper motor The center+tap allo!s a change of c#rrent direction in each of t!o coils !hen a !inding is gro#nded0 res#lting in a polarit" change of the stator
Fig )&*
The stepper motor shaft mo$es in a fi%ed repeata&le increment0 !hich allo!s one to mo$e it to a precise position The stator poles are determined &" the c#rrent sent thro#gh the !ire coils As the direction of the c#rrent is changed the polarit" is also changed ca#sing the re$erse motion of the rotor The stepper motor disc#ssed here has a total of 1 leads2 3 leads representing the fo#r stator !indings and , commons for the center+tapped leads As the se4#ence of po!er is applied to each stator !inding0the rotor !ill rotate There are se$eral !idel" #sed se4#ences !here each has a different degree of precision
INTERFACING 8051 Ta&le &elo! sho!s a ,+phase ) , !indings are energi5ed at a time*03+step stepping se4#ence
6e can start !ith an" of the se4#ences in the a&o$e ta&le 0once !e start !e m#st contin#e in the proper order For e%ample 0 if !e start !ith st!p$%0110& 0 !e m#st contin#e in the se4#ence of steps 3010,0703010,etc Step angle is the minim#m degree of rotation associated !ith a single step Step per re$ol#tion is the total n#m&er of steps needed to rotate one complete rotation or 710 degrees) e g0 180steps8, degrees9710* (ario#s motors ha$e different step angles Ta&le &elo! sho!s some step angles for $ario#s motors Step angle :, 18 ,0 ,5 50 :5 15 Step per re$ol#tion 500 ,00 180 133 :, 38 ,3
INTERFACING 8051
T(! "o)r st!p s!*)!nc! an' n)#+!r o" t!!t( on rotor: After completing e$er" "o)r st!ps0 the rotor mo$es onl" on! toot( pitc( In a stepper motor !ith ,00 steps per re$ol#tion0 the rotor has 50 teeth since 38509,00 steps are needed to complete one re$ol#tion The smaller the step angle0 the more teeth the rotor passes E,a#pl!: Gi$e the n#m&er of times the 3+step se4#ence m#st &e applied to a stepper motor to ma<e an 80+degree mo$e if the motor has a ,+degree step angle Sol)tion: 8For , degree step angle 8Step per re$ol#tion9 710;, 9180 88No of rotor teeth9 step per re$ol#tion;step se4#ence 9 180;39 35 8The n#m&er of times the 3+step se4#ence m#st &e applied to a stepper motor to ma<e an 80+degree mo$e9 80 degrees; 3steps8,degrees9 10 i e to mo$e the rotor 80 degrees0 !e need to send 10 consec#ti$e fo#r+steps se4#ences
-A.F STEP SE/UENCE: For finer resol#tion 0 all stepper motor allo! an 8+step s!itching se4#ence also called as half -step In the 8+step s!itching se4#ence each step is half of the normal step angle )3+step s!itching se4#ence* as sho!n in ta&le &elo!
INTERFACING 8051
00Unipolar 1!rs)s +ipolar st!pp!r #otor int!r"ac!: There are three common t"pes of stepper motor interfacing2 #ni$ersal0 #nipolar0 and &ipolar The" can &e identified &" the n#m&er of connections to the motor A #ni$ersal stepper motor has 8 connections0 #nipolar stepper motor has 1 connections0 And &ipolar stepper motor has 3 connections as sho!n in fig &elo!
The #ni$ersal stepper motor can &e config#red for all three modes 0!hile the #nipolar can &e either #nipolar or &ipolar and the &ipolar cannot &e config#red for #ni$ersal nor #nipolar mode
Int!r "acin2 )nipolar st!pp!r #otor to 8051: Controllin2 st!pp!r #otor 1ia optoisolator
INTERFACING 8051
A&o$e fig#re sho!s an interface to a #ni$ersal stepper motor #sing optoisolator !hich are !idel" #sed to isolate the stepper motor=s &ac< E/F $oltage i e to protect from damaging the digital;microcontroller s"stem The fo#r leads of the stator !inding are controlled &" fo#r &its of the 8051 port)p1 0+p1 7* Since the 8051 lac<s s#fficient c#rrent to dri$e the stepper motor !indings0 !e m#st #se a dri$er s#ch as >?N,007 to energise the stator Instead of >?N,007 !e can also #se transistor as dri$ers0as sho!n in fig#re &elo!
INTERFACING 8051
If the transistors are #sed as dri$ers0 !e m#st also #se diodes to ta<e care of ind#cti$e c#rrent generated !hen the coil is t#rned off 6here >?N,007 has an internal diode to ta<e care of &ac< E/F
3C M0TOR INTERFACING AN3 P4M A direct c#rrent)@C* motor is another !idel" #sed de$ice that translates electrical p#lses into mechanical mo$ement @ C motor ha$e onl" positi$e and negati$e leads &" connecting them to a @ C $oltage so#rce the motor mo$es in one direction A" re$ersing the polarit"0 the @Cmotor !ill mo$e in the opposite direction As sho!n in &elo! fig#res
Applications: 1& s#all "ans )s!' in #ot(!r +oar' to cool t(! cp)5 6i'ir!ctional control 6ith the help of s!itches !e can change the direction of the @C motor rotation Fig)a* sho!s the connection of an B+Aridge #sing simple s!itches All the s!itches are open0 !hich does not allo! the motor to t#rn )r#n* (eena S . /IT0 /"sore :
Fig#re &elo! sho!s the s!itch config#ration for t#rning the motor in one direction 6hen s!itches 1 and 3 are closed 0 the c#rrent is allo!ed to pass thro#gh the motor cloc<!ise 6hen s!itches , and 7 are closed 0 the c#rrent is allo!ed to pass thro#gh the motor co#ntercloc<!ise
Fig#re &elo! sho!s the in$alid config#ration C#rrent flo!s directl" to gro#nd0 creating a short circ#it 8
INTERFACING 8051
The same effect )in$alid state*occ#rs !hen s!itches 1 and 7 are closed or s!itches ,and 3 closed
P)ls! 7i't( #o')lation%P4M& The speed of the motor depends on three factors2 1* load ,* $oltage and 7*c#rrent For a gi$en fi%ed load !e can maintain a stead" speed &" #sing a method called p#lse !idth mod#lation)'6/* A" changing )mod#lating* the !idth of the p#lse applied to the @C motor !e can increase or decrease the amo#nt of po!er pro$ided to the motor0 ther&" increasing or decreasing the motor speed i e !ider the p#lse0 higher the speed Fig#re &elo! sho!s the '6/ comparisions
INTERFACING 8051
Separate po!er s#pplies to the motor and logic !ill red#ce the posi&ilit" of damage to the control circ#itr" And also allo!s the #se of high+$oltage motors The deco#pling capacitor across the motor helps to red#ce the E/I created &" the motor The 5ener diode is #sed to red#ce gate $oltage &elo! the rated ma%im#m $al#e
1*!rite a program to monitor the stat#s of the s!itch and perform the follo!ing )a* if S6910 the @C motor mo$es co#ntercloc<!ise )&* if S6900 the @C motor mo$es cloc<!ise Sol#tion2
Crg 0000h /AIN2 C?R '1 0 C?R '1 1 C?R '1 , SETA', : /CNITIR2 SETA '1 0 ENA ', :0 C?CC.6ISE C?R '1 1 SETA '1 , SE/' /CNITCR C?CC.6ISE2 SETA '1 1 C?R '1 , SE/' /CNITCR EN@
10
INTERFACING 8051
,*!rite a program to monitor the stat#s of the s!itch and perform the follo!ing )a* if p, :910 the @C motor mo$es !ith ,5F d#t" c"cle p#lse )&* if p, :900 the @C motor mo$es !ith 50F d#t" c"cle p#lse Sol#tion2
Crg 0000h /ain2 C?R '1 0 SETA ', : /CNITCR2 ENA ', :0 FIFTG'ERCENT Hif p, :91 follo! the ne%t instr#ction 0if p, :90 go to la&el fift"percent SETA '1 0 /C( R50I,5 ACA?? @E?AG C?R '1 0 /C( R50I:5 ACA?? @E?AG SE/' /CNITCR FIFTG'ERCENT2 SETA '1 0 /C( R50I50 ACA?? @E?AG C?R '1 0 /C( R50I50 ACA?? @E?AG SE/' /CNITCR @E?AG2 /C( R,0 IFF ?12 /C( R70 IFF ?,2 @ENJ R70 ?, @ENJ R,0 ?1 RET EN@
3AC INTERFACE
@igital to analog con$erters)@AC* is a de$ice !idel" #sed to con$ert digital p#lses to analog signals The first criterion for K#dging a @ACis its resol#tion0 !hich is a f#nction of the n#m&er of &inar" inp#ts R!sol)tion2 This is the n#m&er of possi&le o#tp#t le$els the @AC is designed to reprod#ce This is #s#all" stated as the n#m&er of &its it #ses0 !hich is the &ase t!o logarithm of the n#m&er of le$els For instance a 1 &it @AC is designed to reprod#ce , ),1* le$els !hile an 8 &it @AC is designed for ,51 ),8* le$els
11
INTERFACING 8051 An 8+&it @AC s#ch as @AC 0808 pro$ides ,51 discrete $oltages )or c#rrent* le$els of o#tp#t similarl" 1,+&it @AC pro$ides 30D1 discrete $oltage le$els The digital inp#t are con$erted to c)rr!nt Io#t L &" connecting a r!sistor to the Io#t pin0 !e con$ert the res#lt to 1olta2!5 i5!5 Io)t0R89o)t5 The total c#rrent pro$ided &" the Io#t pin0 is a f#nction of the &inar" n#m&er at the @o+@:
INTERFACING 8051
Inp#t $al#es for @AC for $ario#s angles is calc#lated and sho!n as in ta&le &elo! for step angle 70 degree
Angle sin 9o)t851:%50sin& 1 3AC inp)t 1al)!s 8 %1;8:1;8 sin& '!ci#al Inp#t $al#es in (!,
5 :5 D 77 10 D 77 :5 5 ,5 1: 0 1: ,5 5
80 C0 EE FF EE C0 80 30 11 0 11 30 80
INTERFACING 8051
I incl#deNreg51 hO (oid main) * >nsigned char co#ntH P 6hile)1* P For )co#nt90H co#ntT90%ffH co#ntMM* '09co#ntH S P For)co#nt90%ffH co#ntO0Hco#nt++* '09co#ntH S S
13
INTERFACING 8051
Fig#re sho!s the generation of c#rrent reference setting Iref9,mA L&" #sing the standard 5$ po!er s#ppl" L 1< or 1 5< ohm resistors Con$ert this c#rrent to $oltage and monitor the o#tp#t on scope Ideall" !e connect the o#tp#t pin Io#t to a resistor A#t this resistor affect the o#tp#t $oltage For this reason0 Iref c#rrent o#tp#t is isolat!' &" connecting it to an op+amp s#ch as :31 !ith Rf95<ohm
15
INTERFACING 8051
>E?6OAR3 INTERFACING: .e"&oard L?C@s are the most !idel" #sed inp#t;o#tp#t de$ices of the 8051 .e"&oards are organi5ed in a matri% of ro!s and col#mns The 8051 C'> accesses &oth ro!s and col#mns thro#gh , 8+&it ports0 an 888 matri% of <e"s can &e connected to a controller fig#re &elo! sho!s a 383 matri% connected to t!o ports
11
INTERFACING 8051
6hen a <e" is pressed0 a ro! L col#mn ma<e a contact0 other!ise there is no connection &et!een them The ro!s are connected to an o#tp#t port and The col#mns are connected to an inp#t port If no <e" is pressed reading the inp#t port !ill "ield 1s for all col#mns since the" are all connected to (CC If all the ro!s are gro#nded and a <e" is pressed 0one of the col#mn !ill ha$e 0 since the <e" pressed pro$ides the path to gro#nd It is the f#nction of the microcontroller to scan the <e"&oard contin#o#sl" to detect and identif" the <e" pressed i5! + 2ro)n'in2 t(! ro7s an' r!a'in2 t(! col)#ns If the data read from the col#mns is @7+@0911110 then no <e" is pressed0 If the data read from the col#mns is @7+@0911010then the <e" in @1 col#mn is pressed Cnce the <e" pressed is detected the microcontroller !ill go thro#gh the process of identif"ing the <e" Starting !ith the top ro! 0i e gro#nding @0 onl" L reads the col#mn If no <e" is pressed in that ro! then the data read is all 1s L it gro#nds the ne%t ro! i0e @10@,0@7 respecti$el" L reads the col#mn0 and chec< for an" 5ero This process contin#es #ntil the ro! is identified for the <e" pressed and to find o#t !hich col#mn the <e" is pressed
Fi2)r! + pro1i'!s t(! "lo7c(art "or scannin2 an' i'!nti" in2 t(! pr!ss!' @! 5
1:
INTERFACING 8051 EUA/'?E2 From Fig 0identif" the ro! and col#mn of the pressed <e" for each of the follo!ing a*@7+@091110 for the ro!0 @7+@091011 for the col#mn Sol#tion The ro! &elongs to @0 and the col#mn &elongs to @,H therefore0 <e" pressed is n)#+!r ; &* @7+@091101 for the ro!0 @7+@090111 for the col#mn Sol#tion The ro! &elongs to @1 and the col#mn &elongs to @7H therefore0 <e" pressed is n)#+!r A c* @7+@091011 for the ro!0 @7+@090111 for the col#mn Sol#tion The ro! &elongs to @, and the col#mn &elongs to @7H therefore0 <e" pressed is l!tt!r 6 d* @7+@090111for the ro!0 @7+@091110 for the col#mn Sol#tion The ro! &elongs to @7 and the col#mn &elongs to @0H therefore0 <e" pressed is l!tt!r C
18
INTERFACING 8051
1D
INTERFACING 8051
.C3 INTERFACING: In recent "ears the ?C@ is finding !idespread #se replacing ?E@s )se$en segment*0 d#e to the follo!ing reasons2 1 The declining prices of ?C@s , The a&ilit" to displa" n#m&ers0 characters0 and graphics 7 Ease of programming for characters0 and graphics The ?C@ descri&ed in this chapter has 13 pins The f#nction of each pin is gi$en in ta&le &elo!
,0
INTERFACING 8051
9CCB 9SS C 9EE: %pin 1B;C$& (CC0 (SS pro$ide M5( and gro#nd0 respecti$el" (EE is #sed for controlling lcd contrast RS- R!2ist!r s!l!ct %pin D&: If RS80B the instr#ction command code register is selected !hich Allo!s the #ser to send a command s#ch as clear displa"0 c#rser at home0 etc ta&le 1 &elo! lists the instr#ction command codes If RS81B the data register is selected !hich Allo!s the #ser to send data to &e displa"ed on the ?C@ To displa" letters and n#m&ers0 !e send ASCII codes for the letters A+J 0a+50 and n#m&ers 0+D to 8+&it data pins )@0+@:* !hile ma<ing RS81
R=4- r!a'=7rit!%pin5&: R=481 7(!n r!a'in20 fig c sho!s ?C@ timing to read)?+B for E pin* R=480 7(!n 7ritin2 fig d sho!s ?C@ timing to !rite)B+? for E pin* E-!na+l!%pin <&: This pin is #sed to latch the information presented to its data pins A (i2(-to-lo7%--.& p)ls! m#st &e applied to this pin in order for the ?C@ to latch in the data present at the data pins As sho!n in fig c L d 30-3A%pin Ato 1D&: The 8+&it data pins @0+@: are #sed to send information to the ?C@ or read the contents of the ?C@s internal registers Fig 1, , sho!s the 8051 and ?C@ interfacing
INTERFACING 8051
fig d sho!s ?C@ timing to !rite)B+? for E pin* Ta+l! 1 : .C3 co##an' co'!s2
,,
INTERFACING 8051
,7