You are on page 1of 27

Using DataSockets to Control

a Stepper Motor Over the Network


SamerElHajMahmoud
ElectronicsEngineeringTechnologyProgram
TexasA&MUniversity

Instructors Portion
Summary
This lab aims at providing the students with hands on experience in
remotely controlling and monitoring a stepper motor over the network
usingDataSocketsprogrammingandthedigitaloutputofthe6024Edata
acquisitioncard.Thelabassumesthatthestudentshavepriorexposureto
LabVIEW, and that they know the basics of writing and debugging
LabVIEWVIs(VirtualInstrument).Theexperimentwillteachthemhow
toapplytheirLabVIEWknowledgetocontrolasteppermotorthrougha
client/server network program. The experiment also covers the basic
hardware to buffer the digital output of the card along with the basic
conceptsofDataSocketsandtheDataSocketsserver.Thestudentsshould
study stepper motor operation andconcepts (step mode, poles, wiring)
beforecomingtothelab.

Theobjectivesforthisexperimentincludeexposingstudentstothebasic
theorybehindsteppermotors,teachingtheconceptsofdigitalinterface
anddatasocketsnetworkcontrol,andhavingthestudentsimprovetheir
LabVIEW skills by developing a VI to control a stepper motor. The
instructions provided in the students section describe a stepbystep
approach to write the basic structure of the VI. The rest of the
implementation is left to the students. The VI provided is a sample
implementation,andisintendedfortheinstructorsreferenceuseandnot
for the students. The diagram can be password protected in case the
students want to look at the front panel and see how the VI they are
writing shouldbehave. Beforeperforming this lab, the students should
have finished a preliminary experiment, Digital Control of a Stepper
Motor,whichisincludedasanappendixattheendofthisexperiment.

UsingDataSocketstoControlaStepperMotorovertheNetwork
1
Uses
This experiment applies to general instrumentation and electronics
systems interfacing courses in electrical engineering or engineering
technology programs. The experiment can also be useful in basic
LabVIEW courses, teaching the concepts of DataSockets, Remote
Control, and Digital Input/Output through data acquisition cards, in
addition to other LabVIEW techniques such as the use of the Logical
SelectandArraycomponents.

Equipment List
2PCsrunningMSWindows
(visithttp://www.ni.com/labview/lv_sysreq.htmfor
requirementsspecifictoyouroperatingsystem)

LabVIEWFullDevelopmentSystemversion6iorlater.

6024EDAQfromNationalInstruments(partnumber322072C01)

CB50LPI/OConnectorBlockfromNationalInstruments(part
number77710101)

NBIRibbonCablefromNationalInstruments(partnumber180624
10)

LM18293FourChannelPushPullDriverfromNational
Semiconductor(http://www.national.com/pf/LM/LM18293.html
forthedatasheetofthischip).Note:Incaseitisnotpossibletoobtain
thisIC,anyequivalentcurrentbuffercanwork.Asimplesolution
wouldbetouse4NPNBJTs(1N2222)inanopencollectormodeto
drivethesteppermotorlines.

A4coilSteppermotor,with7.5stepresoultion(48internalpoles),
suchaspartnumber26M048BfromThomsonAirpaxMechatronics:
http://www.allegromicro.com/techpub2/airpax/smh15.p
df

Prototypeboardandjumperwires.

Setup
Follow the steps listed below to prepare the workstations for this
experiment. The instructions assume you are using the equipment list
shownpreviously.

UsingDataSocketstoControlaStepperMotorovertheNetwork
2
Note: Most of the manuals that are referred to ship with National
Instrumentshardwareandsoftware.Ifyoucantfindyourhardcopyofthe
manuals, youcangetthem online at http://www.ni.com/manuals.
Ifyou encounter problems during setup, contact technical support at
http://www.ni.com/support.

Before the Day of the Lab


1. InstallLabVIEWonbothPCs(seetheLabVIEWReleaseNotesfor
yourversionofLabVIEW).

2. Installyour6024Eboard(seethe6024EUserManual,oronlineat:
http://www.ni.com/pdf/manuals/322072c.pdf).

3. Connectthecabletothe6024EcardandtotheI/Oconnectorblock.

On the Day of the Lab


1. Powerupbothcomputers.

2. StartLabVIEW.

References
NIswebsite:http://www.ni.com

LM18293datasheet:
http://www.national.com/ads-cgi/viewer.pl/ds/LM/LM18293.pdf

ThomsonAirpaxStepperMotorHandbook:
http://www.allegromicro.com/techpub2/airpax/airpax.htm

HowStruffWorkswebsite:http://www.howstuffworks.com/
D. Trhomson, and P. Sweat. Basic Use of DataSockets
in LabVIEW, July 2001. Online at:
http://www.ses-co.com/DataSockets.doc

UsingDataSocketstoControlaStepperMotorovertheNetwork
3
Students Portion
Introduction
Inthisexperiment,youwillwriteLabVIEWVIstoremotelycontrola
steppermotorusingDataSocketsProgrammingandthedigitaloutputof
the6024EDataAcquisitionCard(DAQ).YouwillwritetwoVIs,aclient
andaserver.Inaddition,youwillhavetousetheDataSocketsServer.
Thislabrequiresbackgroundinsteppermotorbasictheory,includingthe
concepts ofpoles andhalf/full steps controlcodes.Theseconcepts are
summarized in the Theory section of this experiment. In addition to
writingtheVI,youarerequiredtobuildaninterfacecircuittodrivethe
motorfromtheDAQdigitaloutputs.

Objective
TolearnhowtouseLabVIEWforDigitalI/OthroughaDAQ
card.

Tolearnaboutsteppermotorbasicsandhowtocontrolastepper
motorusingthedigitaloutputofaDAQinfull/halfstepmodeand
clockwise/counterclockwisedirection,whilecontrollingthespeedof
rotationanddisplayingthecurrentposition.

To learn the basics of network programming in LabVIEW and


DataSockets.

Theory
1.StepperMotor
Forsteppermotortheory,refertothetheorysectionoftheexperiment
DigitalControlofaStepperMotorthatisavailableintheappendix.

2.DataSockets
DataSockets is a network programming technology to simplify data
exchangebetweencomputersanddistributedI/Odevices.Thistechnique
canbeusedtopassdataovertheInternetorLocalAreaNetworks(LANs),
withoutthecomplexityoflowlevelTCPprogramming.Thedatacanbe
usedforremotemonitoringandcontrolofprocessesthatcanbephysically
locatedfarawayfromtheoperator.DataSocketsalsomakessharingof
scientificandengineeringdatabetweensoftwareapplicationsandbetween
networkedcomputersaseasyasreadingandwritingdatatofiles.

UsingDataSocketstoControlaStepperMotorovertheNetwork
4
ThemainprotocolthatisusedwithDataSocketsiscalledDataSockets
TransferProtocol(DSTP).ConnectionsmadewithstandardURLsofthe
followingformat:

dstp://machine_name/tag_name

Figure 4 illustrates the client/server model in DataSockets network


programming.ThetermsClientandServerrefertothetwoLabVIEW
programs(orVIs)thatyouwillwriteinthisexperiment.EachVIwillrun
onadifferentmachineonthenetwork,ortheycanbothrunlocallyonthe
same machine. The operator usually controls the client side, while the
actualmotorisconnectedtotheDAQontheserverhost.
DataSockets
Server(DSS)
Process
(StepperMotor)

Client LAN/Internet Server

Figure4Client/ServernetworkdiagramwithDataSockets
TheclientVIhasaGUIthatcontainsallthenecessaryinputtotheprocess
(orcontrols)andthefeedbackoutputfromtheprocess(theindicators).
Theoperatorusestheclienttocontroltheremoteprocessandmonitorthe
feedbackmeasurements.Allwhattheclientdoesistopackagetheinputs
fromthecontrols,send(orwrite)themtotheserver,andreadbackfrom
theserverthefeedback,unbundlethemanddisplaythemontheindicators.

TheserverVIdoesntcontainanycontrols.Itreadsfromthenetworkthe
valuessenttoitfromtheclient,unbundlethemandusethemastheinputs
tothecontrolprogramthatdrivestheprocess.Italsocollectsthefeedback
measurementsfromtheprocessandbundlethemandwritethembackto
theclienttobedisplayed.

EachDSTPconnectionisunidirectional;itsupportssendingthedatafrom
one of the hosts to the other. This means we will need two DSTP
connectionsforaclosedloopcommunicationbetweentheclientandthe
serverprograms.Oneconnectionwillreadfromtheclientandwritetothe
server,andtheotherwillreadfromtheserverandwritetotheclient.
WhencreatingtheDSTPconnections,itisnecessarytoassignanewtag
toeachconnection.

ForDataSocketsconnectionstobeestablishedsuccessfully,aDataSockets
Server(DSS)mustberunningonthenetwork.Allcommunicationthrough
theDSTPbetweentheclientandtheserverprogramsarepassedthrough
theDataSocketsServer.TheDataSocketsServercanberunningoneither
theclientortheservermachines,butitcanalsoberunningonathird

UsingDataSocketstoControlaStepperMotorovertheNetwork
5
independentmachine.MostprogrammersprefertoruntheDataSockets
ServeronthesamemachinethathoststheserverVI.Theimportantthing
torememberisthatallDSTPconnectionsmustusetheIPaddressofthe
DataSockets Server (DSS) on both the client and server sides. This is
explainedinthefollowingtable:

Firstconnection SecondConnection
dstp://DSS_IP/tag1 dstp://DSS_IP/tag2
ClientSide
(ClientWrite) (ClientRead)
dstp://DSS_IP/tag1 dstp://DSS_IP/tag2
ServerSide
(ServerRead) (ServerWrite)

TheDSScanbereferredtobyitsIPaddressorDNSname.Inaddition,if
the DSS is running locally on the client or the server sides, then the
following IP address can be used on that side: 127.0.0.1, which is
equivalenttotheDNSname:localhost.

TheDataSocketsoperationcanbeperformedinLabVIEWusingtwomain
VIs:DataSocketsReadandDataSocketsWrite.BothVIsneedtheaddress
ofthe DataSockets tobespecified as aURL(as mentioned above)of
stringtype.Inaddition,theDataSocketsReadrequiresatypebundled
input to be able to cast the unbundled message components to their
originaltypes.Forexample,iftheclientsentabundleconsistingofan
integer,astringandadouble,thentheserverReadmustbeconnectedtoa
bundleofinteger,stringanddoubleconstantsinthatspecifiedtype.The
constants can simply be 0 or empty strings. They should be bundled
togetherandconnectedtothetypeinputoftheServerReadsubVI.This
way,whenyouunbundledtheoutputoftheRead(orthedata)theVI
willcasteachofthemtoitscorrespondingtype.

Starting with LabVIEW version 6.1, a new and improved method for
remotecontrolofaVIisavailable.Usingasimpleenablefeature,youcan
allowyourVItobecompletelycontrolledandviewedonline(withany
webbrowser)withoutaddinganydatasocketscodetoyourprogram.This
requiresaserver(providedwithLabVIEW6.1)andaLabVIEWclient
browserplugin,availablefromNIswebsite.Thismethodisnotgoingot
beusedinthisexperiment.

Finally,tobeabletoconnectfromonemachinetotheDataSocketsServer
onanother,youneedtosettheDataSocketsServerManageraccessrights
to every host. For more information on DataSockets, refer to the
examplesprovidedwithyourLabVIEWthatarealsoavailableinthehelp
systemoryoucanrefertothisusefuldocument:

http://www.sesco.com/DataSockets.doc

UsingDataSocketstoControlaStepperMotorovertheNetwork
6
Pre-Lab Preparation
Readthisexperimentbeforecomingtothelab.Youshouldunderstandthe
operationofthesteppermotor,andknowthedifferencebetweenfullstep
andhalfstepmodes.Youshouldalsounderstandthedifferencebetween
theclientandtheserverprograms,andtheuseoftheDataSocketsServer.

Bringthefollowingtolabwithyou:
Thisexperiment.
Yourlabnotebookandpencil.

2virusfreeformatted3.5inchfloppydisks(alwaysmakeabackup
copyofyourcodeontheseconddisk).

Answerthefollowingquestionsinthedatasheetprovidedattheendofthis
experimentbeforecomingtothelab.Remembertoincludetheseanswers
inyourlabreport.

1. Whatisthemaindifferencebetweentheclientandserverprogramsin
thisexperiment.

2. WhataretheVIsusedforDataSocketscommunication.

3. WhatistheDataSocketsServer?Howmanycopiesofitshouldbe
runninginthisexperimentandwhere?

4. IftheDataSocketserverisrunningonthemachinewithIPaddress
192.196.0.1,andtheclientmachinehastheaddressof192.196.0.2
whiletheservermachinehasIPaddres192.196.0.3.Howwouldyou
writethedstpURLsforthefollowingsituations:

- ClientDataSocketsRead
- ClientDataSocketsWrite
- ServerDataSocketsRead
- ServerDataSocketsWrite

5. IftheDataSocketsServerisrunningonthesamemachineastheserver
program,howwouldyouranswersforquestion4differ?(Hint:usethe
localhostDNSname).

6. Whatisthelogic1outputvoltageonthe6024Ecard?Whatisthe
logic0outputvoltage?Whatisthelowestinputvoltagetoproducea
logic 1 input? And the highest input voltage to produce a logic 0
input?CompareyouranswerstoTTLandCMOSstandards.

7. Howdoyouproduceatristateoutput?Whatisthevoltagelevel?

UsingDataSocketstoControlaStepperMotorovertheNetwork
7
8. Howfastcanasingledigitaloutputonthe6024bechanged?

9. WhichVIisthemostsuitablefortheDigitalControlofthestepper
motor(FunctionsMenuDataAcquisitionDigitalI/O)?

10. HowwillyoustorethelastpositionofthemotorintheLabVIEW VI?


Howwillyouinitializethisvalue?

11. WhatisthedifferencebetweenaDigitalPortandaDigitalLineinthe
DigitalI/OVIs?

12. If the consecutive positions of a Stepper Motor in the clockwise


directionsarenumbered0,1,2,3.7,obtainthebinarycodegivento
thesteppermotorcorrespondingtoeachposition.

Workstation Details
Yourworkstationshouldhavethefollowingitems:

TwocomputerswithNationalInstrumentsLabVIEWsoftwarean
connectedoveraLocalAreaNetwork(LAN)

NationalInstrumentsDAQboard(insideoneofthecomputers)

NationalInstrumentsDAQboardterminalblock

Steppermotor(48internalpoleswith4coilsand5terminals)

LM18293pushpullquadlinedriver(oranalternativecurrentdriver
hardware).

Prototypeboardandjumperwires

UsingDataSocketstoControlaStepperMotorovertheNetwork
8
Lab Procedure
1. Beforestartingthisexperiment,youneedtocompleteapreliminary
experiment,DigitalControlofaStepperMotor,thatisavailablein
theappendix.TheVIsthatyouaregoingtowriteinthatexperiment
willbeusedinthecomingstepsofthislab.

2. StartbywritingtheclientsideVI.StartanewVIinLabVIEWonthe
machine that will run the client (this doesnt need a DAQ to be
installedinsideit).Youshouldthenaddthefollowingcontrolsand
indicatorstothefrontpanel.YoucancopyandpastethemfromtheVI
ofthepreliminaryexperiment.Foradescriptionoftheusageofeach
item,refertothepreliminaryexperiment.

a. HalfStepping/FullSteppingModeSwitch.

b. Clockwise/CounterClockwiseRotationSwitch.

c. SpeedofRotationDigitalControl.

d. NumberofStepsDigitalControl.

e. PowerSwitch.

f. CurrentPositionindicator.

g. CurrentOutputCode.

h. ReadURLInputString:Thisiswhereyouwilltypethe
DataSocketsURLfortheclientread.

i. WriteURLInputString:Thisiswhereyouwilltypethe
DataSocketsURLfortheclientwrite.

2.Afteraddingthosecontrols,startwiringtheVIdiagramoftheclient
program.YourcodewillneedthefollowingVIs:

a. Aninfinitewhileloop,whichwillwraptheentireclientprogram.

b. ADataSocketsReadandaDataSocketswriteVIs.Youwillneed
toconnecttheURLinputofbothofthemtothecorresponding
inputstring(readorwrite)onthefrontpanel.

c. TwobundleandoneunbundleVIs.OneofthebundleVIswillbe
usedtobundletogetherthecontrolstoformtheinputs(ordata)of
the DataSockets Write, which will be the stepping mode, the
rotationdirection,thespeedofrotation,thenumberofstepsand
thepowerswitch.Theunbundlewillbeusedattheoutput(data)of

UsingDataSocketstoControlaStepperMotorovertheNetwork
9
the Read DataSockets VI to separate the values read from the
networkandconnectthemtotheircorrespondingindicators.These
will be the current position indicator and current output code.
Finally,thelastbundleisgoingtobeusedtocastthetypesofthe
dataoutputofDataSocketsReadVI.Itshouldbeconnectedtothe
type(Variant)inputofDataSocketsRead.Thetypesthatyou
must bundle should correspond to the types of the data items
unbundledattheoutputofDataSocketsRead,i.e.TF(forstepping
mode),TF(forrotationdirection),U32(forspeedofrotation),etc..

3.Next,youwillstartwritingtheserverprogramthatwillrunonthe
secondmachine, whichhastheDAQ cardinstalled. Thisprogram is
essentiallythesameonethatwascreatedinthepreliminaryexperiment
butwithaddeddatasocketsfunctionality.Thefrontpaneloftheserver
programshouldcontainthefollowingcontrolsandindicators.Forthe
firsttwoitems,refertothepreliminaryexperimentforanexplanationof
eachitem.

a. CurrentPositionindicator.

b. CurrentOutputCode

c. Read URL Input String: This is where you will type the
DataSocketsURLfortheserverread.

d. Write URL Input String: This is where you will type the
DataSocketsURLfortheserverwrite.

4. Start wiring the server program VI diagrams with the controls and
indicatorstoimplementthefunctionalityofthesteppermotorcontrol.
The best way to do this is to start with the code written in the
preliminaryexperiment,anddothefollowingchangestoit

a. Deleteallcontrolsfromthefrontpanel,onlyleavingthecurrent
positionindicatorandcurrentoutputcycle.
b. ChangethemainForLoopintoawhileloop.Theloopstops
whenthecurrentiterationisgreaterthanorequalthenumberof
iterationsthatwillbereceivedfromdatasocketsread(fromthe
client).
c. AddoneDataSocketsReadandoneDataSocketswriteVIs.You
will need to connect the URL input of both of them to the
correspondinginputstring(readorwrite)onthefrontpanel.
d. AddtwobundleandoneunbundleVIs.Thesearegoingtobe
usedinawaysimilartothatoftheclientprogram.Youwillneed
themtocollecttogetherthedatatobesenttotheclient(server

UsingDataSocketstoControlaStepperMotorovertheNetwork
10
write)andtoseparatethedatareadfromtheclient.Makesure
thatthedatayouwriteintheserverisinthesameorderyouread
intheclient,andviceversa.
e. Connect thebundletotheindicators: currentoutputcodeand
current position indicator (in the same order specified in the
client). Connect the output on the bundle to the DataSocket
write.
f. ConnecttheoutputoftheDataSocketreadtotheunbundledVI.
Theoutputsoftheunbundledgotosteppingmode,therotation
direction, the speed of rotation, the number of steps and the
power switch (in the same order specified in the client). The
otherbundleisgoingtobeusedtocastthetypesofthedata
outputofDataSocketsReadVI.Itshouldbeconnectedtothe
type(Variant)inputofDataSocketsRead.Thetypesthatyou
mustbundleshouldcorrespondtothetypes ofthedataitems
unbundledattheoutputofDataSocketsRead
5.ThesearethebasicVIsthatyouwillneedtohaveworkingclientand
serverprograms.YouwillstillneedmoreVIsintheserverprogramto
controlthespeedofrotation(millisecondswait)andtoshowthecurrent
motorposition.Rememberthatonewholerotationis360degrees,and
thatthemotorgoes3.75degreesforeachhalfstepandtwiceasmuchfor
fullsteps.Ifyouhaveanyquestionsaboutwritingtheremainingcode,
askyourlabinstructor.
6.Afterfinishingyourcodesaveittothefloppydisks.Then,connectthe
DAQ digital output pins with the motor and the current driver IC.
FollowtheconnectionsinthediagraminFigure5.
7.Next,youneedtoconfigureandruntheDataSocketsserver.First,run
theDataSocketsServerManagerfromtheStartmenu(StartPrograms
National Instruments DataSockets DataSockets Server
Manager). Set permissions for all groups to everyhost. Then, run
DataSocketsServer.
8.Runyourclientandserverprogramsonthecorrespondingmachines.
You need to set the correct URLs for client and server read/write
depending on the address of the machine running the DataSockets
Server.Makesurethetagforclientreadandserverwriteareidentical,
andthesameforclientwriteandserverread.Refertothetheorysection
formoreinformationonthis.Ifyouhaveanyquestions,askyourlab
instructor.
9.Testyourcodeandconnectionsbymovingthemotorasfollows:
Fullstepclockwise
Fullstepcounterclockwise

UsingDataSocketstoControlaStepperMotorovertheNetwork
11
Halfstepclockwise
Halfstepcounterclockwise
Alltheabovecombinationswithvaryingspeed
Lossoftorqueobservationwhenusinghalfstepvs.fullstep.
Notedowntheangleofrotation(thecurrentposition)whileyouare
experimenting with the possible combinations above. If you are
having problems controlling the motor over the network, or if a
networkisunavailable, youmaytrytorunboththeclientandthe
serveralongwiththeDataSocketsServeronthesamemachine.Ask
yourinstructorforhelp.

Lab Report
Yourreportmustbetypedandofprofessionalquality.Youshouldinclude
thefollowinginyourreport:

1. Allschematics,whichmustbecomputergenerated.Components
must be labeled with circuit references and values. The
schematics must be fully compliant with standard engineering
practicesforcircuitdepiction.

2. SnapshotsofthefrontpanelandblockdiagramsofallVIsand
SubVIsthatyouwroteorused.

3. ATheorysectiondescribingthetheorybehindtheconceptsused
inthislab.

4. AnimplementationsectiondescribingthedetailsofyourVIcode
andthelogicflow.

5. Thetestresultsandobservations.

6. TheanswerstothePrelabquestionsintheprovideddatasheet.

7. SelectedsectionsofthedatasheetofthePCI1200,thestepper
motorand/ortheLM18293.

UsingDataSocketstoControlaStepperMotorovertheNetwork
12
Data Sheet
1.Answer:.

2.Answer:.

3.Answer:.

4.Answer:.

5.Answer:.

6.Answer:.

7.Answer:.

8.Answer:.

9.Answer:.

UsingDataSocketstoControlaStepperMotorovertheNetwork
13
10.Answer:

Position A1 A2 B1 B2
0
1
2
3
4
5
6
7

UsingDataSocketstoControlaStepperMotorovertheNetwork
14
APPENDIX
Digital Control of a Stepper Motor
SamerElHajMahmoud
ElectronicsEngineeringTechnologyProgram
TexasA&MUniversity

Instructors Portion
Summary
Thislabprovidesthestudentswithhandonexperienceincontrollinga
steppermotorusingthedigitaloutputofthe6024Edataacquisitioncard.
TheLabassumesthatthestudentshavepriorexposuretoLabVIEW,and
thattheyknowthebasicsofwritinganddebuggingLabVIEWVI(Virtual
Instrument) code. The experiment will teach them how to apply their
LabVIEW knowledge to control a stepper motor. The experiment also
coversthebasichardwaretobufferthedigitaloutputofthecard.The
studentsshouldstudysteppermotoroperationandconcepts(stepmode,
poles,wiring)beforecomingtothelab.

Theobjectivesforthisexperimentincludeexposingstudentstothebasic
theorybehindsteppermotors,teachingtheconceptsofdigitalinterface,
andhavingthestudentsimprovetheirLabVIEWskillsbydevelopingaVI
to control a stepper motor. The instructions provided in the students
sectiondescribeastepbystepapproachtowritethebasicstructureofthe
VI.Therestoftheimplementationislefttothestudents.TheVIprovided
isasampleimplementation,andisintendedfortheinstructorsreference
useand not forthestudents.Thediagramcanbepasswordprotectedin
casethestudentswanttolookatthefrontpanelandseehowtheVIthey
arewritingshouldbehave.

Uses
This experiment applies to general instrumentation and electronics
systems interfacing courses in electrical engineering or engineering
technology programs. The experiment can also be useful in basic
LabVIEWcourses,teachingtheconceptsofDigitalInput/Outputthrough

UsingDataSocketstoControlaStepperMotorovertheNetwork
15
dataacquisitioncards,inadditiontootherLabVIEWtechniquessuchas
theuseoftheLogicalSelectandArraycomponents.

Equipment List
PCrunningWindows,Macintosh,Linux,Sun,orHPUX
(visithttp://www.ni.com/labview/lv_sysreq.htmforrequirementsspecifictoyour
operatingsystem)

LabVIEWFullDevelopmentSystem

6024EDAQfromNationalInstruments(partnumber322072C01)

CB50LPI/OConnectorBlockfromNationalInstruments(partnumber77710101)

NBIRibbonCablefromNationalInstruments(partnumber18062410)

LM18293FourChannelPushPullDriverfromNationalSemiconductor
(http://www.national.com/pf/LM/LM18293.htmlforthedatasheetofthischip).Note:In
caseitisnotpossibletoobtainthisIC,anyequivalentcurrentbuffercanwork.Asimple
solutionwouldbetouse4NPNBJTs(1N2222)inanopencollectormodetodrivethe
steppermotorlines.

A4coilSteppermotor,with7.5stepresoultion(48internalpoles),suchaspartnumber
26M048BfromThomsonAirpaxMechatronics:
http://www.allegromicro.com/techpub2/airpax/smh15.pdf

Prototypeboardandjumperwires.

Setup
Follow the steps listed below to prepare the workstations for this
experiment. The instructions assume you are using the equipment list
shownpreviously.

Note: Most of the manuals that are referred to ship with National
Instrumentshardwareandsoftware.Ifyoucantfindyourhardcopyofthe
manuals, youcangetthem online at http://www.ni.com/manuals.
Ifyou encounter problems during setup, contact technical support at
http://www.ni.com/support.

Before the Day of the Lab


3. InstallLabVIEW(seetheLabVIEWReleaseNotesforyourversionof
LabVIEW).

4. Installyour6024Eboard(seethe6024EUserManual,oronlineat:
http://www.ni.com/pdf/manuals/322072c.pdf).

UsingDataSocketstoControlaStepperMotorovertheNetwork
16
5. Connectthecabletothe6024EcardandtotheI/Oconnectorblock.

On the Day of the Lab


1. Powerupthecomputer.

2. StartLabVIEW.

References
NIswebsite:http://www.ni.com

LM18293datasheet:
http://www.national.com/ads-cgi/viewer.pl/ds/LM/LM18293.pdf

ThomsonAirpaxStepperMotorHandbook:
http://www.allegromicro.com/techpub2/airpax/airpax.htm

HowStuffWorkswebsite:http://www.howstuffworks.com/

UsingDataSocketstoControlaStepperMotorovertheNetwork
17
Students Portion
Introduction
Inthisexperiment,youwillwriteaLabVIEWVItocontrolastepper
motorusingthedigitaloutputofthe6024EDataAcquisitionCard(DAQ).
Thislabrequiresbackgroundinsteppermotorbasictheory,includingthe
concepts ofpoles andhalf/full steps controlcodes.Theseconcepts are
summarized in the Theory section of this experiment. In addition to
writingtheVI,youarerequiredtobuildaninterfacecircuittodrivethe
motorfromtheDAQdigitaloutputs.

Objective
TolearnhowtouseLabVIEWforDigitalI/OthroughaDAQ
card.

Tolearnaboutsteppermotorbasicsandhowtocontrolastepper
motorusingthedigitaloutputofaDAQinfull/halfstepmodeand
clockwise/counterclockwisedirection,whilecontrollingthespeedof
rotationanddisplayingthecurrentposition.

Theory
Amotorisanelectromagneticrotatingmachinewherecurrentflowina
coilaroundthepolesinducesanelectromotiveforcethatattractsorrepels
arotatingpartinthecenterofthemotor.DCmotorsconsistofa rotor,
whichisthecenterpartandastator,whichistheouterblockasinFigure
1. Toallowtherotortoturnwithouttwistingthewires,theendsofthe
wireloopareconnectedtoasetofcontactscalledthecommutator,which
rubsagainstasetofconductorscalledthe brushes.Steppermotorsare
verydifferentfromDCmotorsinthewaytheyarephysicallycomposed
andused.UnlikeDCmotors,whichmaybecomposedoftwolargestator
magnets,oneoneachsideoftherotor,steppermotorsarecomposedof
many ferrite poles surrounding a permanently magnetized stator core.
Figure1showsthetwobasicmodelsofDCandsteppermotors.
AsillustratedinFigure1,eachpolewithinthesteppermotoriswoundby
athinwire.Whenanyoneofthesewiresisenergizedbycurrentpassing
through it, a magnetic field is created across the ferrite material. This
therebyinducesamagneticNorthandamagneticSouthonthepole.
Amagnetizedstatorpolewillattractamagnetizedportionoftherotor
withtheoppositepolarity.Byusingaspecificcombinationofenergized
poles,therotorcanbeheldinplacebythemagnetism,oritcanbemade

UsingDataSocketstoControlaStepperMotorovertheNetwork
18
torotatebyenergizingadjacentpolesanddeenergizingthecurrentones

sothattherotoristhenattractedtotheadjacentsourceofmagnetism.
Figure1ComparingaDCmotor(left)toaStepperMotor(right)

(Source:http://www.howstuffworks.com/motor1.htm)

ThesteppermotorshowninFigure1has4internalferritepoles,butpairs
ofpolesareconnectedtogethertoformonecoil.Themotorwewillusein
thislabhas48internalferritepoles,buttheyareconnectedtoformfour
coils.Eachofthefourcoilsformsoneterminalofthemotor.Inaddition,
thereisafifthterminalthatcorrespondstoacommonlinewithallcoils.
Thiscommonterminalcanbeusedasthecommonground(oracommon
source)forthemotor.Forafourcoilmotor,afourbitcodesequenceis
neededtoenergizetheappropriatepolesatanyonetime.Thesequence
neededtomaketherotorturncanbedoneineitherfullsteporhalf
step increments. The difference between these two modes is that the
applicationofsomeofthecodesisomitted.Thiscanbeseeninthetables
inFigure2.Boththespeedanddirectionmaybechangedatanyinstant
byapplyingtheappropriatecodesatthesteppermotorssignallines.

Figure2StepperMotorswitchingsequence

UsingDataSocketstoControlaStepperMotorovertheNetwork
19
(Source:http://www.allegromicro.com/techpub2/airpax/smh29.pdf)

The angular rotation of the rotor is half the distance when halfstep
codesareusedthanwhenfullstepcodesareused.Thismeansthatit
takeshalfasmanyfullstepcodestomaketherotormakeonecomplete
turncomparedtousinghalfsteps.Thisalsomeansthatafinerangular
increment is possible when using halfstep codes. Depending on the
application,thismaybeanadvantage. Intheexamplegiven,therotor
shifts45degreesbetweentheapplicationsoftwohalfstepcodes,whileit
shifts 90 degreesbetweentheapplicationsoftwofullstepcodes. The
morepolesamotorhas,thesmallertherotationalincrementsonbothhalf
and full steps. On the other hand, this also means that more code
sequencesareneededtomakeonecompleteturn. Thereareadvantages
anddisadvantagestohavingasteppermotorwithanNnumberofpoles.
Thetradeoffisrotationalspeedversusangularresolution.Thefollowing
formuladefinesangularresolutionofasteppermotor.

360 Degrees
Angular Resolution
2 number of internal poles

Forthemotorusedinthislab,thenumberofinternalpolesis48,sothe
360
minimumangularresolutionwouldbe: 3.75 .
2 48
Thisresolutionisforhalfstepconfiguration.Thefullstepmodeexhibits
twicetheangularresolutionofthehalfstepmode.
Anothercharacteristicdifferencebetweenusinghalfstepincrementsand
fullstepincrementstomaketherotormoveisthetorqueforcecapability.
Themotorwillexhibitagreatertorqueforcewhenfullstepcodesareused
becausethereistwiceasmanyenergizedstatorpolesapplyingmagnetic
attractionontherotorthanwhenhalfstepcodesareused.
Finally,todriveasteppermotor,asignalconditioningstageisneeded.
SincetheoutputcurrentoftheDAQused(thePCI6024E)istoolowto
drive the motor, a current amplifier (line driver) will be connected
betweentheDAQdigitaloutputandthemotorwires.Anexampleisgiven
later using the LM18293 line driver chip, but other current driving
hardwarecanbeusedsuchasusingfourBJTtransistorsinopencollector
modeasshowninFigure3.

UsingDataSocketstoControlaStepperMotorovertheNetwork
20
Figure3StepperMotorwithBJTcurrentdriver

(Source:http://www.allegromicro.com/techpub2/airpax/smh29.pdf)

Pre-Lab Preparation
Readthisexperimentbeforecomingtothelab.Youshouldunderstandthe
operationofthesteppermotor,andknowthedifferencebetweenfullstep
andhalfstepmodes.

Bringthefollowingtolabwithyou:
Thisexperiment.
Yourlabnotebookandpencil.

2virusfreeformatted3.5inchfloppydisks(alwaysmakeabackup
copyofyourcodeontheseconddisk).

Answerthefollowingquestionsinthedatasheetprovidedattheendofthis
experimentbeforecomingtothelab.Remembertoincludetheseanswers
inyourlabreporttoo.Someofthesesquestionsneedexperimentationto
findtheanswer.

13. Whatisthelogic1outputvoltageonthe6024Ecard?Whatisthe
logic0outputvoltage?Whatisthelowestinputvoltagetoproducea
logic 1 input? And the highest input voltage to produce a logic 0
input?CompareyouranswerstoTTLandCMOSstandards.

14. Howdoyouproduceatristateoutput?Whatisthevoltagelevel?

15. Howfastcanasingledigitaloutputonthe6024bechanged?

16. WhichVIisthemostsuitablefortheDigitalControlofthestepper
motor(FunctionsMenuDataAcquisitionDigitalI/O)?

UsingDataSocketstoControlaStepperMotorovertheNetwork
21
17. HowwillyoustorethelastpositionofthemotorintheLabVIEW VI?
Howwillyouinitializethisvalue?

18. WhatisthedifferencebetweenaDigitalPortandaDigitalLineinthe
DigitalI/OVIs?

19. If the consecutive positions of a Stepper Motor in the clockwise


directionsarenumbered0,1,2,3.7,obtainthebinarycodegivento
thesteppermotorcorrespondingtoeachposition.

Workstation Details
Yourworkstationshouldhavethefollowingitems:

ComputerwithNationalInstrumentsLabVIEWsoftware

NationalInstrumentsDAQboard(insidethecomputer)

NationalInstrumentsDAQboardterminalblock

Steppermotor(48internalpoleswith4coilsand5terminals)

LM18293pushpullquadlinedriver(oranalternativecurrentdriver
hardware).

Prototypeboardandjumperwires

Lab Procedure
1. Start a new VI in LabVIEW. You should then add the following
controlsandindicatorstothefrontpanel:

j. HalfStepping/Full SteppingMode Switch: This switch controls


whetherthemotorrotatesinincrementsoffullstepsorhalfsteps.

k. Clockwise/CounterClockwiseRotation Switch: This control is


usedtoalternatebetweenthetwodirectionsofrotation.

l. SpeedofRotationDigitalControl:Aknobtocontrolthespeedof
themotorinsteps/second.Thisfunctionvariesthemotorspeedby
controllinghowfasttheactualbinaryarrayisfedtothemotor.In
otherwords,itcontrolsthetime,inmillisecondsofwait,that
lapses between the outputs of each binary array that drives the
steppermotor.

m. NumberofStepsDigitalControl: Byusingthisfunctiontheuser
canspecifythemaximumnumberofstepsthemotorwillmake

UsingDataSocketstoControlaStepperMotorovertheNetwork
22
whethertheyarefullsteps,orhalfsteps.Thiswillbethenumber
ofiterationstothemainloopintheVIcode.

n. PowerSwitch:ThisisthemainOn/OffswitchfortheVI.

o. Current Position indicator: This is a gaugelike indicator that


showsthecurrentpositionofthemotorindegrees,assumingit
startedat0degrees.Thisindicatorshouldreflectthedirectionof
rotationofthemotorandtheamountofdegreeseachstepmoves.

p. CurrentOutputCode:Thisisanindicatorwith4ledsarray
showingthecurrentoutputcodetothemotorinbinary.

2. After adding those controls, start wiring the VI diagrams with the
controlstoimplementthefunctionalityofthesteppermotorcontrol.You
mightfindthefollowingVIcomponentsusefulinyourcode:

g. A main loop, best implemented as a For Loop structure. The


numberofiterationsistheinputfromthenumberofstepscontrol
onthefrontpanel.
h. A1dimensionalarray(lookuptable)ofcontrolcodes.Sincethe
motorusedhas4coils,therewillbe8differentcodesforahalf
step configuration. We will use one array only (the halfstep
codesarrangedinclockwiseorder)andobtainthevaluesfrom
thisarrayusinganindex.Theindexitselfdependsonthestep
modeandthedirectionofrotation.Thecodesinthearrayshould
bewritteninbinary(makesuretorightclickonthearrayandset
theFormatPrecisiontoBinary).
i. TwoSelectVIs(fromFunctionsComparison).Thesewillbe
usedwiththetwoswitches(stepmodeandrotationdirection).
TheSelectVIwiredtotheStepModeswitchwillselecta1for
halfstepand2forfullstep.Thisisequivalenttoskippingevery
othercodeinthearraywhengoinginfullsteps.Similarly,the
Selectwiredtothedirectionofrotationswitchwillselecta1for
aclockwiserotation anda1foracounterclockwise rotation.
This is equivalent to going forward or backward in the array
elements.
j. AMultiplicationVItomultiplytheoutputsofthetwoSelects
describedincabove.Therewillbe4differentcombinations
for the output of the multiplier VI, specifying the
increment/decrementtotheindexofthearray:
1=halfstepclockwise

UsingDataSocketstoControlaStepperMotorovertheNetwork
23
2=fullstepclockwise
1=halfstepcounterclockwise
2=fullstepcounterclockwise
k. AnAdditionVItoaddtheincrement/decrementobtainedind
withthepreviousvaluestoredinashiftregister.Theoutputof
theAdditionVIfeedstheinputtheshiftregister.Thisway,you
willkeeptrackofthecurrentvalueoftheindextotraversethe
lookuptable.Makesuretheshiftregisteroutput(totheleft)is
initializedtozero(attachittoazeroconstantoutsidetheloop)
l. AQuotientandRemainder VI.This willbeusedtowrapthe
indexoverthe8elementsofthearray.Youwilluseittodivide
theoutputoftheadderinewithaconstantinteger(8),and
taketheRemainderastheactualindextothearray.
m. AWriteToDigitalPortVItosendthevalueobtainedfromthe
arraytothedigitalportofthe6024E.Configuretheoutputso
thatyousendtoPort0(PA)ofdevice1(6024E).Thedefault
portlengthis8butweareusingonly4bits(theleastsignificant
bitsoftheword).
n. A Stop VI (Application Control Stop) wired to the power
switchandplacedinsidethemainloop.
3. These are the basic elements that you will need to have aworking
program.YouwillneedmoreVIcomponentstocontrolthespeedof
rotation (milliseconds wait) and to show the current motor position.
Rememberthatonewholerotationis360degrees,andthatthemotor
goes3.75degreesforeachhalfstepand7.5degreesforeachfullstep.If
youhaveanyquestionsaboutwritingtheremainingcode,askyourlab
instructor.
4.Afterfinishingyourcodesaveittothefloppydisks.Next,youneedto
connect the DAQ digital output pins with the motor and the current
driverIC.FollowtheconnectionsinthediagraminFigure4.
5.Testyourcodeandconnectionsbymovingthemotorasfollows:
Fullstepclockwise
Fullstepcounterclockwise
Halfstepclockwise
Halfstepcounterclockwise
Alltheabovecombinationswithvaryingspeed
Maketheobservationnecessarytocharacterizethelossoftorque
observationwhenusinghalfstepvs.fullstep.

UsingDataSocketstoControlaStepperMotorovertheNetwork
24
Note the angle of rotation (the current position) while you are
experimentingwiththepossiblecombinationsabove.

Lab Report
Yourreportmustbetypedandofprofessionalquality.Youshouldinclude
thefollowinginyourreport:

8. Allschematics,whichmustbecomputergenerated.Components
must be labeled with circuit references and values. The
schematics must be fully compliant with standard engineering
practicesforcircuitdepiction.

9. FrontpanelandblockdiagramofallVIsandSubVIsthatyou
wroteorused.

10. ATheorysectiondescribingthetheorybehindtheconceptsused
inthislab.

11. AnimplementationsectiondescribingthedetailsofyourVIcode
andthelogicflow.

12. Thetestresultsandobservations.

13. TheanswerstothePrelabquestions.

14. Selected sections of the datasheet of the 6024E, the stepper


motorand/ortheLM18293.

Data Sheet
1.Answer:.

2.Answer:.

UsingDataSocketstoControlaStepperMotorovertheNetwork
25
3.Answer:.

4.Answer:.

5.Answer:.

6.Answer:.

7.Answer:

Position A1 A2 B1 B2
0
1
2
3
4
5
6
7

UsingDataSocketstoControlaStepperMotorovertheNetwork
26

+5

LM18293 DIO0
DIO3

DIO2
DIO1

+5
DGND

Yellow
Red Stepper
Blue Motor
White

Figure4ConnectionSchematic

UsingDataSocketstoControlaStepperMotorovertheNetwork
27

You might also like