Upload
vuquynh
View
214
Download
1
Embed Size (px)
Citation preview
1
RENSSELAERPOLYTECHNIC INST ITUTE‐ ECSE 4790 MICROPROCESSORSYSTEMS (MPS)
ControllerAreaNetworkNationalInstrumentsManual
LabVIEWTeam:
AlbertBarsaCarlosCaoCaoPaulKwoniUpdateversion
AUGUST20,2012
ManualforECSE4790MPSCourselabexperimentdealingspecificallywiththeNationalInstrumentsUSBCANHardware
2
CANUSB:
ThedemoboxprovidedbyLesleyYuhelpedusgreatlyunderstandthefunctionalityandlimitationoftheNIUSB‐8473Hardware.TheCANUSBdoesnotsupportChannelAPIbecauseUSBdeviceslackthisfunction.ThismanualwillalsodetailothertopicsusingtheNational Instrument’s(NI)equipment. ItwillstartoffbycoveringtheCANUSB,itwillthencovertheDAQcardandfinallywillcoverCANtoDAQdatasynchronization.
HardwareRequired:
Figure1:TerminationCable Figure2:NICANUSB‐8473
Figure3:NICANDemoBox
Procedure:
InstallingLabVIEWSoftware
• LabVIEWisalreadyinstalledonthelabdesktops,howeveryou’llneeditonyourlaptoptobeabletoruntheexampleVIsforthisdemonstrationonyourlaptop.Thistakesquiteabitoftimeifyouaregoingtoinstall the latest version. So farNI‐HWS,NI‐IMAQ,NI‐IMAQdx,NI‐IMAQ for IEEE1394,NI‐IMAQ IO,NI‐Motion,andNI‐RIOarenot requiredtobe installed.Downloadthe latestversionofLabVIEWfromRPI.Instructionsonhowtogetalicenseanddownloadareonthehelpdesksite.
3
• FollowtheinstallinstructionontheRPIwebpage
InstallingNI‐CANSoftware
• Theexamplesthatyouneedhavetobe installedseparatelyforNI‐CAN(2.7.3)thatcomeswithNIUSB‐8473.ItcontainsspecificexamplesthatutilizeCAN.ItalsoinstallsthedriversthatarerequiredtoenabletheNIUSBmodulestoproperlycommunicatewithyourcomputer.InstallNI‐CAN2.7.3from: http://joule.ni.com/nidu/cds/view/p/id/2646/lang/en
• WhenpromptedforaLabVIEWVersion,chooseLabVIEW2011,unlessyouhaveanolderversion.Installallsubfeatures.
• YoucandisableVisualBasic/VisualC/BorlandCsupport.ItisnotneededfortheCANviewer.
Figure4:NI‐CAN2.7.3Examples
YouaredonewiththeLabVIEWinstallandmayopenanyCANVIthatyouwishtouse.
InstallingMeasurement&AutomationExplorerSoftware
• Thehardwaredemocomeswithanotherdisklabeled“NICANDemoBox”thathasausermanualandacoupleoffilesonit.YouneedtocopythecontentofthisdisktotheNationalInstrumentsfolderthatislocatedatC:\ProgramFiles\NationalInstruments.
4
h Figure5:NI‐CANDemoBoxCD
AfteryouaredonecopyingyouneedopenMeasurement&AutomationExplorerthatcanbefoundeitheronyourDesktoporinprogramfilesundertheNationalInstrumentsfolder.
Figure6:NIMAX(Measurement&AutomationExplorer)Icon
Onceit loadsexpandtheDataNeighborhoodbyselectingthe+signonits leftside.LeftclickonCANChannels.SelectLoadChannelConfiguration.
Figure7:ExplorerWelcomeWindow
• Open CAN Demo Box.ncd from its location which should be in the directory you copied thecontentoftheCDin.Select“AddAllMessagesandChannels.”ClickLoad,andthenclickDone.
5
Figure8:LoadingChannelConfiguration
• Itshouldload13messagefilesintotheexplorer.
Figure9:MessageFilesLoaded
SettingupHardware
• ConnecttheNIUSB‐8473toyoucomputerviatheUSBport.
6
• Inthedemoboxyouareprovidedwithaterminationcable.ThiscablewillbeusedtoconnectthemaleDB9terminaloftheNIUSBhardwaretothemaleDB9terminalofthedemoboxlabeled“CAN.”
• ConnectajumperwirebetweentheFunctionGeneratorGenterminalandtheAnalogInToCANCh0terminal.(NationalInstruments,2006)
• ConnectasecondjumperwirebetweentheFunctionGeneratorGenterminalandtheAnalogInToCANCh1terminal.(NationalInstruments,2006)
Figure10:Wiring(NationalInstruments,2006)
• Connect the DC power supply to the box. At power up, the box will begin transmitting theWAVEFORM0_SAW0_SWITCHES_FROM_CDBandWAVEFORM1_SAW1_FROM_CDBmessagesattheNI‐CANdefaultbaudrateof125K.(NationalInstruments,2006)
• Thisiswhatyourfinalsetupshouldlooklike.
Figure11:ProperlyConnectedHardware
• YoucanverifythattheCANmessagesarebeingtransmittedbyrunningtheBusMonitorintheMeasurement & Automation Explorer (MAX). To run the Bus Monitor, right‐click the portconnected to thePort connector on theNI CANDemoBox and select BusMonitor. (NationalInstruments,2006)
7
Figure12:BusMonitor
LabVIEW
• StartLabVIEWanditwillopenawindowlabeled“GettingStarted.”Clickon“FindExamples.”
Figure13:LabVIEWWelcomeWindow
• Itwillopenanotherwindow“NIExampleFinder”inwhichthereisasearchfieldonthetopleft
corner.Searchfor“CAN.”Doubleclickthesearchresultsinthefieldbelow.SelectCANReceive.vifromthelistgiveninthecenter.
8
Figure14:NIExampleFinder
• This will open the CAN Receive.vi, make sure you select CAN0 in the interface window and
changetheBaudrateto500000beforehittingrun(theright‐pointingarrow).
Figure15:CANReceive.viExample
9
Figure16:DemoSetupwithCANReceive.virunningonthelaptop
SendingaFrametotheCANbuswithLabVIEW:
HardwareRequired:
Figure17:TerminationCable Figure18:NICANUSB‐8473
Procedure:HardwareConnections
• The connection between theNIUSB‐8473 andCANbus requires a termination cable. It is an essentialcomponent togetting thedata fromtheCANbus toyourPC.The terminationcablewillactasamale‐maleconverterbetweentheNIUSB‐8473andCANbusDB9terminals.
• TheNIUSB‐8473willconnecttoyourPCthroughtheUSBport.
10
• Youwill connect themale DB9 terminal of your NI USB‐8473 to one of the female terminals on yourterminationcable.
• Theother female terminalof the termination cablewill be connected to themaleDB9 terminalof theCANbus.
LabVIEW
• StartLabVIEWanditwillopenawindowlabeled“GettingStarted.”Clickon“FindExamples.”
Figure19:LabVIEWWelcomeWindow[Uselatestversionavailable]
• Itwillopenanotherwindow“NIExampleFinder” inwhichthereisasearchfieldonthetopleftcorner.
Searchfor“CAN.”Doubleclickthesearchresultsinthefieldbelow.SelectCANTransmit–eventbased.vifromthelistgiveninthecenter.
11
Figure20:NIExampleFinder
• ThiswillopentheCANTransmit–eventbased.viwithitsdefaultinputvalues.
Figure21:CANTransmit‐eventbased.vi
• Thisstepisthemostimportantanditneedstobefollowedcarefully.Theinterfaceneedstobechanged
toCAN0,theBaudratemustbe500000oryouwillnotbeabletocommunicatewiththeCANbusonthecaratall.
12
Figure22:CANTransmit‐eventbased.viwithinterfaceandBaudratechanged
• AfterchangingthevaluesofinterfaceandBaudrate,youneedtochangethedatalengthandArbitrationId.Thechangesinthesetwovaluesdependonwhichfeatureyouwanttocontrol.Thefollowingtablewillassistyouinselectingthesevalues.
CANDemoBoxFunctions
Changesmaybeobserveddirectlyformostitemsifthedisplayisalreadyshowingtheaffectedmenuitem.
Function ArbitrationID[decimalval]
Databytes
Data
Ch0Dataout&Switches(Readonly)
0x710[1808]
3 2bytesofanalogdata,3rdbyte:XXS3S2S1S0XX
Ch1Dataout(Readonly)
0x720[1824]
3 2bytesofanalogdata,3rdbyte:0x00
StringRequest 0x730[1840]
0(ignored)
Ignored,butmakesureRTRisnotset.Boxreplieswithnextmessage.
StringResponse(Readonly)
0x740[1856]
6 6‐bytestringwithASCII“NI‐CAN”codes;replytoStringRequestcommand.
TransmitType 0x760[1888]
1 0‐Disableall1‐Waveform0,Sawtooth0,Switchesonly2‐Waveform1,Sawtooth1only3‐Enableall
DelayMultiplier 0x763[1891]
2 Delaybetweenanalogsamples:DelayMultiplierx200nsRange:0–65535Default:50,000(10ms)
BaudRateType(Canchangebutcan’tchangebackwithoutusingBoxmenu
buttons)
0x765[1893]
1 2‐125Kbps3‐250Kbps4‐500Kbps5‐1Mbps
13
FunctionGeneratorOutput 0x766[1894]
1 0‐Sine1‐Square2‐Triangle
FunctionGeneratorFrequency 0x767[1895]
1 0to9‐0.1to1Hzin0.1Hzincrements9to18‐1to10Hzin1Hzincrements18to117‐10Hzto1kHzin10Hzincr.
LCDContrast 0x768[1896]
1 0‐Decreasecontrast1‐Increasecontrast
LCDMenu(DisplaysselectedmenuonDemoBoxLCDpanel)
0x769[1897]
1 0‐CANbaudrate1‐CANtransmitstatus2‐CAN/DAQ3‐Functiongeneratoroutput4‐Functiongeneratorfrequency5‐LCDcontrast6‐(clearscreen)7‐“HighSpeedCAN”message
• It is highly recommended that you start off with the simplest feature to control. It would berecommended that you try changing the displayed function generator frequency at Id 0x767. As anexample,tosendasingledatabyte(bytevalueof1)toadevicewhoseArbitrationIDis0x30thesettingwouldbe:
Figure23:ChangingArbitrationIdandDataLength[NewArbitrationIdshouldbe04]
• TheDatahas8inputsbutwhenyousettheDatalengthtobe1,itwilltakeonlythefirstinputandignoretherest.NowyoucanclickthebuttonwiththewhitearrowonitthatwillmaketheVIrun.Thedeviceat0x30canbeactivatedwhenyousetthefirstinputto1andclickWrite.Toturnitoffyouneedtochangetheinputto0andclickWriteoncemore.
14
Figure24:RunningVIandChangingDatainput[NewArbitrationIdshouldbe04]
GettingtheDAQcardtalkingtoDAQassist:
[ThissectioncanonlybecompletedifaDAQCard‐6062Eisavailable,otherwiseitshouldbeskipped.Thispartof the procedure requires the use of FrameAPI for the CAN interface rather than Channel API. So far, only
ChannelAPIhasbeenimplemented.TheUSB‐8473convertersdonotsupportFrameAPI.ContinuewithUsingLabVIEWWiththeCANDemoBoxandAnalogSignalsonpage23.]
InorderforthecomputertorecognizetheDAQcard,weneedtoinserttheDAQcardfirstandinstallthedriverforit.Atthistimeofinstallation,IamusingLabVIEW8.5.1totalktotheDAQcard.Thedriverversionthatworked well talking to LabVIEW 8.5.1 was NI‐DAQmx 8.8, which can be downloaded from:http://ftp.ni.com/support/softlib/multifunction_daq/nidaqmx/8.8/nidaq880f2_downloader.exe
15
Use the defaults setting to install this driver. Once the driver is finished installing, you can check by
clicking (NI MAX icon), click on “Devices and Interfaces ‐> Ni‐DAQmx Devices ‐> NI DAQCard‐6062E:“Dev1”,andchoose“TestPanels”attheuppercorner:
AndyoucantestthefunctionalityoftheDAQcard:
16
Youcanalsogoto“Software”tocheckifthedriveriscorrectlyinstalled,andyouwillseethefollowing:Onceitisverified,youcanmaketheDAQtalkingtotheDAQassist.Thefollowingstepsarefollowed:
1) OpenLabVIEW2) PressCtrl+Ntocreatea“NewVI”3) ThenpressCTRL+E,(Window‐>ShowBlockDiagram),tobringtheBlockDiagram4) Rightclickanywhereontheblankspace,andpickthefirsticononthelistandyouwillseetheDAQassist
icon:
5) Choose“DAQAssist”,andyouneedtoplacetheDAQAssistandwillseeanInitializingdialog.
17
6) Finally,youwillhavethefollowing:
7) Thenyouselecteither“AcquireSignals”or“GenerateSignals”tochoosethetoolyouneedlikeVoltage,temperature,Resistance,etc.
8) Click on Finished once you are done. And you will see another window of the kind of tool you have
selected.Inmycase:Ihavechose:AcquireSignals‐>AnalogInput‐>Voltage‐>ai0togetthefollowingwindows:
18
CB‐68LP
To investigate further the useful feature of the DAQ card, we can use an Unshielded Screw TerminalBlocks,CB‐68LPthathas68pinstosimulatedifferentI/OsignalswiththeDAQcard.Toconnectcorrectlywiththepins,wecanlookatthereferencetablebelow:
TheimportantpinsthatareneededtomakethisterminalconnectorandtheDAQcardworkareindicated,andyoucanusetheTestPaneltosimulatethesignalswithdifferentinputnumbers.
19
TOPIC:CANDEMOBOX,USB‐8473s,andDAQCARDSYNCHRONIZATION
Beforewestart: Inorder to accomplish thegoalof this guide,weneed the followingequipments:
CANdemobox,NIUSB‐8473s,DAQCard‐6062E,andcablesthatallowingconnectionbetweencomputerCANdemobox,andNIUSB‐8473s.
SpecialsetuponNIUSB‐8473s:Tomakethisdevicetowork,weneedtoputsomewiresbetweenthedemoboxanditself.Thewiresconfigurationisfollowed:
20
Next,wegoto totestiftheDAQcardisfuctioningcorrecting.ThisisimportantbecausesometimesthecomputerdoesnotrecognizetheDAQcardandcauseproblemstohappen.
21
OnceweknowthattheDAQcardisworkingcorrectly.WenowcanlaunchLabVIEW8.5,atthisstageiftestingLabVIEW8.6DOESNOTwork.Clickon“FindExamples ‐>Search ‐>Enterkeyword”,andwrite“CAN”,thenclickon“CANFrameAPIInputDAQmxInput.VI”.
Andyouwillseethefollowingwithoutanyproblems:
Ifyoucan’tseethepictureabove,thefollowingarethepossiblecausesthatwehaveencountered:
22
1) TheLabVIEWversionshouldbethelatestavailable
2) ThecorrectwiringbetweenCANUSBandDemobox
3) TheDAQcardshouldbeinsertedandworkingproperly
WhenwegobacktoourLabVIEW,weonlyneedtoclick“RUN”or“CLT+R”,wecanseethatLabVIEWisreadingdatafromthedevices.Wealsonotedthedifferenttimesframesthatthedatawasacquired:
Youcanclickon“Window‐>ShowBlockDiagram”orCLT+Etoseehowthedeviceworks.
23
UsingLabVIEWWiththeCANDemoBoxandAnalogSignals
ThispartofthelabprocedurewilluseNILabVIEWtoolstoobserveandplotanalogwaveformsgeneratedintheCANDemoBoxandsampledinthebox.ThedatasamplesaresentoutasCANframesonthebus.AVIwillbeusedtoreadthesamplesandcreateareal‐timeplotofthewaveforms.
[TheproceduresandVIssupportingtheanalogsignalsgeneratedbytheNICANDemoBoxanddisplayingthemingraphicalformarenotavailableyet.Thispartoftheexercisewillbeimplementedatalaterdate.]
24
UsingLabVIEWWiththeModelCar
Thesecondpartofthe labprocedure involvesCANcommunicationswiththemodelcarstillusingtheLabVIEWtoolsandtwoVIsthatweredevelopedtoassistintheprocessofwritinganddebuggingCcodeontheC8051F040EVB.UseanyofthepreviousVIsaswellastwonewones(CAN‐sender‐MPS.viandCAN‐viewer‐MPS.vi).Thesearestrippeddownversionsthathavebeensimplifiedtobeeasiertouse.Beforegoingbacktothelabtocontinuetheprocedure,someofthefunctionsmaybecheckedoutheretoverifythecorrectoperationoftheRCcaranditsresponsetocommands.ThefollowingtablesummarizestheCANIDstowhichthecarwillrespond.
RCCarFunctions
Function ArbitrationID Datalength
Data
Headlights 0x01 1 Byte0:0=Off,1=On
Leftturnsignal 0x02 1 Byte0:0=Off,1=On
Rightturnsignal 0x03 1 Byte0:0=Off,1=On
Horn 0x04 1 Byte0:0=Off,1=On
DriveMotorDAC 0x05 2 Byte1,Byte0:12‐bitvalue(0‐4095/0‐0xFFF)
SteeringServoPWM 0x06 2 Byte1,Byte0:16‐bitvalue(850‐2150)
(Windshieldwiper) 0x20 1 Byte0:0=Off,1=On
RCCarStatusReplies
Function ArbitrationID Datalength
Data
MotorTemperature 0x07 2 Byte1,Byte0:12‐bitvalue(0‐4095/0‐0xFFF)
WheelRPM 0x08 2 Byte1,Byte0:12‐bitvalue(0‐1400/0‐0x578)
MotorCurrent 0x09 2 Byte1,Byte0:12‐bitvalue(0‐4095/0‐0xFFF)
LeftTurnSignalStatus 0x0A 1 Byte0:0=Off,0xFF=On
RightTurnSignalStatus 0x0B 1 Byte0:0=Off,0xFF=On
WorksCitedNationalInstruments.(2006,October).NI‐CANHardwareandSoftwareManual.
https://forum.ecse.rpi.edu/index.php?topic=7056.0