CGetting Started.docx
《CGetting Started.docx》由会员分享,可在线阅读,更多相关《CGetting Started.docx(17页珍藏版)》请在冰豆网上搜索。
![CGetting Started.docx](https://file1.bdocx.com/fileroot1/2023-1/14/320ead84-ee44-49e0-801b-0cffa82b29f0/320ead84-ee44-49e0-801b-0cffa82b29f01.gif)
CGettingStarted
C2000GettingStarted
Introduction
TheTexasInstrumentsC28xfamilyofdigitalsignalprocessorshasbeendesignedtoimplementcontrolapplications,forexample,digitalmotorcontrolandun-interruptiblepowersupplies.ThischapterdescribesabasicapplicationusingtheTMS320F2812.
Objectives
∙DesignaverysimpleprojectfortheTexasInstrumentsC28xfamilyofDSPdevicesusingMATLAB®andSimulink®.
∙Runtheprojectinreal-timeontheTexasInstrumentsF2812ezDSP.
Requirements
IndevelopingthisLaboratory,thefollowinghardwareandsoftwarewereused:
∙MATLABR2006bwithEmbeddedTargetforTIC2000.
∙CodeComposerStudio(CCS)3v1.
∙SpectrumDigitalezDSPF2812Hardware
∙A1kOhmresistor
StartingaNewProject
Thereareseveralstagestofollowinordertoimplementaproject.Thesearenowexplained.
ConnectingtheF2812ezDSP
ForMATLABandSimulinktoruncorrectly,youneedtoruntheF2812ezDSP.
1.ConnecttheF2812hardwaretotheparallelportofthecomputerandturnonthesupplytotheboard.Whentheboardispowered,thetwogreenLEDlightsontheboardwillcomeonduringself-test.
2.StartCodeComposerStudioforF2812ezDSPanduseDebug->Connect
Figure1–StartupScreenforCodeComposerStudio(CCS)
CreatinganewMATLABModel
3.StartMATLAB7.3.0R2006b.InthetoplefthandcorneroftheMATLABscreen,selectFile->New->Model.
Figure2–ANewMATLABModel
Thefollowingscreenwillappear.
Figure3–AnEmptyMATLABModel
SavingtheNewModel
4.Savethenewmodelas“my_model.mdl”.
Figure4-Savingthenewmodel
OpeningtheLibraryBrowser
5.SelectView->LibraryBrowser
Figure5–SelectingtheLibraryBrowser
TheSimulinkLibraryBrowser
6.Alistofavailableblockswillappear.Weareparticularlyinterestedinthe“EmbeddedTargetforTIC2000DSP”.Clickonthisselection.
Figure6-TheSimulinkLibraryBrowser
SelectingTargetPreferences
7.FromtheC2000TargetPreferences,select“F2812ezDSP”.Drag-and-droptheiconontothenewmodel.
Figure7–SelectingTargetPreferences
Whenthefollowingscreenappears,itisimportanttoselect“Yes”.
Figure8-InitializingSimulationParameters
AddingC281xChipSupport
8.ReturntotheSimulinkLibraryBrowser.Select“C281xDSPChipSupport”.ThisliststheinternalblockswithintheC281x.
Figure9–C281xDSPChipSupport
AddingaDigitalOutput
9.Drag-and-dropthe“DigitalOutput”blockontothemodel.
Figure10–AddingtheDigitalOutputBlock
SettingtheOutputParameters
10.Doubleclickonthe“GPIOD0”block.
Figure11–SettingtheOutputBlockParameters
SettingtheOutputPortBits
11.Select“IOPort”GPIOFfromthepull-downmenu.Deselect“Bit0”(removethefromthebox).Select“Bit14”sothatawillappearinthebox.Clickon“OK”.
Figure12–SettinguptheOutputPortBits
AddingaConstant
12.Fromthe“SimulinkLibraryBrowser”,select“CommonlyUsedBlocks”.Highlight“Constant”.Drag-and-dropthe“Constant”blockontothemodel.
Figure13–AddingaConstant
SettingtheConstantParameters
13.Doubleclickonthe“Constant”block.Selectthe“SignalDataTypes”tab.Makethedatatype“Boolean”.Clickon“OK”.HereaBooleanvariablehasoneoftwovalues,0or1.
Figure14–SettingtheConstantType
14.
Selectthe“Main”tab.Changethe“Constantvalue”to0.Clickon“OK”.
Figure15–SettingtheConstantValue
FinishingtheFirstModel
15.Clickontherighthandsideofthe“Constant”block,thendragthecursortothe“GPIOD0”block.Thiswillconnectthetwoblockstogether.
Figure16–ConnectingtheBlocks
YourfirstSimulinkmodelisnowcomplete!
YouarenowreadytoconvertitintoaformthatyoucanrunontheezDSPF2812.
BuildingtheModel
SelectTools->Real-TimeWorkshop->BuildModel.
Figure17–BuildingtheModel
BuildinProgress
MATLABwillcreateanewprojectinCodeComposerStudioandgeneratethecodeforit.Thereisnoneedtodoanyprogramming!
Figure18–BuildinProgress
RunningtheModel
ThemodelhasnowbeenbuiltandisrunningontheF2812EZDSP.TheDS2LEDontheezDSPboardshouldnowbeoff.
Figure19–RunningtheApplication
CheckingtheGeneratedCode
Expandthe“my_project.pjt(Custom_MW)window.Clickon“my_model.c”.Thiscontainsthegeneratedcodefortheproject.CanyouseethelinewheretheconstantisfedintoGPIO?
Figure20–CheckingtheGeneratedCode
ModifyingtheModel
Sofar,wehaveonlyimplementedaverybasicmodel.Letusnowaddtoit.
TurningtheDS2LEDonagain
ToturntheDS2LEDonagain,changethevalueofthe“Constant”inthemodel.
ChangingtheConstant
Returnto“my_model.mdl”.Doubleclickonthe“Constant”block.Changethe“Constantvalue”to1thenclickon“OK”.
Figure21–ChangingtheConstantto1
BuildtheModelAgain
SelectTools->Real-TimeWorkshop->BuildModel.Thiswillbuildthemodelandrunit.
Figure22–Re-buildingtheModel
AddinganInputLine
Sofar,theLEDhasbeenactivatedcontinuously,becauseitwasbeingdrivenbyaconstant.WewillnowaddadigitalinputportthatwillcontrolthestateoftheLEDusingexternalhardware.
OpeningtheLibraryBrowser
SelectView->LibraryBrowser->C281xDSPChipSupport.Highlightdigitalinput.
Figure23–SelectingtheDigitalInputBlock
Drag-and-dropthe“DigitalInput”blockontothemodel.
SettingtheInputParameters
Drag-and-dropthe“product”blockontothemodel.
Setthe“IOPort”fieldto“GPI0A”.
Select“Bit0”byputtingainthebox.
Figure24–SettingtheInputParameters
Checkthatthe“Sampletime”is“inf”.
Makethe“Datatype”to“Boolean”.
Clickon“OK”.
AddingSomeSignalProcessing
Atthemomentwehaveaverysimplesystemthatdirectlyfeedstheinputstraighttotheoutput.Itisnowtimetoaddsomesimplesignalprocessing.
AddingtheNOTOperator
Thelogical“NOT”operatorturnstheinputupside-down
∙Wheninput=0,output=1
∙Wheninput=1,output=0.
SelectView->CommonlyUsedBlocks.Highlightthe“LogicOperator”
Figure25–AddingaLogicalOperator(NOT)
Drag-and-dropthe“LogicalOperator”blockontothemodel.
SettingtheOperatorType
Doubleclickonthe“LogicalOperator”block.Changethe“Operator”typetoNOT.Clickon“OK”.
Figure26–ChangingtheLogicOperatorType
CompletingtheModel
Jointheblockstogethertocompletethemodel.
Figure27–CompletingtheModel
Re-buildingtheModel
Re-buildthemodelusingTools->Real-TimeWorkshop->Build.
RunningtheModel
Connecta1kOhmresistorbetweenConnectorP8pin9(GPIOAbit0)andConnectorP8pin19(Ground).TheDS2LEDwillnowbeoff.
RemovetheresistorfromtheezDSPF2812board.TheDS2LEDwillnowbeon.
Figure28–PlugginginaResistorintotheezDSPF2812
Congratulations!
YouhavenowimplementedyourfirstprojectusingSimulinkandtheTexasInstrumentsC28x.
Youmaybewonderingwhyyouhaveuseda1kOhmresistortocontroltheinput.Itwouldbepossibletoconnectthedigitalinputtogroundviaa0Ohmlink(apieceofwire).Thisisnotrecommended.TheGPIOontheF2812canbeconfiguredasbothinputsandoutputs.Ifyouputa0Ohmlinkonadigitaloutputitcanbedamagedbecauseitwilltaketoomuchcurrent.However,a1kOhmresistorlimitsthecurrenttoafewmAandpreventsdamagetotheF2812.
ThingstoTry
UseaDifferentInputPin
Useadifferentinputpintoconnecttheinputresistor.Itwillbenecessarytomakechangestothe“DigitalInput”block.
UseMultipleInputs
UsetwoinputpinsandturntheDS2LEDonifeitherinputislow.Youwillneedtousealogicaloperator.
References
[1]SpectrumDigitalIncorporated,"eZdspTMF2812TechnicalReference"Rev.F,September2003.()
MATLABandSimulinkareregisteredtrademarksofTheMathWorks,Inc.Seeforalistofadditionaltrademarks.Otherproductorbrandnamesmaybetrademarksorregisteredtrademarksoftheirrespectiveholders.