/
Programmer'sGuide Programmer'sGuide

Programmer'sGuide - PDF document

alexa-scheidler
alexa-scheidler . @alexa-scheidler
Follow
403 views
Uploaded On 2016-10-25

Programmer'sGuide - PPT Presentation

SLAA490D ID: 480468

SLAA490D

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Programmer'sGuide" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Programmer'sGuide SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary MSP430™microcontrollersofferanumberofperipheralsthat,whenconfiguredproperly,canbeusedto performacapacitancemeasurement.Thepurposeofthecapacitivetouchlibraryistocreateasingle interfacethatcanbeintegratedwiththeperipheralsetsfoundintheValueLine,2xx,5xx,FR4xx,and FR59xxproductfamilies.Thisdocumentexplainsthecapacitivetouchlibrary'sconfigurationanduse. Thesoftwarelibrarydescribedinthisdocumentcanbedownloadedfrom http://www.ti.com/tool/capsenselibrary. Contents 1Introduction...................................................................................................................4 2Methods.......................................................................................................................5 3Configuration.................................................................................................................8 4Resources...................................................................................................................41 5APICalls.....................................................................................................................43 6EstablishingMeasurementParameters.................................................................................50 AppendixACTS_Layer.candCTS_Layer.hDetailedDescription........................................................55 ListofFigures 1RelaxationOscillatorMeasurement.......................................................................................5 2Resistor-CapacitorTimeConstantMeasurement(RC).................................................................6 3RCSchematic................................................................................................................7 4FastScanROMeasurement...............................................................................................7 5Elements......................................................................................................................9 6ElementMeasurementParameters:ButtonsExample................................................................10 7CBCTL0Register...........................................................................................................11 8RO_PinOscSchematic....................................................................................................11 9PinOscPortParameters...................................................................................................12 10CapacitiveTouchI/OImplementation...................................................................................12 11CAPSIOxCTLRegister....................................................................................................13 12RCIOParameters.........................................................................................................14 13SensorExample............................................................................................................15 14RO_COMPBPortParameters............................................................................................16 15PortParametersforRO_COMPAp_TAxImplementation.............................................................17 16fRO_COMPAp_SW_TAxGeneralDescription.........................................................................18 17RO_COMPAp_TAxSchematicDescription.............................................................................20 18TimingParameters:ExampleWDTp....................................................................................22 19RO_COMPBSchematic...................................................................................................23 20RO_PinOsc_TA0TimingParameter.....................................................................................28 21RCTimingParameters....................................................................................................32 22fRO_CSIO_TA2_TA3TimingParameters..............................................................................33 23fRO_PinOsc_TA0_TA1TimingParameters............................................................................34 24fRO_PinOsc_TA0TimingParameters...................................................................................35 25fRO_COMPB_TA1_TA0TimingParameters...........................................................................36 1 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.com 26fRO_COMP_B_TAx_SWTimingParameters..........................................................................38 27fRO_COMPAp_TA0_SWTimingParameters..........................................................................39 28fRO_CSIO_TA0_SWTimingParameters...............................................................................40 29SliderExample..............................................................................................................46 30WheelExample.............................................................................................................47 31CustomSliderExample...................................................................................................48 32MeasurementExampleofaFour-ElementSensor....................................................................53 33ValidSliderLocationsasaFunctionoftheSensorThreshold.......................................................54 34Status/BaselineControlRegister(RAM)................................................................................55 35BaseCapacitanceUpdate................................................................................................57 36DeltaMeasurementBlockDiagram......................................................................................58 37SingleButtonAlgorithm...................................................................................................59 38ArrayofButtonsAlgorithm................................................................................................60 39SliderandWheelAlgorithm...............................................................................................61 40SliderThresholdDetection................................................................................................62 41SliderandWheelProcessMiddleAlgorithm............................................................................63 42SliderAlgorithm:BeginningofSlider....................................................................................63 43SliderAlgorithm:EndOfSlider...........................................................................................64 44WheelThresholdDetection...............................................................................................64 45WheelAlgorithm:Beginning..............................................................................................65 46WheelAlgorithm:Ending..................................................................................................66 47DominantElementIdentificationFunction..............................................................................67 ListofTables 1HALRecommendation......................................................................................................4 2RelaxationOscillatorNamingConvention................................................................................6 3FastRONamingConvention...............................................................................................7 4ComparisonoffROandROMeasurementTimes......................................................................8 5CBCTL0RegisterDescription............................................................................................11 6CAPSIOxCTLRegisterDescription......................................................................................13 7baseOffsetDescription....................................................................................................18 8halDefinitionDescriptions................................................................................................19 9WatchdogTimerSourceSelectDefinitions.............................................................................21 10WatchdogTimer+IntervalSelectDefinitions...........................................................................21 11WatchdogSourceSelectDefinitions.....................................................................................24 12WatchdogIntervalSelectDefinitions....................................................................................24 13TimerASourceSelectDefinitions........................................................................................25 14TimerASourceSelectDefinitions........................................................................................26 15TimerASourceSelectDefinitions........................................................................................30 16RTCSourceSelectDefinitions...........................................................................................31 17measureGateSourceDefinitionsforfRO_xxxx_SW_Txx.............................................................39 18sourceScaleDefinitionsforfRO_xxxx_SW_Txx.......................................................................40 19GateTimeExamples......................................................................................................42 20ExampleFlashResourceAllocation.....................................................................................42 21CapacitiveTouchLibraryAPIs...........................................................................................44 22UpdateTrackingRateFormat............................................................................................50 23ExampleRawResultsWithROMethod................................................................................51 24ExampleChangeinCapacitanceResultsWithROMethod..........................................................52 25MeasurementExampleofaFour-ElementSensor....................................................................53 2 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.com 26Status/BaselineControlRegisterDescription..........................................................................55 27TrackingSettingsAgainstDirectionofInterest.........................................................................57 28TrackingSettingsinDirectionofInterest................................................................................57 29ExampleHALDefinitions..................................................................................................59 3 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Introductionwww.ti.com 1Introduction TheCapacitiveTouchSoftwareLibraryprovidescodethatperformscapacitancemeasurementsonthe MSP430microcontrollerplatformusingseveralcombinationsandpermutationsofperipherals.Tosimplify theuseofcapacitivetouchsensingontheMSP430,thelibraryprovidesaconfigurationstructurethatis specifictotheimplementationandAPIcallsthatarespecifictotheapplication. ThemainpurposeofthisdocumentistoexplaintheAPIcallsandtheconfigurationofthelibrary. However,itisalsoimportanttohaveabasicunderstandingofthemeasurementimplementationsandhow peripheralresourcesareusedbeforeusingthelibrary. Section2describestherelaxationoscillator(RO),timeconstant(RC),andfastROmethodswiththe MSP430. Section3describesthelibraryconfiguration. Section4describesperipheralresources. Section5describestheAPIsandthelevelsordegreesofabstractionwiththoseAPIs.Thehigherlevels ofabstractionprovidestandardcontrolsforfasterandeasierdevelopmentwhilethelowerlevelsallowfor customizationanduniquecontrols. Theassociatedcode(1)isintendedtobeastartingpointfordevelopingcapacitivetouchandother capacitivemeasurementsolutions.Thelibrarysupportsawidevarietyoffeaturesandfunctions,allof whichmaynotberequiredforaspecificapplication.Thesourcecodeisprovided,andcustomersare encouragedtoremovesectionsofcodethatarenotusedaftercreatingaworkingapplication.Additionally, interruptserviceroutines(ISRs)arepartofthesourcecode,whichmayneedadditionalcodetosupport otherapplications.ThisisacommonadjustmentneededwithWDTISR.Again,asapplicationsallowfor sharedISRfunctionality,customersareencouragedtoupdatethesourcecodeprovidedtosupport capacitivetouchfunctionalityinadditiontoothertasks. (1)Thesoftwarelibrarydescribedinthisdocumentcanbedownloadedfromhttp://www.ti.com/tool/capsenselibrary. Table1.HALRecommendation Devices HALs Section G2xx2 RO_PINOSC_TA0_WDTp Section3.2.2.3.1 RO_PINOSC_TA0_WDTp Section3.2.2.3.1 G2xx3 fRO_PINOSC_TA0_TA1 Section3.2.2.9 RO_PINOSC_TA1_WDTp Section3.2.2.3 G2xx5 fRO_PINOSC_TA1_TB0 Section3.2.2.3 F51xx RO_COMPB_TA0_WDTA Section3.2.2.2.1 RO_COMPB_TA1_WDTA Section3.2.2.2.1 F52xx fRO_COMPB_TA1_TA0 Section3.2.2.11 fRO_CSIO_TA0_TA1 Section3.2.2.8 FR4xx RO_CSIO_TA0_RTC Section3.2.2.5.5 RO_COMPB_TA1_WDTA Section3.2.2.2.1 F55xx fRO_COMPB_TA1_TA0 Section3.2.2.11 RO_CSIO_TA2_WDTA Section3.2.2.5.1 FR58xxandFR59xx fRO_CSIO_TA2_TA3 Section3.2.2.7 MSP430isatrademarkofTexasInstruments. Allothertrademarksarethepropertyoftheirrespectiveowners. 4 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comMethods 2Methods Forthemethodsdescribedinthisdocument,thefundamentalprincipleisthattwoindependenttimebases arecompared.Onetimebaseisfixedandtheotherisvariableasafunctionofthecapacitance.Aslong asthecapacitancedoesnotchange,therelationshipbetweenthetworemainsconstant.Timersareused tomeasurethetwotimebases,andtherelationshipismonitoredinsoftware.Whentherelationship changes,thesoftwaremustdecideifthechangewasanincreaseordecreaseinthecapacitanceandif thechangewassignificantenoughtobeconsidereda'touch'. Thethreemethodsdiscussedinthisdocumentaretherelaxationoscillator(RO),theresistorcapacitor (RC),andthefastrelaxationoscillator(fRO). 2.1RelaxationOscillator(RO)(1) TheROmethodcountsthenumberofrelaxationoscillatorcycleswithinafixedperiod(gatetime),as showninFigure1.Thevariabletimebase,TimeBase1,isconnectedtoarelaxationoscillatorcircuit.The relaxationoscillatorcanberealizedwithacomparator,thePinOscfeaturefoundintheValueLineproduct family,ortheCapacitiveTouchI/OfoundintheMSP430FR58xxandMSP430FR59xxfamily.Thefixed timebase,TimeBase2,isconnectedtoaninternalMSP430systemclocksuchastheDCOorREFO.The gatetimeisanumberofthesystemclockoscillations. Figure1.RelaxationOscillatorMeasurement Thefrequencyoftherelaxationoscillatorisfunctionofthecapacitanceofthecircuit.Asthecapacitance increases(C1toC2),therelationshipbetweentheTimeBase1andTimeBase2changes.Thenumberof relaxationoscillatorcyclescountedwithinthegatetimedecreases.Asthecapacitancedecreases(C2to C1),thenumberofcycleswithinthegatetimeincreases.Capacitanceandcountshaveaninverse relationshipintheROmethod. (1)TheROmethodisdescribedinmoredetailinPCB-BasedCapacitiveTouchSensingWithMSP430(SLAA363). 5 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Methodswww.ti.com ThenamingconventionfortheROmethodinthelibraryidentifiestherelaxationoscillatormechanism,the timerthatisusedtomeasureorcountoscillations,andthetimerthatisusedtodefinethegateperiod. Table2.RelaxationOscillatorNamingConvention Name ROMechanism Counter GatePeriod RO_XXX_YYY_ZZZ XXX YYY ZZZ RO_COMPAp_TA0_WDTp Comparator_A+ TimerA0 Watchdogtimer(intervalmode) RO_Pinosc_TA0 PinOscillator TimerA0 'n'ACLKperiods(1) Capacitive-Touch RO_CSIO_TA2_TA3 TimerA2 TimerA3 EnabledIO (1)TheRO_PINOSC_TA0isaspecialcasethattakesadvantageoftheinternalconnectionbetweenACLKandtheTimerA0 captureinput.TheuserhasthechoiceofsimplydividingtheACLKintheapplicationlayer(by2,4,8,andsettingnto1)orby enteringanumberofACLKcycles,orboth. 2.2Resistor-CapacitorTimeConstantMeasurement(RC)(1) TheRCmethodisthereciprocaloftheROmethod.AsshowninFigure2,thegatetimeisnowvariable, andtheoscillatorbeingcountedisfixed.Thefixedtimebase,TimeBase1,isconnectedtoaninternal MSP430oscillator,suchastheDCO.Thevariabletimebase,TimeBase2,isconnectedtoacapacitor andresistorandthetimeittakestochargeanddischargethecapacitoranumberoftimesthroughthe resistorisnowthegatetime.TheRCmethodcanberealizedwithanyMSP430. Figure2.Resistor-CapacitorTimeConstantMeasurement(RC) Thegatetimeisafunctionofthecapacitanceofthecircuit.Asthecapacitanceincreases(C1toC2),the relationshipbetweenthetwotimebaseschanges.Thenumberofsystemclockcyclescountedwithinthe gatetimeincreases.Asthecapacitancedecreases(C2toC1),thenumberofcycleswithinthegatetime decreases.FortheRCmethodtherelationshipbetweencapacitanceandcountsisdirect. Thismethodusesasingletimingresource(TIMER_A0)tomeasurethetimeittakesthecapacitanceto chargeanddischarge'n'times.Tomeasurebothchargeanddischarge,twoIOareneeded,asshownin Figure3.Thisisreflectedinthefunctionnamewithinthelibrary:RC_PAIR. (1)TheROmethodisdescribedinmoredetailinPCB-BasedCapacitiveTouchSensingWithMSP430(SLAA363). 6 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comMethods Figure3.RCSchematic 2.3FastScanRelaxationOscillator(fRO) ThefROmethodissimilartotheRCmethodexceptthatthevariablegateperiodiscreatedwitha relaxationoscillatorinsteadofthechargeanddischargetime.AndasshowninFigure4,thefixedtime base,TimeBase1,isconnectedtoaninternalMSP430oscillator,suchastheDCO.Thevariabletime base,TimeBase2,isconnectedtotherelaxationoscillator. Figure4.FastScanROMeasurement Thegatetimeisafunctionofthecapacitanceofthecircuit.Asthecapacitanceincreases(C1toC2),the relationshipbetweenTimeBase1andTimeBase2changes.Thenumberofsystemclockcyclescounted withinthegatetimeincreases.Asthecapacitancedecreases(C2toC1),thenumberofcycleswithinthe gatetimedecreases.ForthefROmethodtherelationshipbetweencapacitanceandcountsisdirectjust liketheRCmethod.Thefastrelaxationoscillator(fRO)methodisintendedtobridgethegapbetweenthe RCandROmethods.ThefROmethodprovidesthefastscanratesoftheRCmethodandtheimproved sensitivityoftheROmethod. ThenamingconventionforthefROmethodinthelibraryidentifiestherelaxationoscillatormechanism,the timerusedtodefinethegateperiod(asafunctionofthevariablerelaxationoscillatorfrequency),andthe timerusedtocountthefixedoscillationfrequency. Table3.FastRONamingConvention Name ROMechanism GatePeriod Counter fRO_XXX_YYY_ZZZ XXX YYY ZZZ fRO_COMPB_TA1_SW ComparatorB TimerA1 SoftwareLoop fRO_PINOSC_TA0_TA1 PinOscillator TimerA0 TimerA1 7 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Asthenameimplies,thepurposeofthefROmethodistoprovidefastscanrates;fasterthantheRO methodwithsimilarsensitivity(1).WiththeROmethod,sensitivityisafunctionofthegatetime.Increasing thegatetimeincreasessensitivity.Thenegativeconsequenceofincreasinggatetimeisdecreasedscan rates:moretimeisspentduringasinglemeasurement.ThesensitivityofthefROmethodcanalsobe improvedwithincreasedgatetime,however,thesensitivitycanalsobeimprovedbyimprovingthesystem clockresolution(higherspeed). IncomparisontotheROmethodthefROmethodprovidessimilarsensitivity(changeincounts)ina shortergatetime.Thetheoreticalexercisefoundinshowsthatsimilarsensitivitycanbeachievedwiththe fROmethodinlesstime. (1)Inthiscontext,sensitivityisameasureofhowsmallachangeincapacitancecanberesolved. Table4.ComparisonoffROandROMeasurementTimes RO_PinOsc_TA0_WDTp fRO_PinOsc_TAx_TA1 GateTime Counter Counts GateTime Counter Counts (1-MHzSMCLK, (RO) (45ROcycles) (SMCLK) WDT,512) Touched 512µs 1MHz 512 45/1MHz=45µs 12MHz 540 Untouched 512µs 1.1MHz 563 45/1.1MHz=41µs 12MHz 492 Difference 51 48 3Configuration Therearetwomainfilesthatserveasthemeanstoconfigurethelibrary:structure.candstructure.h. structure.cincludesdefinitionsoftheelementsandthesensors(groupsofelements).Thestructure.hfile makesthedefinitionsinstructure.cvisibletotheotherportionsofthelibraryandalsousesprecompiler definitionstoenablefunctionsandlimitcodesize. 3.1ElementDefinition Acapacitivemeasurementelementisasingularstructure,whosecapacitancerepresentsanevent;for example,atouch,achangeinhumidity,orachangeindielectric.Anelementcanbeusedindividually(for exampleasabutton)orcombinedwithotherelementstocreateakeypad,wheel,orsliderasshownin Figure5. 8 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration Figure5.Elements Theelementdefinitionsbelongtooneoftwocategories;portdefinitionormeasurementparameter.The portsdefinitionsincludedigitalI/Operipheralregisters,comparatorperipheralregisters,andbitdefinitions. Themeasurementparametersincludethethresholdandmaximumsignalresponse(maxResponse)ofan element.Theportdefinitioncanbecompletedbysimplyreadingtheschematicwhilethemeasurement parametersrequiretesting(seeSection6).Establishingthecorrectmeasurementparameterscalibrates theelements. Theelementdefinitionfoundintheconfigurationfilestructure.cusesadesignatedinitializerlist.This allowsmemberstobeinitializedinanyorderandalsoenhancesthereadabilityoftheelementbeing initialized.ThisfeaturerequirestheGCClanguageextensionfoundinCodeComposerStudio(CCS).C99 isthedefaultdialectfoundinIARand,therefore,thedefaultsettingscanbeused. 3.1.1CommonElementVariables InputBitsisonecommondefinitionthatcanrepresentthebityintheGPIOdefinitionPx.y,thecomparator inputmuxforeitherCOMP_A+orCOMP_Bsolutions,orthecapacitivetouchIOportandbitselectionin thecapacitivetouchIOcontrolregister. thresholddefinesthelimitorthresholdthatthechangeincapacitancemustexceedbeforeanevent (typicallyatouch)isdeclared. maxResponseisthemaximumresponseexpectedfromanelementwithinasensorandonlyusedin sensorswithmultipleelements:slider,wheel,andbuttons(1).ThepurposeofthemaxResponseparameter istonormalizethecapacitivemeasurementtoapercentage,wherethethresholdrepresents0%andthe maxResponserepresents100%.Thispercentageisusedtoidentifythedominantelementwithinthe sensorifmultipleelementshavethresholdcrossings. (1)Thebuttonsabstractionisasensormadefromtwoormoreelements.Thebuttonabstractionisasensormadefromoneelement. 9 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Figure6.ElementMeasurementParameters:ButtonsExample Figure6showstherelativerelationshipbetweenthresholdandmaxResponseinabuttonsapplication. First,themaxResponsevalueisonlyneededforthebuttons,wheel,andsliderAPIs.Asmentionedinthe definitionthemaxResponseisusedtodeterminethedominantelement.Second,themaxResponse representaheavytouchwherethefingerflattens,bypressingheavily,tocreatealargersurfacearea.By contrastalightornormaltouchcreatesamuchsmallersurfacearea.Thethresholdvaluerepresentsa changeincapacitancethatissmallerthaneventhelightesttouchbutstillsignificantlylargerthanany noisethatmightappearasachangeincapacitance. ThethresholdandmaxResponsevariablesarelimitedtounsigned16-bitintegers(0to65535).These valuesarefurtherlimitedbythefollowingwhenamulti-elementabstractionisused(buttons,slider,or wheel):maxResponse–threshold655.Section6providesmoredetailonestablishingthemeasurement parameters. 3.1.1.1Comparator_A+(COMP_A+) ImplementationsusingtheCOMP_A+peripheraltocreatearelaxationoscillatorusethesameelement structureformat. InputBitsidentifythebits,P2CA1,P2CA2,andP2CA3,withintheCACTL2registerwhichrepresentthe negativeterminalinputofthecomparator.Thisinputisconnecteddirectlytotheelectrode.Theinputfor thereferenceisdefinedinthesensorsection. ConststructElementelement_name={ .inputBits=P2CA2,//CA2 .threshold=100, .maxResponse=200 }; 10 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.1.1.2Comparator_B(COMP_B) InputBitsidentifytheCBIMSELbitsintheCBCTL0register. Figure7.CBCTL0Register 15 14 13 12 11 10 9 8 CBIMEN Reserved CBIMSEL rw-0 r-0 r-0 r-0 rw-0 rw-0 rw-0 rw-0 7 6 5 4 3 2 1 0 CBIPEN Reserved CBIPSEL rw-0 r-0 r-0 r-0 rw-0 rw-0 rw-0 rw-0 Table5.CBCTL0RegisterDescription Bit Field Type Reset Description 15 CBIMEN RW 0h ChannelinputenablefortheV–terminalofthecomparator. 0b=SelectedanaloginputchannelforV–terminalisdisabled. 1b=SelectedanaloginputchannelforV–terminalisenabled. 14-12 Reserved R 0h Reserved.Alwaysreadsas0. 11-8 CBIMSEL RW 0h ChannelinputselectedfortheV–terminalofthecomparatorifCBIMENissetto 1. 7 CBIPEN RW 0h ChannelinputenablefortheV+terminalofthecomparator. 0b=SelectedanaloginputchannelforV+terminalisdisabled. 1b=SelectedanaloginputchannelforV+terminalisenabled. 6-4 Reserved R 0h Reserved.Alwaysreadsas0. 3-0 CBIPSEL RW 0h ChannelinputselectedfortheV+terminalofthecomparatorifCBIPENissetto 1. conststructElementelement_name={ .inputBits=CBIMSEL_2,//CB2 .threshold=100, .maxResponse=200 }; 3.1.1.3PinOscillator(PinOsc) ThePinOscillator(PinOsc)implementationoftherelaxationoscillatorreplacesthecomparatorand referencecircuitrywiththeSchmitttriggerinputfoundinthedigitalI/Oandaninternalinverter.The PinOscfeedbackpathtotheRCfilterisaccomplishedwiththeintegratedresistor,asshowninFigure8. Figure8.RO_PinOscSchematic 11 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com *inputPxselRregisterand*inputPxsel2Registeridentifytheappropriateregistersthatneedtobeconfigured forthepinoscillatormethod.TheseregistersinconjunctionwithinputBitsconfiguretheelementasshown inFigure9andthefollowingcodesnippet. Figure9.PinOscPortParameters conststructElementright={ .inputPxselRegister=(uint8_t*)&P2SEL, .inputPxsel2Register=(uint8_t*)&P2SEL2, .inputBits=BIT3, .maxResponse=400, .threshold=50 }; 3.1.1.4CapacitiveTouchI/O(CSIO) ThecapacitivetouchIO(CSIO)implementationoftherelaxationoscillatoristhesameasthePinOsc; however,theinterfaceforcontrollingthedigitalI/Oisdifferent. Figure10.CapacitiveTouchI/OImplementation Therelaxationoscillatorisaccomplishedwithinternalcircuitryandtheportparameteronlyincludesthe inputBitswhichrepresentthecapacitivetouchIOportandpinselectbitswithinthecontrolregister (CAPSIOxCTL).Theportandpinselectbitsaredefinedattheelementlevelwhilethecontrolregisteris definedatthesensorlevel:inputCapsioctlRegister. 12 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration InputBitsidentifytheportandpinselectbitsintheCAPSIOxCTLregister. Figure11.CAPSIOxCTLRegister 15 14 13 12 11 10 9 8 Reserved CAPSIO CAPSIOEN r0 r0 r0 r0 r0 r0 r-0 rw-0 7 6 5 4 3 2 1 0 CAPSIOPOSELx CAPSIOPISELx Reserved rw-0 rw-0 rw-0 rw-0 rw-0 rw-0 rw-0 r0 Table6.CAPSIOxCTLRegisterDescription Bit Field Type Reset Description 15-10 Reserved R 0h Reserved.Alwaysreads0. 9 CAPSIO R 0h CapacitiveTouchI/Ostate.ReportsthecurrentstateoftheselectedCapacitive TouchI/O.Reads0,ifCapacitiveTouchI/Odisabled. 0b=Currentstate0orCapacitiveTouchI/Oisdisabled 1b=Currentstate1 8 CAPSIOEN RW 0h CapacitiveTouchI/Oenable 0b=AllCapacitiveTouchI/Osaredisabled.Signaltowardtimersis0. 1b=SelectedCapacitiveTouchI/Oisenabled 7-4 CAPSIOPOSELx RW 0h CapacitiveTouchI/Oportselect.SelectsportPx.Selectingaportpinthatisnot availableonthedeviceinusegivesunpredictableresults. 0000b=Px=PJ 0001b=Px=P1 0010b=Px=P2 ... 1110b=Px=P14 1111b=Px=P15 3-1 CAPSIOPISELx RW 0h CapacitiveTouchI/Opinselect.SelectsthepinwithinselectedportPx(see CAPSIOPOSELx).Selectingaportpinthatisnotavailableonthedeviceinuse givesunpredictableresults. 000b=Px.0 001b=Px.1 010b=Px.2 ... 110b=Px.6 111b=Px.7 0 Reserved R 0h Reserved.Alwaysreads0. conststructElementelement_name={ .inputBits=CAPSIOPOSEL0+CAPSIOPOSEL1+CAPSIOPISEL2,//P3.4 .threshold=100, .maxResponse=200 } 13 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.1.2ElementVariablesSpecifictoRC TheRCmethodiscomprisedoftwoGPIO.Oneistheinputandtheotheristhereference.The configurationrequiresthepertinentregisteraddressesforagivenportaswellasthebitdefinition. inputPxdirRegister,inputPxoutRegister,andinputPxinRegisteridentifytheportdirection,output,andinput addresses.TheseregistersinconjunctionwithinputBitsconfiguretheinputportionoftheelement definition. referencePxdirRegisterandreferencePxoutRegisteridentifytheportdirectionandoutputaddresses. TheseregistersinconjunctionwithreferenceBitsconfigurethereferenceportion. Onefeatureofthisdescriptionisthatonepincanhavetwodifferentfunctions.Thatisthepincanbea referenceinoneelementdefinitionandaninputinanotherelementdefinition.Figure12andthefollowing codesnippetshowthereferenceandinputdefinitions. Figure12.RCIOParameters //RCP2.0input,P2.1Reference conststructElementelement1={ .inputPxinRegister=(uint8_t*)&P2IN, .inputPxoutRegister=(uint8_t*)&P2OUT, .inputPxdirRegister=(uint8_t*)&P2DIR, .inputBits=BIT0, .referencePxoutRegister=(uint8_t*)&P2OUT, .referencePxdirRegister=(uint8_t*)&P2DIR, .referenceBits=BIT1, .threshold=100, .maxResponse=200 }; //RCP2.1input,P2.0Reference conststructElementelement2={ .inputPxinRegister=(uint8_t*)&P2IN, .inputPxoutRegister=(uint8_t*)&P2OUT, .inputPxdirRegister=(uint8_t*)&P2DIR, .inputBits=BIT1, .referencePxoutRegister=(uint8_t*)&P2OUT, .referencePxdirRegister=(uint8_t*)&P2DIR, .referenceBits=BIT0, .threshold=120, .maxResponse=250 }; 14 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2SensorDefinition Thesensorcansimplybeasingleelement,agroupofindependentelementslikeakeypad,oragroupof elementsfunctioningasonesensorlikeawheelorslider.Thesensordefinitionincludesallofthe applicableelements,theimplementationthatisusedtomeasurethecapacitanceofalltheelements,and theperipheraladdressesandbitsettingsforthegivenmechanism.Inthecaseofwheelsandsliders,the sensordefinitionalsodefinesthenumberofpointsorpositionsalongwiththeslider,asshownin Figure13,andthesensitivityofthesensor. Figure13.SensorExample Thissectionisdividedintothreesub-sections:portvariables,commonvariables,andvariablesspecificto slidersandwheels.TheportvariablesareonlyapplicabletotheCSIOandcomparatorimplementationsof capacitivetouchsensing.TheseimplementationsrequireeitheradditionalGPIOorregistersettingsto configuretheMSP430.Thecommonvariablesarevariablesthatarecommoninnamebutdifferentin meaningdependentuponthemethod.Thissub-sectiondescribesthrougheachimplementation,providing codeexamples.Thewheelsandsliderssub-sectiondescribesthevariablesassociatedwithwheeland slidersensor. Thesensordefinitionfoundintheconfigurationfilestructure.cusesadesignatedinitializerlist.Thisallows memberstobeinitializedinanyorderandalsoenhancesthereadabilityofthesensorbeinginitialized. ThisfeaturerequirestheGCClanguageextensionfoundinCodeComposerStudio(CCS).C99isthe defaultdialectfoundinIARandthereforethedefaultsettingscanbeused. 3.2.1PortVariables TheportvariableswithinthesensordefinitionareonlyapplicabletotheCOMP_A+,COMP_B,andCSIO implementations. 3.2.1.1CSIOPortVariable Theportandpinselectbitsaredefinedattheelementlevelwhilethecontrolregisterisdefinedatthe sensorlevel:inputCapsioctlRegister. TheinputCapsioctlRegisterisdifferentfromtheotherparametersfoundinthelibrarybecausethe associationbetweentheCAPSIOxCTLregisterandtimerisdevicedependent.Itisimportantthatthe controlregisterselectedworkswiththeHALalsoindicatedwithinthesensorleveldefinition.Forexample ifCAPSIO0CTLisassociatedwithTimerA2,thentheinputCapsioctlRegistermustpointtoCAPSIO0CTL whentheRO_CSIO_TA2_WDTAHALdefinitionisused. 15 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.1.2COMP_BPortVariables TheimplementationoftheCOMP_Bsolutionrequiresanalternativesetofparametersforthesensorport variables,showninFigure14. Figure14.RO_COMPBPortParameters cboutTAxRegister,cboutTAxRegisteridentifytheportdirectionaddressandportselectionaddress.The variablecboutTAxBitsdefinethebitsthataretobesetorresetwithinthedirectionandselectionregister toselecttheCBOUTxoutputandTxCLKinputfunctionoftheport.Notethaton5xxfamilydevices,these portssharethesameIO. SomeMSP430devicesallowthedigitalI/Otobedrivenfromadifferentvoltagerail(DVIO)thanthe voltagerail(VCC)thattheComp_Bperipheraluses.Ifthecomparatoroutput,CBOUT,usesDVIOand DVIOisdifferentfromVCC,thentheinputhighandinputlowvaluessetwithinthelibraryneedtobe updated.ThesevaluesaresetintheComp_Bcontrolregister2,CBCTL2,foundintheCTS_HAL.cfile. cbpdBitsisusedtodisabletheDigitalI/Oontheportpinsalsousedasthecomparatorinputs.Thisis appliedtotheCOMP_BcontrolregisterCBCTL3.ThebitCBPDy,inCBCTL3,disablestheportofthe comparatorchannel'y'(thatis,CBPDydisablesCByandnotPx.y) 16 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2.1.3COMP_A+PortVariables Intheelementstructurethecomparatorinputisdefinedforeachelement.Atthesensorlevel,asshownin Figure15,thecomparatorreferenceinputisdefinedaswellasthereferenceport,comparatoroutput,and timerinput. Figure15.PortParametersforRO_COMPAp_TAxImplementation caoutDirRegisterandcaoutSelRegisteridentifytheportdirectionaddressandportselectionaddress.The variablecaoutBitsdefinethebitsthataretobesetorresetwithinthedirectionandselregistertoselect theCAOUToutputfunctionoftheport.SomedevicesalsousethePxSEL2registertodefinetheCAOUT usecase.InthecaseofthesedevicesthevaluecaoutSel2Registermustalsobedefined(eitheras P1SEL2orP2SEL2). txclkDirRegister,txclkSelRegisteridentifytheportdirectionaddressandportselectionaddress.The variabletxclkBitsdefinethebitsthataretobesetorresetwithinthedirectionandselectionregisterto selecttheTxCLKinputfunctionoftheport.SomedevicesalsousethePxSEL2registertodefinethe TxCLKusecase.Inthecaseofthesedevices,thevaluetxclkSel2Registermustalsobedefined(eitheras P1SEL2orP2SEL2). TherefPxDirRegister,refPxOutRegister,andrefBitvariablesdefinethepullupportionoftheexternal referencecircuitshowninFigure15.Thesebitsprovidethemechanismtoturnonandoffthereference forpowersavings.refPxDirRegister,refPxOutRegisteridentifytheportdirectionaddressandportoutput address.ThevariablerefBitsdefinethebitsthataretobesetorresetwithinthedirectionandselection registertoenablethereferencecircuit. refCactl2BitsindicateswhichpositiveinputofCOMP_A+isconnectedtothevoltagereference.The referenceshouldonlybeappliedtothepositiveinputviaCA0,CA1,orCA2.Thisisrepresentedas P2CA0,P2CA4,andP2CA0+P2CA4,respectively. capdBitsisusedtodefinetheIOwhichmakeupthesensor.ThisisappliedtotheCOMP_A+control registerCAPD.Thisvalueisthelogical'OR'ofallthebitdefinitionsforeachinputandthereferenceinput (thatis,the'y'ofPx.yandNOTthe'y'inCAy). AslightvariationoftheCOMP_A+implementationisthefRO_COMPAp_SW_TAximplementationwhich usesasoftwaretimertocreatethegatetimeandthetimerperipheralasthefrequencycounter.Because thisimplementationdoesnotusethetimertocountthenumberrelaxationsoscillationsthephysical connectionisnolongerneededasshowninFigure16. 17 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Figure16.fRO_COMPAp_SW_TAxGeneralDescription TheportparametersarethesameasthosedescribedabovewiththeexceptionoftxclkDirRegister, txclkSelRegister,andtxclkBits,whicharenotused. 3.2.2CommonSensorVariables numElementsidentifiesthenumberofelementsthatarewithinthesensor. baseOffsetisacumulativecountofthenumberofelementsthataredefinedintheapplication.Thereisa baselinevaluestoredinRAMforeachelement. //INstructure.hFILE #defineTOTAL_NUMBER_OF_ELEMENTS8 //INCTS_Layer.cFILE uint16_tbaseCnt[TOTAL_NUMBER_OF_ELEMENTS]; Table7.baseOffsetDescription Sensor .baseOffset Element RAMAddress element0 baseCnt[0] element1 baseCnt[1] Slider0 0 element2 baseCnt[2] element3 baseCnt[3] element4 baseCnt[4] element5 baseCnt[5] Slider1 4 element6 baseCnt[6] element7 baseCnt[7] arrayPtridentifiesalloftheelementsassociatedwithasensor.Inthecaseofthewheelandsliderthe orderofthearrayisimportantbecauseitisassumedthattheorderrepresentsthephysicalorderofthe elements. measGateSourceisusedtodefineeitherthegatetimersourceorthemeasurementclocksource dependinguponthemethod(halDefinition).InRCandfROmethods,measGateSourcedefinesthe measurementclocksource.IntheROimplementationmeasGateSourceidentifiesthegatetimersource. 18 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration sourceScaleisusedtofurtherdividedownthesource(eitherthemeasurementsourceorthegatesource dependinguponthecontext).Thisonlyappliestotimerperipheralsandnotthewatchdogtimer peripherals. accumulationCyclesisusedtodefinethegatetime.TypicallyaccumulationCyclesisthenumberof oscillationsofthegatetime,butwhenthewatchdogtimerisusedasthegateperipheralthe accumulationCyclesrepresentsthebitsettingsinthewatchdogtimercontrolregister. halDefinitionidentifieswhichmeasurementimplementationisbeingusedforthesensor.Table8liststhe differentimplementationscurrentlysupported. Table8.halDefinitionDescriptions halDefinition Description RelaxationoscillatorimplementedwithCOMP_A+peripheral.Thegatetimeisfixedanddefinedbythe RO_COMPAp_TA0_WDTp WDT+peripheralsettointervalmode.ThecapacitanceisrepresentedbythenumberofROcycles RO_COMPAp_TA1_WDTp countedbyTimerA0orTimerA1duringthefixedgatetime(seeSection3.2.2.1). RelaxationoscillatorimplementedwithPinOsc,TimerA0isusedtomeasurefrequencyofoscillator,and RO_PINOSC_TA0_WDTp theWDTpisusedtosetthegatetime(seeSection3.2.2.3). RelaxationoscillatorimplementedwithPinOsc,TimerA1isusedtomeasurefrequencyofoscillator,and RO_PINOSC_TA1_WDTp theWDTpisusedtosetthegatetime(seeSection3.2.2.3). RelaxationoscillatorimplementedwithPinOsc,TimerA0isusedtomeasurefrequencyofoscillator,and RO_PINOSC_TA0 theACLKsourceisusedtosetthegatetime(seeSection3.2.2.4). RelaxationoscillatorimplementedwithPinOsc,TimerA0isusedtomeasurefrequencyofoscillator,and RO_PINOSC_TA0_TA1 TimerA1isusedtosetthegatetime(seeSection3.2.2.3). RelaxationoscillatorimplementedwithPinOsc,TimerA1isusedtomeasurefrequencyofoscillator,and RO_PINOSC_TA1_TB0 TimerB0isusedtosetthegatetime(seeSection3.2.2.3). RO_COMPB_TA0_WDTA RelaxationoscillatorimplementedwithCOMP_Bperipheral,TimerA0,TimerA1,orTimerB0isusedto RO_COMPB_TA1_WDTA measurefrequencyofoscillator,andtheWDTAperipheralisusedtosetthegatetime(see RO_COMPB_TB0_WDTA Section3.2.2.2). RelaxationoscillatorimplementedwithCOMP_Bperipheral,TimerA1isusedtomeasurefrequencyof RO_COMPB_TA1_TA0 oscillator,andTimerA0isusedtosetthegatetime(seeSection3.2.2.2). RelaxationoscillatorimplementedwithcapacitivetouchIOperipheral,TimerA2isusedtomeasure RO_CSIO_TA2_WDTA frequencyofoscillator,andtheWDTAperipheralisusedtosetthegatetime(seeSection3.2.2.5). RelaxationoscillatorimplementedwithcapacitivetouchIOperipheral,TimerA2isusedtomeasure RO_CSIO_TA2_TA3 frequencyofoscillator,andTimerA3isusedtosetthegatetime(seeSection3.2.2.5). RelaxationoscillatorimplementedwithcapacitivetouchIOperipheral,TimerA0isusedtomeasure RO_CSIO_TA0_WDTA frequencyofoscillator,andWDTAperipheralisusedtosetthegatetime(seeSection3.2.2.5). RelaxationoscillatorimplementedwithcapacitivetouchIOperipheral,TimerA0isusedtomeasure RO_CSIO_TA0_TA1 frequencyofoscillator,andTimerA1isusedtosetthegatetime(seeSection3.2.2.5). RelaxationoscillatorimplementedwithcapacitivetouchIOperipheral,TimerA0isusedtomeasure RO_CSIO_TA0_RTC frequencyofoscillator,andRTCperipheralisusedtosetthegatetime(seeSection3.2.2.5). MeasureRCtimeconstantwithTimerA0.Thegatetimeisvariableandchangeswiththechargeand dischargetime.Asoftwareloopisusedtoestablishthenumberofchargeanddischargecyclesthat RC_PAIR_TA0 definethegatetime.ThecapacitanceisrepresentedbythenumberofTimerA0countswithinthegate time.TypicallyTA0issourcedfromahighfrequencyclock(SMCLK)forimprovedsensitivity.The capacitiveelementischargedanddischargewiththeotherIOdefinedinthepair(seeSection3.2.2.6). FastScanRelaxationoscillatorimplementedwithCOMP_A+peripheral.Thegatetimeisvariableand fRO_COMPAp_TA0_SW changeswiththeperiodoftherelaxationoscillator.TheTimerA0orTimerA1isusedtoestablishthe fRO_COMPAp_TA1_SW numberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythenumberof softwareloopscountedwithinthegatetime(seeSection3.2.2.13). FastScanRelaxationoscillatorimplementedwithCOMP_A+peripheral.Asoftware(SW)loopisusedto establishthenumberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythe fRO_COMPAp_SW_TA0 numberoftimercountsinTimerA0forthegatetime.TypicallyTA0issourcedfromahighfrequency clock(SMCLK)forimprovedsensitivity(seeSection3.2.2.14). MeasurethetimewithTimerA0,RelaxationoscillatorimplementedwithPinOsc,severaloscillationsare fRO_PINOSC_TA0_SW countedinSWtoestablishthegatetime(seeSection3.2.2.10). FastScanRelaxationoscillatorimplementedwithPinOsc.TheTimerA0isusedtoestablishthenumber ofoscillationsthatdefinethegatetime.ThecapacitanceisrepresentedbythenumberofTimerA1 fRO_PINOSC_TA0_TA1 countswithinthegatetime.TypicallyTA1issourcedfromahighfrequencyclock(SMCLK)(see Section3.2.2.9). 19 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Table8.halDefinitionDescriptions(continued) halDefinition Description FastScanRelaxationoscillatorimplementedwiththeCOMP_Bperipheral.TheTimerA0orTimerA1is fRO_COMPB_TA0_SW usedtoestablishthenumberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedby fRO_COMPB_TA1_SW thenumberofsoftwareloopscountedwithinthegatetime(seeSection3.2.2.12). FastScanRelaxationoscillatorimplementedwithCOMP_B.TheTimerA1isusedtoestablishthe numberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythenumberof fRO_COMPB_TA1_TA0 TimerA1countswithinthegatetime.TypicallyTA1issourcedfromahighfrequencyclock(SMCLK) (seeSection3.2.2.11). FastScanRelaxationoscillatorimplementedwiththecapacitivetouchIO.TheTimerA2isusedto establishthenumberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythe fRO_CSIO_TA2_TA3 numberofTimerA3countswithinthegatetime.TypicallyTA3issourcedfromahighfrequencyclock (SMCLK)(seeSection3.2.2.7). FastScanRelaxationoscillatorimplementedwiththecapacitivetouchIO.TheTimerA0isusedto establishthenumberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythe fRO_CSIO_TA0_TA1 numberofTimerA1countswithinthegatetime.TypicallyTA1issourcedfromahighfrequencyclock (SMCLK)(seeSection3.2.2.8). FastScanRelaxationoscillatorimplementedwiththecapacitivetouchIO.TheTimerA0isusedto fRO_CSIO_TA0_SW establishthenumberofoscillationsthatdefinethegatetime.Thecapacitanceisrepresentedbythe numberofsoftwareloopscountedwithinthegatetime(seeSectionSection3.2.2.15). 3.2.2.1RO_COMPAp_TAx_WDTp TherelaxationoscillatoriscomprisedoftheCOMP_A+module,areference,andRCfilter.Thereference isconnectedtothenon-invertinginputofCOMP_A+(viatheinputmux)whiletheRCfilterisconnectedto theinvertinginput(alsoviaaninputmux).Thereferenceisavoltagedividermadeupofoneconnection toaGPIOandtheotherconnectionstogroundandthecomparatoroutput. Onewaytomeasurethecapacitanceistoroutetheoscillator(viaCAOUT)toatimerinput(TAxCLK). TwodifferentHALdefinitionsareprovideddependinguponwhichclockisavailable; RO_COMPAp_TA0_WDTpandRO_COMPAp_TA1_WDTp. Figure17.RO_COMPAp_TAxSchematicDescription ThetwotimingparametersdefinetheWDTpintervalthatisthegatetimeforthe RO_COMPAp_TAx_WDTpimplementation. 20 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration measureGateSourceindicatestheWDTpsource:SMCLKorACLK.Thisparameterisequivalenttothe 'Watchdogtimer+clocksourceselect'bitsintheWatchdogTimer+register. Table9.WatchdogTimerSourceSelectDefinitions Definition Value Source GATE_WDTp_ACLK 0x0004 ACLK GATE_WDTp_SMCLK 0x0000 SMCLK accumulationCyclesisusedtodefinetheWDTpintervalintheRO_COMPAp_TAx_WDTpimplementation. ThisisequivalenttotheintervalselectbitsintheWatchdogTimer+register. Table10.WatchdogTimer+IntervalSelectDefinitions Definition Value Interval (s) WDTp_GATE_32768 0x0000 32768/source WDTp_GATE_8192 0x0001 8192/source WDTp_GATE_512 0x0002 512/source WDTp_GATE_64 0x0003 64/source 21 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Figure18showshowthecommonsensorparametersmeasGateSourceandaccumulationCyclesare usedtoselectthegatetime. Figure18.TimingParameters:ExampleWDTp 22 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration Thefollowingexampledescribesasensormadeupoffourelements,andeachelementismeasuredwith theROmethodforaperiodof512/SMCLK. conststructSensorslider= { .halDefinition=RO_COMPAp_TA0_WDTp, .numElements=4, .baseOffset=0, .points=80, .sensorThreshold=50, //Pointertoelements .arrayPtr[0]=&element0,//pointtofirstelement .arrayPtr[1]=&element1, .arrayPtr[2]=&element2, .arrayPtr[3]=&element3, //ReferenceInformation //CAOUTisP1.7 //TACLKisP1.0 .caoutDirRegister=(uint8_t*)&P1DIR,//PxDIR .caoutSelRegister=(uint8_t*)&P1SEL,//PxSEL .txclkDirRegister=(uint8_t*)&P1DIR,//PxDIR .txclkSelRegister=(uint8_t*)&P1SEL,//PxSEL .caoutBits=BIT7,//BITy .txclkBits=BIT0, //ReferenceisonP1.6 .refPxoutRegister=(uint8_t*)&P1OUT, .refPxdirRegister=(uint8_t*)&P1DIR, .refBits=BIT6,//BIT6 .refCactl2Bits=P2CA4,//CACTL2-�P2CA4,CA1 .capdBits=(BIT1+BIT2+BIT3+BIT4+BIT5), //TimerInformation .measGateSource=GATE_WDTp_SMCLK,//0-�SMCLK,1-�ACLK .accumulationCycles=WDTp_GATE_512//512 }; 3.2.2.2RO_COMPB_yyy_zzz TherelaxationoscillatorsolutionwithCOMP_BisthesameinfunctionastheCOMP_A+solution.The COMP_Bperipheralsolutionisdifferentinimplementation,integratingthereferencecircuitryand connectiontotheTimerAorTimerBperipheral,asshowninFigure19. Figure19.RO_COMPBSchematic 23 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.2.2.1RO_COMPB_TAx_WDTA,RO_COMPB_TBx_WDTA ThetwotimingparametersdefinetheWDTAintervalthatisthegatetimefortheimplementation.The WDTAmoduleprovidesfourdifferentsourcesettingsandeightwatchdogtimerintervals. measureGateSourceindicatestheWDTAsource:SMCLK.ACLK,VLO,orXCLK.Thisparameteris equivalenttotheWatchdogtimerclocksourceselectbitsintheWatchdogTimerControlregister (WDTCTL). Table11.WatchdogSourceSelectDefinitions Definition Value Source GATE_WDTA_SMCLK 0x0000 SMCLK GATE_WDTA_ACLK 0x0020 ACLK GATE_WDTA_VLO 0x0040 VLO GATE_WDTA_XCLK 0x0060 XCLK accumulationCyclesisusedtodefinetheWDTAinterval.Thisisequivalenttotheintervalselectbitsinthe WatchdogTimerControlRegister(WDTCTL). Table12.WatchdogIntervalSelectDefinitions Definition Value Interval (s) WDTA_GATE_2G 0x0000 2G/source WDTA_GATE_128M 0x0001 128M/source WDTA_GATE_8192K 0x0002 8192k/source WDTA_GATE_512K 0x0003 512k/source WDTA_GATE_32768 0x0004 32768/source WDTA_GATE_8192 0x0005 8192/source WDTA_GATE_512 0x0006 512/source WDTA_GATE_64 0x0007 64/source Thefollowingexampledescribesasensormadeupoffourelementsandeachelementismeasuredwith theROmethodforaperiodof512000/SMCLK. conststructSensorsliderA= { .halDefinition=RO_COMPB_TA0_WDTA, .numElements=4, .baseOffset=0, .points=64, .sensorThreshold=5, .cbpdBits=(BITC+BITD+BITE+BITF), //Pointertoelements .arrayPtr[0]=&element0, .arrayPtr[1]=&element4, .arrayPtr[2]=&element8, .arrayPtr[3]=&elementC, .cboutTAxDirRegister=(uint8_t*)&P3DIR,//PxDIR .cboutTAxSelRegister=(uint8_t*)&P3SEL,//PxSEL .cboutTAxBits=BIT4,//P3.4 //TimerInformation .measGateSource=GATE_WDTA_SMCLK, .accumulationCycles=WDTA_GATE_512K// }; Differentmemberswithinthe5xxfamilyprovideaninternalconnectionbetweenCBOUTandatimer.The descriptionandparametersarethesamefortimersTA0,TA1,andTB0,withtheexceptionoftheHAL definitionname. 24 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2.2.2.2RO_COMPB_TA1_TA0 Thetimingparametersdefinethetimerintervalthatisthegatetimefortheimplementation.Thetimer moduleprovidesfourdifferentsourcesettings,adividertoscaletheinputsource,andtheinterval,which isa16-bitintegerloadedintothetimercompareregister. measureGateSourceindicatesthetimersource:TxCLK,ACLK,SMCLK,orINCLK.Thisparameteris equivalenttothetimersourceselectbits(TxSSEL)inthetimercontrolregister(TxCTL). Table13.TimerASourceSelectDefinitions Definition Value Source TIMER_TxCLK 0x0000 TxCLK TIMER_ACLK 0x0100 ACLK TIMER_SMCLK 0x0200 SMCLK TIMER_INCLK 0x0300 INCLKorinvertedTxCLK sourceScaleisusedtodividethetimersource.Thisparameterisequivalenttotheinputdividerselectbits (ID)foundinthetimercontrolregister(TxCTL). accumulationCyclesisusedtodefinethetimerinterval.Thisvalueisloadedintothecapture/compare register(TxCCR0). Thefollowingexampledescribesasensormadeupoffourelementsandeachelementismeasuredwith theROmethodforaperiodof50/ACLK. conststructSensorkeypad= { .halDefinition=RO_COMPB_TA1_TA0, .numElements=5, .baseOffset=0, .cbpdBits=0x001F,//CB0,CB1,CB2,CB3,CB4 .arrayPtr[0]=&element0,//pointtofirstelement .arrayPtr[1]=&element1, .arrayPtr[2]=&element2, .arrayPtr[3]=&element3, .arrayPtr[4]=&element4, .cboutTAxDirRegister=(uint8_t*)&P1DIR,//PxDIR .cboutTAxSelRegister=(uint8_t*)&P1SEL,//PxSEL .cboutTAxBits=BIT6,//P1.6 //TimerInformation .measGateSource=TIMER_ACLK,//ACLK .sourceScale=TIMER_SOURCE_DIV_0,//ACLK/1 /*50ACLK/1cyclesor50*1/32Khz=1.5ms*/ .accumulationCycles=50 }; 25 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.2.3RO_PinOsc_TAx_zzz 3.2.2.3.1RO_PinOsc_TA0_WDTp Thecommontimingparameters,measGateSourceandaccumulationCycles,arethesameasthe COMP_A+implementation(seeSection3.2.2.1). ThefollowingsensordefinitiondescribesasensormadeupofoneelementthatismeasuredwiththeRO methodforaperiodof8192/SMCLK. conststructSensormiddle_button= { .halDefinition=RO_PINOSC_TA0_WDTp, .numElements=1, .baseOffset=4, //Pointertoelements .arrayPtr[0]=&middle_element,//pointtofirstelement //TimerInformation .measGateSource=GATE_WDTp_SMCLK,//0-�SMCLK,1-�ACLK //.accumulationCycles=WDTp_GATE_32768//32768 .accumulationCycles=WDTp_GATE_8192//8192 //.accumulationCycles=WDTp_GATE_512//512 //.accumulationCycles=WDTp_GATE_64//64 }; 3.2.2.3.2RO_PinOsc_TA0_TA1 Thetwotimingparametersdefinethetimerintervalthatisthegatetimefortheimplementation.Thetimer moduleprovidesfourdifferentsourcesettings,adividertoscaletheinputsource,andtheinterval,which isa16-bitintegerloadedintothetimercompareregister. measureGateSourceindicatesthetimersource:TxCLK,ACLK,SMCLK,orINCLK.Thisparameteris equivalenttothetimersourceselectbits(TxSSEL)inthetimercontrolregister(TxCTL). Table14.TimerASourceSelectDefinitions Definition Value Source TIMER_TxCLK 0x0000 TxCLK TIMER_ACLK 0x0100 ACLK TIMER_SMCLK 0x0200 SMCLK TIMER_INCLK 0x0300 INCLKorinvertedTxCLK sourceScaleisusedtodividethetimersource.Thisparameterisequivalenttotheinputdividerselectbits (ID)foundinthetimercontrolregister(TxCTL). accumulationCyclesisusedtodefinethetimerinterval.Thisvalueisloadedintothecapture/compare register(TxCCR0). 26 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration Thefollowingexampledescribesasensormadeupoffourelementsandeachelementismeasuredwith theROmethodforaperiodof11000/ACLK. conststructSensorproximity= { /*GatesourceisINCLKbydefault*/ .halDefinition=RO_PINOSC_TA0_TA1, .numElements=1, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&eProx, /* *TimerInformation *GateSourceisSMCLK */ .measGateSource=TIMER_SMCLK, /*GateSourcedividedby1*/ .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=11000//NumberofTimerA0(RO)cycles }; 3.2.2.4RO_PinOsc_TA0 AnalternativeimplementationoftheRO_PinOsc,withselectMSP430devices(1),istousetheinternal ACLKconnectiontothetimercaptureinput.Thegatetimeisthenumberofcaptureevents(equivalentto ACLKcycles),whilethefrequencycounterisstilltheperipheralTimerA0sourcedfromtherelaxation oscillator.Becausethecaptureinterruptrepresentsasingleoscillationseveralinterruptsarecountedwith asoftwarelooptocreatetheequivalentgatetime.UnliketheWDTmethodwherethemeasurementis doneinlowpowermode,thissoftwareloopmethodconsumesmorepowerbecausetheCPUstaysin ActiveMode. (1)SeethedatasheettodetermineiftheTimercaptureinputsupportsthisconnectiontoACLK. 27 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com AsshowninFigure20,theonlytimingparameterdefinitionfortheRO_PinOsc_TA0implementationisthe numberofACLKcycles:sensor-�accumulationCycles. Figure20.RO_PinOsc_TA0TimingParameter ThefollowingsensordefinitiondescribesasensormadeupofoneelementthatismeasuredwiththeRO methodforaperiodof100/ACLK. conststructSensorvolume= { .halDefinition=RO_PINOSC_TA0, .numElements=2, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&up,//pointtofirstelement .arrayPtr[1]=&down,// //TimerInformation .accumulationCycles=100//100ACLKcycles }; 28 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2.2.5RO_CSIO_yyy_zzz 3.2.2.5.1RO_CSIO_TA2_WDTA Thecommontimingparameters,measGateSourceandaccumulationCycles,arethesameasthe COMP_Bimplementation(seeSection3.2.2.2). Thefollowingsensordefinitiondescribesasensormadeupof6elements,whereeachelementis measuredwiththeROmethodforaperiodof64/SMCLK. conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA2_WDTA, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=GATE_WDTA_SMCLK, .accumulationCycles=WDTA_GATE_64 }; 3.2.2.5.2RO_CSIO_TA0_WDTA Thecommontimingparameters,measGateSourceandaccumulationCycles,arethesameastheCOMPB implementation(seeSection3.2.2.2). Thefollowingsensordefinitiondescribesasensormadeupof6elements,whereeachelementis measuredwiththeROmethodforaperiodof64/SMCLK. conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA0_WDTA, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=GATE_WDTA_SMCLK, .accumulationCycles=WDTA_GATE_64 }; 29 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.2.5.3RO_CSIO_TA2_TA3 Thetimingparametersdefinethetimerintervalthatisthegatetimefortheimplementation.Thetimer moduleprovidesfourdifferentsourcesettings,adividertoscaletheinputsource,andtheinterval,which isa16-bitintegerloadedintothetimercompareregister. measureGateSourceindicatesthetimersource:TxCLK,ACLK,SMCLK,orINCLK.Thisparameteris equivalenttothetimersourceselectbits(TxSSEL)inthetimercontrolregister(TxCTL). Table15.TimerASourceSelectDefinitions Definition Value Source TIMER_TxCLK 0x0000 TxCLK TIMER_ACLK 0x0100 ACLK TIMER_SMCLK 0x0200 SMCLK TIMER_INCLK 0x0300 INCLKorinvertedTxCLK sourceScaleisusedtodividethetimersource.Thisparameterisequivalenttotheinputdividerselectbits (ID)foundinthetimercontrolregister(TxCTL). accumulationCyclesisusedtodefinethetimerinterval.Thisvalueisloadedintothecapture/compare register(TxCCR0). Thefollowingexampledescribesasensormadeupof6elementsandeachelementismeasuredwiththe ROmethodforaperiodof400/SMCLK. conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA2_TA3, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=TIMER_SMCLK, .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=400 }; 30 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2.2.5.4RO_CSIO_TA0_TA1 Thecommontimingparameters,measGateSourceandaccumulationCycles,arethesameasthe RO_CSIO_TA2_TA3implementation. Thefollowingexampledescribesasensormadeupofsixelementsandeachelementismeasuredwith theROmethodforaperiodof400/SMLK. conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA0_TA1, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=amp;key0, .arrayPtr[1]=amp;key1, .arrayPtr[2]=amp;key2, .arrayPtr[3]=amp;key3, .arrayPtr[4]=amp;key4, .arrayPtr[5]=amp;key5, .measGateSource=TIMER_SMCLK, .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=400 }; 3.2.2.5.5RO_CSIO_TA0_RTC ThetimingparametersdefinetheRTCintervalwhichisthegatetimefortheimplementation.TheRTC moduleprovides3differentsourcesettings,adividertoscaletheinputsource,andtheintervalwhichisa 16bitintegerloadedintotheRTCmoduloregister. measureGateSourceindicatesthetimersource:SMCLK,VLOCLKorXT1CLK.Thisparameteris equivalenttothereal-timeclocksourceselectbits(RTCSS)intheRTCcontrolregister(RTCCTL). Table16.RTCSourceSelectDefinitions Definition Value Source GATE_RTC_SMCLK 0x1000 SMCLK GATE_RTC_XCLK 0x2000 XT1CLK GATE_RTC_VLO 0x3000 VLOCLK sourceScaleisusedtodividethetimersource.Thisparameterisequivalenttothereal-timeclockpre- dividerselectbits(RTCPS)foundintheRTCcontrolregister(RTCCTL). accumulationCyclesisusedtodefinethetimerinterval.ThisvalueisloadedintotheRTCmoduloregister (RTCMOD). 31 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Thefollowingexampledescribesasensormadeupofsixelementsandeachelementismeasuredwith theROmethodforaperiodof400/SMLK conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA0_RTC, .inputCapsioctlRegister=(uint16_t*)&conststructSensorkeyPad= { .halDefinition=RO_CSIO_TA0_RTC, .inputCapsioctlRegister=(uint16_t*&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=GATE_RTC_SMCLK, .sourceScale=RTC_DIV_10, .accumulationCycles=40 }; 3.2.2.6RC_PAIR_TA0 TheRCmethodusesthetimerperipheraltomeasurethechargeanddischargetimeoftheRCcircuit. Thismeasurementcanbeincreased(intimeandincounts)byaccumulatingseveralchargeand dischargecyclesasshowninFigure21.Thenumberofcyclesisdefinedintheparameter:sensor- �accumulationcycles. Figure21.RCTimingParameters Thefollowingsensordefinitiondescribesasensormadeupoftwoelementsthataremeasuredwiththe RCmethod.Thegatetimeforeachelementisfourchargeanddischargecycles. conststructSensorscroll= { .halDefinition=RC_PAIR_TA0, .numElements=2, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&left,//pointtofirstelement .arrayPtr[1]=&right,// //TimerInformation .accumulationCycles=4//4charge/dischargecycles }; 32 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration 3.2.2.7fRO_CSIO_TA2_TA3 Thetimingsourceforgatetimer,TIMERA2,ispartoftheHALdefinition.Thesourceforthegatetimercan bescaledwiththesourceScaleparametertoincreasethegatetime,butitisrecommendedtousethe/1 setting.Thegatetimeisafunctionofthescaleandthenumberofoscillationsshownas'n'inFigure22. ThenumberofoscillationsisdefinedbytheparameteraccumulationCycles. Figure22.fRO_CSIO_TA2_TA3TimingParameters ThetimingparametermeasGateSourceisusedtoselecttheclocksourceforthefrequencycounter, TIMERA3.TypicallythissourceisSMCLK,becauseitrepresentsthehighestresolutionclock.Inthe followingcodesnippetthegatetimeforeachelementis50relaxationcycles.ThenumberofSMCLK cycleswithinthatgatetimerepresentsthecapacitance. conststructSensorkeyPad= { .halDefinition=fRO_CSIO_TA2_TA3, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=TIMER_SMCLK, .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=50 }; 33 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.2.8fRO_CSIO_TA0_TA1 Thecommontimingparameters,measGateSourceandaccumulationCycles,arethesameasthe fRO_CSIO_TA2_TA3implementation. Inthefollowingcodesnippet,thegatetimeforeachelementis50relaxationcycles.Thenumberof SMCLKcycleswithinthatgatetimerepresentsthecapacitance. conststructSensorkeyPad= { .halDefinition=fRO_CSIO_TA0_TA1, .inputCapsioctlRegister=(uint16_t*)&CAPSIO0CTL, .numElements=6, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&key0, .arrayPtr[1]=&key1, .arrayPtr[2]=&key2, .arrayPtr[3]=&key3, .arrayPtr[4]=&key4, .arrayPtr[5]=&key5, .measGateSource=TIMER_SMCLK, .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=50 }; 3.2.2.9fRO_PinOsc_TA0_TA1 Thetimingsourceforgatetimer,TIMERA0,ispartoftheHALdefinition.Thesourceforthegatetimercan bescaledwiththesourceScaleparametertoincreasethegatetime,butitisrecommendedtousethe/1 setting.Thegatetimeisafunctionofthescaleandthenumberofoscillationsshownas'n'inFigure23. ThenumberofoscillationsisdefinedbytheparameteraccumulationCycles. Figure23.fRO_PinOsc_TA0_TA1TimingParameters 34 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration ThetimingparametermeasGateSourceisusedtoselecttheclocksourceforthefrequencycounter, TIMERA1.TypicallythissourceisSMCLK,becauseitrepresentsthehighestresolutionclock.Inthe followingcodesnippetthenumberofSMCLKcyclescountedduringthegatetimeof11Krelaxationcycles representsthecapacitance. conststructSensorproximity= { /*GatesourceisINCLKbydefault*/ .halDefinition=fRO_PINOSC_TA0_TA1, .numElements=1, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&eProx, //TimerInformation /*MeasurementSourceisSMCLK*/ .measGateSource=TIMER_SMCLK, /*GateSourcedividedby1*/ .sourceScale=TIMER_SOURCE_DIV_0, .accumulationCycles=11000//NumberofROcycles }; 3.2.2.10fRO_PinOsc_TA0_SW InthecaseofthefRO_PinOsc_TA0_SWimplementation,thevariablegatetimeriscreatedwiththe relaxationoscillatorandtheperipheralTimerAx.Thefrequencycounterisasoftwareloopwitha frequencyofMCLK/10. ThetimingsourcesarepartoftheHALdefinitionthereforetheonlyparametertodefineisthenumberof oscillationsforthegatetime.Thisnumber,shownas'n'inFigure24,isdefinedbythevariable accumulationCyclesatthesensorlevel:sensor-�accumulationCycles. Figure24.fRO_PinOsc_TA0TimingParameters 35 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com 3.2.2.11fRO_COMPB_TA1_TA0 TheCOMP_Bimplementationisfoundinthe5xxand6xxMSP430familiesofdevices.Thesefamiliescan supportclocksspeedsupto25MHz,furtherimprovingthesensitivitydemonstratedinTable4. Thetimingsourceforgatetimer,TIMERA1,ispartoftheHALdefinition.Thesourceforthegatetimercan bescaledwiththesourceScaleparametertoincreasethegatetime,butitisrecommendedtousethe/1 setting.Thegatetimeisafunctionofthescaleandthenumberofoscillationsshownas'n'inFigure25. ThenumberofoscillationsisdefinedbytheparameteraccumulationCycles. Figure25.fRO_COMPB_TA1_TA0TimingParameters 36 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration ThetimingparametermeasGateSourceisusedtoselecttheclocksourceforthefrequencycounter, TIMERA0.TypicallythissourceisSMCLK,becauseitrepresentsthehighestresolutionclock.Inthe followingcodesnippetthenumberofSMCLKcyclescountedduringthegatetimeof10relaxationcycles (perelement)representsthecapacitance. conststructSensorkeypad= { .halDefinition=fRO_COMPB_TA1_TA0, .numElements=5, .baseOffset=0, .cbpdBits=0x001F,//CB0,CB1,CB2,CB3,CB4 .arrayPtr[0]=&element0,//pointtofirstelement .arrayPtr[1]=&element1, .arrayPtr[2]=&element2, .arrayPtr[3]=&element3, .arrayPtr[4]=&element4, .cboutTAxDirRegister=(uint8_t*)&P1DIR,//PxDIR .cboutTAxSelRegister=(uint8_t*)&P1SEL,//PxSEL .cboutTAxBits=BIT6,//P1.6 /* *MeasurementsourceisSMCLK.Thegatesource,TACLK,isfedby *relaxationoscillatorandisdefinedbyHAL. */ .measGateSource=TIMER_SMCLK,//SMCLK .sourceScale=TIMER_SOURCE_DIV_0,//RO/1 /* *Themeasurementtimeisvariableandafunctionoftherelaxation *oscillator.Assuminganuntouchedfrequencyof500Khz,10cycleswould *be20us. */ .accumulationCycles=10 }; 3.2.2.12fRO_COMPB_TAx_SW ThefRO_COMPB_TAx_SWimplementationhasthesamehardwaredescriptionasthe RO_COMPB_TAx_WDTAimplementation(seeSection3.2.2.2).Asalreadymentionedthekeydifference betweentheROandfROmethodsisthatthefrequencycounterandgatetimerinputsareswitched.The gatetimernowisafunctionofthecapacitancebeingmeasuredandthefrequencycounterisfedbya fixedfrequency(asystemclock).InthecaseofthefRO_COMPB_TAx_SWimplementation,thevariable gatetimeriscreatedwiththerelaxationoscillatorandtheperipheralTimerAx.Thegatetimeisasoftware loopwithafrequencyofMCLK/10. ThefastROmethodistypicallyusedindevicesthathavemultipletimersavailable,sothatthefrequency counterfunctionisperformedwithanotherhardwaretimerinsteadofwithasoftwareloop.Thisnotonly decreasespowerconsumption(runninginLPM0insteadofinactivemode),butisalsoremovesthe10x factorassociatedwiththesoftware. Thereisonlyonetimingparameter,accumulationCycles.Figure26showshowtheparameter accumulationCyclesisusedtoaccumulatemultiplerelaxationoscillatorcyclesinthe fRO_COMPB_TAx_SWmethod. 37 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com Figure26.fRO_COMP_B_TAx_SWTimingParameters 3.2.2.13fRO_COMPAp_TAx_SW ThefRO_COMPAp_TAx_SWimplementationshavethesamehardwaredescriptionasthe RO_COMPAp_TAx_WDTpimplementations(seeFigure17).Asalreadymentionedthekeydifference betweentheROandfROmethodsisthatthefrequencycounterandgatetimerinputsareswitched.The gatetimernowisafunctionofthecapacitancebeingmeasuredandthefrequencycounterisfedbya fixedfrequency(asystemclock).InthecaseofthefRO_COMPAp_Tax_SWimplementation,thevariable gatetimeriscreatedwiththerelaxationoscillatorandtheperipheralTimerAx.Thegatetimeisasoftware loopwithafrequencyofMCLK/10. ThefastROmethodistypicallyusedindevicesthathavemultipletimersavailable,sothatthefrequency counterfunctionisperformedwithanothertimerperipheralinsteadofwithasoftwareloop.Thisnotonly decreasespowerconsumption(runninginLPM0insteadofinactivemode),butisalsoremovesthe10x factorassociatedwiththesoftware. 38 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comConfiguration Thereisonlyonetimingparameter;accumulationCycles.Figure27showshowtheparameter accumulationCyclesisusedtoaccumulatemultiplerelaxationoscillatorcyclesinthe fRO_COMPAp_TA0_SWmethod. Figure27.fRO_COMPAp_TA0_SWTimingParameters 3.2.2.14fRO_COMPAp_SW_TAx Therearethreetimingparameters;measureGateSource,sourceScale,andaccumulationCycles.Thegate timerwhichdefinesthemeasurementperiodisdefinedbyaccumulationCycles.Thesoftwareloopcounts therelaxationoscillatorcyclesuntilaccumulationCyclesisreachedandatthistimereadsthetimer,TAx. ThemeasureGateSourceandsourceScaleconfiguretheTAxperipheral.Specificallytheseparameters definethesource(typicallySMCLK)andthetimerdivider(typicallydivideby1). measureGateSourceidentifiestheclocksourceforTAx.ThisparameteristheequivalenttotheTASSELx bitsfoundintheTimerAcontrolregisterTACTL. Table17.measureGateSourceDefinitionsfor fRO_xxxx_SW_Txx Name Definition TimerSource TIMER_TxCLK 0x0000 TxCLK TIMER_ACLK 0x0100 ACLK TIMER_SMCLK 0x0200 SMCLK TIMER_INCLK 0x0300 INCLK 39 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Configurationwww.ti.com sourceScaleisusedtodividethetimersource.Thisisequivalenttotheinputdividerbits(IDx)foundinthe TimerAcontrolregisterTACTL. Table18.sourceScaleDefinitionsfor fRO_xxxx_SW_Txx Name Definition SourceDivider TIMER_SOURCE_DIV_0 0x0000 /1 TIMER_SOURCE_DIV_1 0x0040 /2 TIMER_SOURCE_DIV_2 0x0080 /4 TIMER_SOURCE_DIV_3 0x00C0 /8 accumulationCyclesdefinesthenumberofrelaxationoscillatorcyclespergateperiod.Inthe fRO_COMPAp_SW_TAxmethodthecountingofrelaxationoscillatorcyclesisdonewithasoftwarepolling loopthatlooksforacomparatorinterruptflagtoindicatethatanoscillationhasoccurred. 3.2.2.15fRO_CSIO_TA0_SW InthecaseofthefRO_CSIO_TA0_SWimplementation,thevariablegatetimeriscreatedwiththe relaxationoscillatorandtheperipheralTimerA0.Thefrequencycounterisasoftwareloopwitha frequencyofMCLK/10. Thetimingsourcesarepartofthehaldefinitionthereforetheonlyparametertodefineisthenumberof oscillationsforthegatetime.Thisnumber,shownas'n'inFigure28,isdefinedbythevariable accumulationCyclesatthesensorlevel:sensor-�accumulationCycles. Figure28.fRO_CSIO_TA0_SWTimingParameters 40 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comResources 3.2.3SliderandWheelSpecificSensorVariables ThefollowingdefinitionsareonlyrequiredwiththeuseofAPIfunctionsTI_CAPT_Wheeland TI_CAPT_Slider. ToincludethewheelorsliderAPIwithinthelibrarythefollowingdefinitionsneedtobemadeinthe structure.hfile: /Arewheelorsliderrepresentationsused? //#defineSLIDER #defineWHEEL //Illegalsliderposition.Thisvalueisreturned //whennotouchonthewheelorsliderisdetected. #defineILLEGAL_SLIDER_WHEEL_POSITION0xFFFF Inthestructure.cfilethesensordefinitionsforpointsandsensorThresholdneedtobeadded. Thevariablepointsisusedtodefinethenumberofpointsalongasliderorwheel. sensorThresholddefinesthecumulativeresponserequiredbythesensortodeclareavalidtouch.The intentofthisvariableistodistinguishagenuineinteractionwiththesensorfromanunintentional interactionthatmayactivateonlyoneelement. ThewheelorslidersensorThresholdiscomparedwiththeresponseofthedominantelementandits neighbors(summationofx-1,x,andx+1).Theendpointsofasliderareaspecialcasewhichrequiresa comparisonofonlytheendelement(thedominantelement)andtheoneneighbor.Iftheresponse exceedsthesensorThresholdthenavalidusecaseofthesensorhasbeenvalidatedandthepositionis calculated.Ifnovalidusecaseisdetected,thentheILLEGAL_SLIDER_WHEEL_POSITION,definedin thestructure.hfileisreturned. 4Resources Dependingupontheconfigurationthislibrarycanconsumeseveraldifferentresourcesmakingthem completelyunavailabletothemainapplicationoronlyunavailableduringactualmeasurementcycles. ResourcesthatarecompletelyunavailablearetypicallythedigitalI/Oandallocatedmemoryresources. Thelibrarydoesperformasimplecontextsaveofalltheregistersusedtominimizetheneedforresetting peripherals.ItshouldbenotedthatthecontextsaveisnotextensiveandagoodpracticeistoclearIFG flagsbeforeenablinginterrupts.(1) 4.1Time TheAPIcallsfoundinthelibraryare'blocking'callsanddonotreturntheCPUtotheapplicationuntilafter themeasurementiscomplete.ThedominantfactoronhowlongtheCPUisunavailableisthegatetime. Thistimecaneitherbeanumberofcyclesfromafixed(systemclock)orvariable(relaxationoscillator) clocksource.Table19showssomeexamplegatetimesforvariouscapacitancemeasurementmethods andsettings.Itisimportanttonotethatsensitivityisdirectlyrelatedtothegatetime.Shorteningthegate timeresultsinadecreaseinsensitivity.InthefROmethod,thesensitivitycanbeincreased(whilekeeping theshortergatetime)byincreasingthefixedsystemclockfrequencyasdescribedinSection2.3. (1)AnexplicitexampleofthisiswithTimerA3wheretheLibrarydoesnotuseallthreecaptureandcontrolregistershowever,theCCIFG maybesetwhenthetimerisused. 41 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated Resourceswww.ti.com Table19.GateTimeExamples GateTimeSource IntervalDefinition Time Method (.measGateSource) (.accumulationCycles) (ms) ACLK=VLO§12kHz 64(WDTp_GATE_64) 5.33 RO_XXX_YYY_WDTp SMCLK=2MHz 8192(WDTp_GATE_8192) 4.1 RO_XXX_YYY_WDTA SMCLK=1MHz 512(WDTp_GATE_512) 0.512 RO_PINOSC_TA0 ACLK=VLO§12kHz 100 8.3 Rise+Fall(untouched)§1.4µs 20 0.028+TBD(1) RC_PAIR_XXX Rise+Fall(touched)§1.6µs 20 0.032+TBD RO(untouched)§700kHz 4000 5.71 fRO_COMPx_YYY_SW RO(touched)§600kHz 4000 6.67 RO(untouched)§1.2MHz 4000 fRO_PINOSC_YYY_SW 3.334 RO(touched)§1MHz 4000 RO(untouched)§700kHz 500 0.714 fRO_COMPx_SW_YYY RO(touched)§600kHz 500 0.833 (1)Thisadditionaltimeistheoverheadassociatedwithusingsoftwaretosetupthechargeanddischargeoverseveralcycles. 4.2Memory:FlashandRAM Theamountofcodespaceconsumedbythelibraryisdirectlyafunctionofthenumberofelements,the numberofsensors,themeasurementmethod,andthelevelofabstraction.Table20showsanexampleof howthecodesizeincreaseswithhigherlevelsofabstraction. Table20.ExampleFlashResourceAllocation ConfigurationStructure: Library SixElements,ThreeSensors APICalls (bytes) (RO_PinOsc_TA0_WDTp) Comments TI_CAPT_Raw 376(0x178) 114(0x72) Optimizationlevel0(CCSv5,TIv4.1.2) TI_CAPT_Init_Baseline TI_CAPT_Update_Baseline 1814(0x716) 114(0x72) Optimizationlevel0(CCSv5,TIv4.1.2) TI_CAPT_Custom TI_CAPT_Init_Baseline TI_CAPT_Update_Baseline TI_CAPT_Custom 2478(0x9AE) 120(0x78) Optimizationlevel0(CCSv5,TIv4.1.2) TI_CAPT_Button TI_CAPT_Wheel RAMcanbeallocatedstaticallytomaintainthebaselinetrackingfeature.TheamountofRAMneededisa functionofthetotalnumberofelements:2bytesperelement.Thelibraryusesthe TOTAL_NUMBER_OF_ELEMENTSdefinitiontoindicatethatRAMneedstobeallocatedforthebaseline trackingandhowmuch.WhenusingonlytheTI_CAPT_RAWAPITOTAL_NUMBER_OF_ELEMENTS shouldnotbedefinedandthereforenoRAMresourcesareconsumed. RAMcanalsobeallocatedstaticallyordynamicallytoperformthemeasurementstodetermineachange incapacitance(TI_CAPT_Customandsensorabstractions).IntheeventthattheRAMisallocated statically,thedefinitionRAM_FOR_FLASHmustbemadeinthestructure.hfile.TheamountofRAM spaceallocatedisdependentuponthelargestnumberofelementspersensor,2bytesperelement. AtthecostofadditionalFLASHspace,thisRAMcanbeallocateddynamicallyfromaHEAP.Toallocate theRAMdynamicallytheRAM_FOR_FLASHdefinitionmustbeomitted.TheHEAPsizeneedstobeset (intheIDE)to2bytesplus2bytespernumberofelementsinthelargestsensor. 42 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comResources 4.3SystemClocks Thelibrarydoesnotmakeanyadjustmentstothesystemclocks(MCLK,SMCLK,orACLK)anduses themasdefinedintheapplicationlayerforcapacitancemeasurements.Itisimportanttounderstandthe clockusageofthelibraryinthecontextoftheapplication.Forexample,ifthecapacitancemeasurement timeissetwiththewatchdogtimerintervalto8192/SMCLK,thenchangingthefrequencyofSMCLKinthe applicationalsochangesthemeasurementtimeduringthecapacitancemeasurement.Iftheclocksource forthecapacitancemeasurementischangedinanapplication,thenitisimportanttore-initializethe baselinetrackingaccordingly. 4.4Peripherals Differentcombinationsofperipheralscanusedtomeasurechangesincapacitance.Whilethese peripheralsarenotavailabletotheapplicationduringacapacitancemeasurement,mostoftheperipherals canbesharedormultiplexedintimewithotherapplicationsorfunctions. 4.4.1TimerAandTimerB Thetimerperipheralisreconfiguredandinitializedwitheverymeasurementand,therefore,canbeused forotherfunctionswhenacapacitancemeasurementisnottakingplace. 4.4.2Real-TimeTimer Thereal-timetimercanbeusedasthegatetimerforcapacitymeasurementwhennotusedasthereal- timeclockforthesystem.TheoverflowofRTCcanbeusedtotriggercaptureactiononTimerAinsome deviceswhichmakesitveryconvenientincapacitymeasuring. 4.4.3WatchdogTimer TheWatchdogtimerISRisdefinedwithinthelibraryandincludedwithaprecompilerdirective.This definitionprohibitsusingtheWDTperipheralasatruewatchdog.However,thesourcecodeisprovided andtheISRcanbemodifiedtosupporttheschedulingoftheWDTfordifferenttasksalongwithcapacitive touchatdifferenttimeswithinanapplication. 4.4.4Comparator_AandComparator_B Thecomparatorperipheralisreconfiguredandinitializedwitheverymeasurementandthereforecanbe usedforothertaskswithinanapplicationwhenacapacitancemeasurementisnottakingplace.Itisnot recommendedtoconnectotherinputstothecapacitivesensorelementbecausethismightinterferewith thecapacitancemeasurement. 4.4.5DigitalI/O ItisnotrecommendedtoshareormultiplexfunctionsonI/Opinsthatareusedforcapacitance measurements. 5APICalls Thelibraryprovidesthreedifferentlayersofabstraction.Thelowestlevelofabstractionisthe TI_CAPT_RawAPIfunctioncall.Thisfunctioncallmeasurestheappropriatesensorandprovidestheraw capacitancemeasurementtotheapplicationlayer.TheTI_CAPT_RAWfunctionisthemostpowerfulin thatitallowsthemostflexibilityininterpretationandapplicationofthecapacitancemeasurement. ThenextlevelofabstractionistheTI_CAPT_CustomAPIfunctioncall.ThisAPIcallstheTI_CAPT_Raw functionandalsoincludesabaselinetrackingalgorithm.TheTI_CAPT_CustomAPIprovides,tothe applicationlayer,themagnitudeofchangeofthemeasuredcapacitancefromthebaselinecapacitance. Changesareonlyprovidedtotheapplicationlayerifthechangeisinthedirectionofinterest.The directionofinterestcanbeeitheranincreaseincapacitanceoradecreaseincapacitance.Thedirection ofinterestcanbesetwiththeTI_CAPT_Update_DOIAPI,andthedefaultsettingisanincreasein capacitance.Ifthechangeincapacitanceisagainstthedirectionofinterestthisinformationisusedbythe baselinetrackingbutnotprovidedtotheapplicationlayer. 43 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated APICallswww.ti.com TheTI_CAPT_CustomAPIisintendedforusewithcustomsensordesignsandapplicationsthatarenot supportedbytheotherAPIs.Inthesecustomapplicationsthebaselinetrackingcanstillbeusedbutthe interpretationofthechangeincapacitancemustbehandledintheapplicationcode. ThelevelofabstractionabovetheTI_CAPT_CustomAPI,includesthesensorrepresentationofabutton, groupofbuttons,awheel,andaslider.TheseAPIsareTI_CAPT_Button,TI_CAPT_Buttons, TI_CAPT_Wheel,andTI_CAPT_Slider,respectively.TheseAPIsincludetheinterpretationandapplication oftheTI_CAPT_Customfunction. Table21liststheAPIsofthecapacitivetouchlibrary.InadditiontotheAPIsjustdescribed,thereareAPIs toadjustthebaselinetracking. Table21.CapacitiveTouchLibraryAPIs Title......................................................................................................................................Page uint8_tTI_CAPT_Button(Sensor*);—CapacitanceMeasurement.............................................................45 element*TI_CAPT_Buttons(Sensor*);—CapacitanceMeasurement.........................................................45 uint16_tTI_CAPT_Slider(Sensor*);—CapacitanceMeasurement.............................................................46 uint16_tTI_CAPT_Wheel(Sensor*);—CapacitanceMeasurement.............................................................47 voidTI_CAPT_Custom(Sensor*,uint16_t*);—CapacitanceMeasurement.................................................48 voidTI_CAPT_Raw(Sensor*,uint16_t*);—CapacitanceMeasurement........................................................48 voidTI_CAPT_Init_Baseline(Sensor*);—BaselineTracking...................................................................48 voidTI_CAPT_Update_Baseline(Sensor*,uint8_t);—BaselineTracking....................................................49 voidTI_CAPT_Reset_Tracking(void);—BaselineTracking.....................................................................49 voidTI_CAPT_Update_Tracking_DOI(uint8_t);—BaselineTracking.........................................................49 voidTI_CAPT_Update_Tracking_Rate(uint8_t);—BaselineTracking........................................................50 44 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comuint8_tTI_CAPT_Button(Sensor*);—CapacitanceMeasurement uint8_tTI_CAPT_Button(Sensor*);CapacitanceMeasurement InputsPointertoSensorthatdefinesabutton. Outputs0/1, FunctionMeasurethebutton.A0meansthatthechangeincapacitanceislessthanorequalto thethresholdsetintheelementand1meansthatthechangeincapacitancehas exceededthethreshold. element*TI_CAPT_Buttons(Sensor*);CapacitanceMeasurement InputspointertoSensorthatdefinesgroupofelementswhereeachelementrepresentsa button. OutputsPointertoanelementor0. FunctionMeasurethesensor(buttons)anddeterminewhichbutton,ifany,isbeingtouched.This functionreturnsthepointertotheelementthatexceedsitsthresholdbythelargest margin(%ofthemaxResponse-threshold).Ifnobuttonexceedsitsthreshold,thenthis functionreturnsa0. 45 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated uint16_tTI_CAPT_Slider(Sensor*);—CapacitanceMeasurementwww.ti.com uint16_tTI_CAPT_Slider(Sensor*);CapacitanceMeasurement InputsPointertoSensorthatdefinesgroupofelementswhichmakeupslider. OutputsLocationontheslider;ILLEGAL_SLIDER_WHEEL_POSITION-�Notouch; 0-max-�touchatlocationwheremaxisdefinedintheSensorasthevariablepoints. FunctionMeasurestheelementswithinthesensor.Thisfunctionreturnseitheraninvalidnumber toindicatethatnotouchwasmeasuredoravalidnumberrepresentingthetouch positionalongtheslider. conststructSensorgroup= { .numElements=5, .baseOffset=0, //Pointertoelements .arrayPtr[0]=&element0,//pointtofirstelement .arrayPtr[1]=&element1, .arrayPtr[2]=&element2, .arrayPtr[1]=&element3, .arrayPtr[2]=&element4, .points=100, .sensorThreshold=50 }; AsshowninFigure29,theorderoftheelementswithintheSensorshouldrepresentthe orderoftheelementsalongtheslider.Thefirstelementidentifiedwithinthesensor positionrepresentsthelowestvalue:theouteredgeofthefirstelementintheSensor arrayisposition0.Thelastelementrepresentsthelargestvalue:theouteredgeofthe lastelementinthearrayrepresentstheresolutionnumberfoundintheSensor(points). Figure29.SliderExample 46 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comuint16_tTI_CAPT_Wheel(Sensor*);—CapacitanceMeasurement uint16_tTI_CAPT_Wheel(Sensor*);CapacitanceMeasurement InputsPointertoSensorthatdefinesgroupofelementswhichmakeupwheel. OutputsLocationontheslider,ILLEGAL_SLIDER_WHEEL_POSITION-�Notouch 0-max-�touchatlocationwheremaxisdefinedbySensorstructuredefinition'points' FunctionMeasuretheelementswithinthesensor.Thisfunctionreturnseitheraninvalidnumber toindicatethatnotouchwasmeasuredoravalidnumberrepresentingtheposition alongthewheel. TheorderoftheelementswithintheSensorstructureshouldrepresenttheorderofthe elementsaroundthewheel.Thefirstelementidentifiedwithinthesensorposition representsthelowestvalue:theouteredgeofthefirstelementintheSensorarrayis position0.Thelastelementrepresentsthelargestvalue:theouteredgeofthelast elementinthearrayrepresentsthepointwherethevaluewrapsaround. Figure30.WheelExample Ifnoelementexceedsitsthreshold(setintheelementstructure),thenthisfunction returnsthevalueILLEGAL_SLIDER_WHEEL_POSITION,whichisdefinedinthe structure.hfile. 47 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated voidTI_CAPT_Custom(Sensor*,uint16_t*);—CapacitanceMeasurementwww.ti.com voidTI_CAPT_Custom(Sensor*,uint16_t*);CapacitanceMeasurement InputsPointertoSensorthatdefinesgroupofelementswhichmakeupacustominterfaceand thepointertothearraythatisupdatedwiththeresultsofthemeasurement. OutputsNone FunctionMeasurethechangeincapacitancerelativetothebaseline(capacitancehistory)for eachelementwithinthesensor. TheorderoftheelementswithintheSensorstructurecanbearbitrarybutmustbe understoodbetweentheapplicationandconfiguration.Thefirstelementinthearray correspondstothefirstelementwithintheSensorstructure. Figure31.CustomSliderExample Thisfunctionrequirestheapplicationtoallocateanarraywhichthisfunctioncanfill whencalled.ThistypeofAPIisusefulwhenthefunctionofthesensorneedstobe controlledwithintheapplicationlayerbutthemeasurementandbaselinetrackingcan stillbemanagedbythelibrary. voidTI_CAPT_Raw(Sensor*,uint16_t*);CapacitanceMeasurement InputsPointertoSensorthatdefinesgroupofelementswhichmakeupacustominterfaceand thepointertothearraythatisupdatedwiththeresultsofthemeasurement. OutputsNone FunctionMeasurethecapacitanceofeachelementwithintheSensor.Thisfunctionupdatesthe inputarraywiththetimerrepresentationofcapacitance. TheorderoftheelementswithintheSensorstructureisarbitraryandmustbemanaged bytheapplicationandconfiguration.Thefirstelementinthearraybeingpassed correspondstothefirstelementwithintheSensorstructure. Thisfunctionrequiresthattheapplicationallocateanarraywhichthisfunctioncanfill whencalled.ThistypeofAPIisusefulwhenthefunctionofthesensorandbaseline trackingneedstobecontrolledwithintheapplicationlayerbutthemeasurementcanstill bemanagedbythelibrary. voidTI_CAPT_Init_Baseline(Sensor*);BaselineTracking InputsPointertoSensor. OutputsNone FunctionMeasurethesensoranddirectlyplacemeasuredvaluesintotheassociatedbaseline variables.UsingthisfunctionloadsthemeasurementsintotheRAMspaceforeach elementwithinthesensor.Variousfunctionsautomaticallyaveragethecurrent measurementwiththeexistingbaselinefunctionandmaycauseerroneousperformance untilthetrackingalgorithmreachesasteady-statevaluerepresentativeofthe environment.ItisrecommendedtousethisAPIwhenthestateoftheRAMspaceis unknown,suchasonpowerup. 48 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comvoidTI_CAPT_Update_Baseline(Sensor*,uint8_t);—BaselineTracking voidTI_CAPT_Update_Baseline(Sensor*,uint8_t);BaselineTracking InputsPointertoSensorandthenumberofmeasurementstoaveragewithbaseline. OutputsNone FunctionAveragebaselinewithnumberofmeasurementsdefinedininput.Thepurposeofthis functionistotakemeasurementssolelyforupdatingbaselinevalueforeachelement withinthesensor. voidTI_CAPT_Reset_Tracking(void);BaselineTracking InputsNone OutputsNone FunctionResetthebaselinetrackingsothatthedirectionofinterestisanincreaseincapacitance. Alsoresetthetrackingratessothatthebaselinetrackschangesinthedirectionof interestattheslowsetting(01)andchangesincapacitanceagainstthedirectionof interestatthefastsetting(00).I.e.trackdecreasesincapacitanceatthefastsettingand increasesincapacitanceattheslowsetting. voidTI_CAPT_Update_Tracking_DOI(uint8_t);BaselineTracking InputsThedirectionofinterest. OutputsNone FunctionIftheinputistrue(non-zero),thenthedirectionofinterestisanincreaseincapacitance. Iftheinputis0x00,thenthedirectionofinterestisadecreaseincapacitance.Inmost applicationsthedirectionofinterestisanincreaseincapacitance,becausethe introductionofanobjectwithinafieldcausesanincreaseincapacitance.Insome situationsitisbeneficialtoidentifywhenanobjectispresentandthenchangethe directionofinteresttodetectwhentheobjectisremoved.Thisistypicallyusefulin applicationswheretheobjectisstationaryforlongperiodsoftime. 49 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated voidTI_CAPT_Update_Tracking_Rate(uint8_t);—BaselineTrackingwww.ti.com voidTI_CAPT_Update_Tracking_Rate(uint8_t);BaselineTracking InputsTherateofhowquicklythebaselineadjuststochangesincapacitancethatareinthe directionofinterestandagainstthedirectionofinterest. OutputsNone Table22.UpdateTrackingRateFormat InputValue TrackingRateinDirectionof TrackingRateAgainstDirection Interest ofInterest 00000000b VerySlow Fast 00010000b Slow(Default) Fast(Default) 00100000b Medium Fast 00110000b Fast Fast 00000000b VerySlow Fast 01000000b VerySlow Medium 10000000b VerySlow Slow 11000000b VerySlow VerySlow FunctionUpdatethetrackingratesperTable22. 6EstablishingMeasurementParameters Themeasurementparameters,maxResponse,threshold,andsensorThresholdareimpactedbytiming parametersselectedwithinthesensordefinition.Calibrationisaniterativeprocesswherethesensor parametersarechangedtoprovidetheappropriateresponsebeforethemeasurementparametersare selected. 6.1MeasurementFunctions TheTI_CAPT_Rawfunctiondoesnotuseanyofthemeasurementparametersandcanbeusedto establishathresholdfortheTI_CAPT_Customfunction.TheTI_CAPT_Customrequiresathreshold parametertodisablethebaselinetrackingwhenoneormoreelementswithinasensorexceedthe threshold.Itisimportanttonotethatwiththerawfunction,anincreaseincapacitanceisrepresentedby anincreaseincountswiththeRCandfROmethodsandbyadecreaseincountswiththeROmethod. #include"CTS_Layer.h" unsignedintraw_data[4]; voidmain(void) { ... while(1) { TI_CAPT_Raw(&group,raw_data); __no_operation();//setbreakpointhere } } 50 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comEstablishingMeasurementParameters Table23.ExampleRawResultsWithROMethod ActiveElement(1) raw_data[0] raw_data[1] raw_data[2] raw_data[3] None 394 435 426 367 0(light) 257 424 427 369 0(normal) 137 410 428 371 0(heavy) 110 304 420 371 None 390 435 426 367 1(light) 367 223 408 367 1(normal) 361 165 401 366 1(heavy) 226 117 332 365 None 389 435 425 368 2(normal) 382 349 146 341 None 390 435 426 267 3(normal) 388 421 255 111 (1)Thedifferencebetweenalight,normal,andheavypressisthesurfacearea.Inapplicationswitha finger,asmorepressureisappliedtheendofthefingerflattenscreatingalargersurfacearea. FromTable23,thethresholdforelements0and1canbeestablishedfromthedifferencebetweenthe interactionandnointeraction.Agoodruleofthumbishalfthedifference.Forexample,inthis configurationtoensuredetectionofalighttouchonsensors0and1,thethresholdsare(394-257)/2and (435-223)/2,respectively. 6.2ButtonandButtons DefiningthethresholdvaluefortheTI_CAPT_ButtonandTI_CAPT_Buttonsabstractionscanbedone withtheeithertheTI_CAPT_RaworTI_CAPT_Customfunctions.TheTI_CAPT_Customfunctionis preferredsimplybecausetheinformationisprovidedasamagnitudeofchangeinsteadofarawvalue. TheTI_CAPT_Customfunctionmeasuresthemagnitudeofchangefromthebaselinethatisbeingtracked bythelibrary.Themagnitudeofchangeisonlyreturnedforthedirectionofinterest.Changesinthe oppositedirectionarerepresentedbya0.Inthefollowingcodeexample,thedirectionofinterestisan increasingcapacitance.SeetheTI_CAPT_Update_Tracking_DOIAPIforadescriptiononchangingthe directionofinterest. #include"CTS_Layer.h" // //thresholdsetto'0'instructure.c unsignedintdelta_data[4]; voidmain(void) { TI_CAPT_Init_Baseline(&group); TI_CAPT_Update_Baseline(&group,30); while(1) { TI_CAPT_Custom(&group,delta_data); __no_operation();//setbreakpointhere } } 51 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated EstablishingMeasurementParameterswww.ti.com Table24.ExampleChangeinCapacitanceResultsWithROMethod ActiveElement delta_data[0] delta_data[1] delta_data[2] delta_data[3] None 0 0 0 0 0(light) 130 11 0 0 0(normal) 188 16 0 0 0(heavy) 287 71 0 0 None 0 0 0 0 1(light) 14 205 13 1 1(normal) 30 288 35 2 1(heavy) 222 328 91 2 None 0 0 0 0 2(normal) 3 49 292 24 None 0 0 0 0 3(normal) 0 5 52 243 ThethresholdcalculationfromTable24issimilartothatshownwithTable23,130/2and205/2. APIsthatuseanarrayofelements,liketheTI_CAPT_ButtonsAPI,requirethedefinitionofthe maxResponseparameterinadditiontothethreshold.Withmultipleelementswithinasensor,the maxResponseisusedtonormalizetheresponseofeachelementandidentifywhichelementhasthe dominantresponse.Thepurposeofthenormalizationistoaccountforpossibledifferencesinelement performance.Asanexample,themaxResponseissimplytheresultfromtheheavyinteraction.Keepin mindtherelationshipbetweenthresholdandmaxResponseasdescribedinSection3.1.1. 6.3SensorArrays:WheelsandSliders WiththewheelandsliderAPIs,thethresholdandmaxResponsemeasurementparameterstakeon slightlydifferentmeanings.Thethresholdrepresentstheminimumresponseexpectedastheinteraction first'slides'intotheelementarea.ThemaxResponserepresentsthemaximumreturnastheinteraction slidesacrosstheelement.Thisistypicallyfoundtobethecenteroftheelementwhichhasthelargest areaoverlapbetweentheelementandinteraction.Thefollowingexampledescribeshowtousethe customfunctiontomeasuretheperformanceofaslideranddeterminethevaluesforthethresholdand maxResponsevariables. 52 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comEstablishingMeasurementParameters Figure32.MeasurementExampleofaFour-ElementSensor Ideallythegeometryoftheelectrodesresultsinequivalentnon-zeroresponsesfora,c,d,f,h,andk. Moreimportantly,theresponseshouldbegreaterthan10%ofthecorrespondingmaximumreturn,b,e,g, orj. Table25.MeasurementExampleofaFour-ElementSensor Element threshold maxResponse(1) e0 (a+d)/2 bor(threshold+655),whicheverissmaller e1 (c+f)/2 eor(threshold+655),whicheverissmaller e2 (d+h)/2 gor(threshold+655),whicheverissmaller e3 (f+k)/2 jor(threshold+655),whicheverissmaller (1)InsomegeometrythevaluewithinmaxResponseisnottrulythelargestreturnfromtheelectrodebut thereturnrecordedatthecenteroftheelectrode.Theimportantcriteriaarethattheneighbors(fora sliderorwheel)haveequalreturns. 53 SLAA490D–April2011–RevisedAugust2015 CapacitiveTouchSoftwareLibrary SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated EstablishingMeasurementParameterswww.ti.com Ifthedesignprohibitsmeetingthesecriteria,thenoneshouldconsiderusingtheTI_CAPT_Custom functionandperformingthepositioncalculationswithintheapplicationlayer.IftheTI_CAPT_Custom functionisusedthenonlythethresholdvalueisrequiredasmentionedearlier. Wheelsandslidersalsorequireathirdmeasurementparameterthatispartofthesensorstructure, sensorThreshold.AsdescribedinFigure33,thesensorThresholddefinesthevalidareaofthewheelor slider.Agoodstartingvalueforawheelis15.Decreasingthisvalueincreasesthearea,buttheaccuracy isafunctionofhowcloselytheinteractionistothecenterline.Conversely,increasingthisvaluereduces theareaofinteractionmorecloselytothecenterlineofthewheel.Thesliderisaspecialcaseofthe wheelinthattheendpointspresentadiscontinuityinthesensorThresholdcalculation.Forslidersitis recommendedtosetthesensorThresholdto0,otherwisetheendsoftheslidercanbetruncated. Figure33.ValidSliderLocationsasaFunctionoftheSensorThreshold 54 CapacitiveTouchSoftwareLibrary SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated AppendixA SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription ThefunctionsfoundinCTS_Layer.candCTS_Layer.hcanbedividedupintofourgroups:Status/Baseline ControlRegister,baselinetracking,measurementfunctions,andsensorabstraction. A.1Status/BaselineControlRegister Astatuscontrolregister,showninFigure34,isprovidedwithinthecapacitivetouchlayerandservesas aninterfacebetweentheapplicationandthelibraryforcontrollingthebaselinetracking.TheEVNTand PAST_EVNTfieldsarenotintendedtobeusedbytheapplicationbutareusedwithinthecapacitivetouch layertoperformvariousfunctions.TheDOI,TRADOI,andTRIDOIfieldsareintendedtobeaccessedby theapplicationandthefollowingAPIsareprovidedfordoingso:TI_CAPT_Update_Tracking_DOI()and TI_CAPT_Update_Tracking_Rate(). uint16ctsStatusReg=0; Figure34.Status/BaselineControlRegister(RAM) 15 14 13 12 11 10 9 8 Unused 7 6 5 4 3 2 1 0 TRADOI TRIDOI Unused PAST_EVNT DOI EVNT Table26.Status/BaselineControlRegisterDescription Bit Field Description 15-8 Unused Unused 7-6 TRADOI Trackingrateagainstdirectionofinterest 00=Veryslow 01=Slow 10=Medium 11=Fast 5-4 TRIDOI Trackingrateindirectionofinterest 00=Veryslow 01=Slow 10=Medium 11=Fast 3 Unused Unused 2 PAST_EVNT Pastevent.Aneventoccurredonthepreviousscan. 0=Noeventoccurredonthepreviousscan 1=Aneventoccurredonthepreviousscan 1 DOI Directionofinterest 0=Decreasingcapacitance 1=Increasingcapacitance 0 EVNT Event.Oneoftheelementsinthegrouphasdetectedathresholdcrossing. 0=Noeventhasoccurred 1=Aneventhasoccurred 55 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated BaselineTrackingwww.ti.com A.2BaselineTracking Baselinetrackingisoneofthemainfeaturesofthecapacitivetouchlayer.Thebaselinecapacitanceis followedortrackedtoaccountforanyenvironmentalchangesthatimpactthemechanismusedtomake thecapacitancemeasurement.ThisincludesbutisnotlimitedtoVCC,temperature,andhumidity. A.2.1DirectionofInterest TherepresentationofanincreaseincapacitanceisanincreaseincountsfortheRCandFastROmethods whileadecreaseincountsintheROmethod.Thepurposeofidentifyingadirectionofinterestisto establishiftheapplicationislookingforanincreaseordecreaseincapacitance.Inmosthumaninterface applicationsthedirectionofinterestisanincreaseincapacitance.Thepresenceofafingerortouch increasesthecapacitanceofanelement.Increasesincapacitancecanalsobecausedbyenvironmental factorsbuttheassumptionisthatthesechangesarerelativelyslowincomparisontotheinteractionwitha person.Changesincapacitancethatareinthedirectionofinterestbutarenotlargeenoughinmagnitude toexceedthethresholdmaybechangesduetotheenvironment.Thisrequiresanupdateinthebase capacitance.Toinsurethatthesechangesarenotduetoaslowmovingobject,itisrecommendedto makeadjustmentsinthedirectionofinterestveryslowly.Thetradeoffinchoosingtheadjustmentrateis accountingforslowmovingobjectsandrapidenvironmentalchanges. Capacitancechangesthatareagainstthedirectionofinteresttypicallyrepresentonlyachangeinthe environment.Becausethechangecanbeattributedtotheenvironmentwithoutanyambiguitythebaseline canbeadjustedmoredramaticallytoaccountfortheshift. A.2.2ExamplesofDirectionofInterest Anapplicationneedstodetectwhenablockofwoodisinplaceandthenremoved.Theblockistypically leftinplaceforseveraldays.Thedirectionofinterestisanincreaseincapacitancetoidentifywhenthe blockisinplaceandthenthedirectionofinterestischangedtoadecreaseincapacitancetoidentifywhen theblockhasbeenremoved.Oncetheblockisinplaceanyadditionalincreaseincapacitanceistreated asachangeagainstthedirectionofinterestandthebaselineisupdatedaccordingly.Inthesameway, aftertheblockisremoved,ifthereisadecreaseincapacitancethisistreatedasachangeagainstthe directionofinterest. A.2.3UpdatingtheBaselineCapacitance Figure35showshowbaselineupdatesoccurwhenthechangeincapacitanceisagainstthedirectionof interestorundercertainconditionswhenthechangeofcapacitanceisinthedirectionofinterest. Achangeincapacitancethatisinthedirectionofinterestmustmeettwocriteriabeforeitisappliedtothe baselinetracking.Firstitmustbelessthanthethresholdandsecondnoeventwithinthesensorcan occur.Achangeincapacitancethatexceedsthethresholdindicatesanevent.Whenaneventoccursitis possiblethattheotherelementswithinthesensorareexcitedevenifonlybyaverysmallamount.The pasteventflag,PAST_EVNT,indicatesthatoneoftheelementswithinasensorhasexperienceda thresholdcrossing.ThereforeifthePAST_EVNTflagistruewithinasensoritisimportanttosuspend baselineupdatesinthedirectionofinterest. Whenthechangeisagainstthedirectionofinterestitislimitedinmagnitudetothethreshold/2before beingappliedtothebaseline. Table27andTable28showhowthecurrentcapacitancemeasurementandthebaselineareweightedto determinethenewbaseline.Thedefaultsettingofthelibraryarethe'fast'settingforchangesagainstthe directionofinterestand'slow'forchangesinthedirectionofinterest. 56 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comBaselineTracking Figure35.BaseCapacitanceUpdate Table27.TrackingSettingsAgainstDirectionofInterest Setting Description RO(measbase) RC,FastRO(meas�base) 3 Fast base=meas/2+base/2 base=meas/2+base/2 2 Medium base=meas/4+3*base/4 base=meas/4+3*base/4 1 Slow base=meas/64+63*base/64 base=meas/64+63*base/64 0 VerySlow(Default) base=meas/128+127*(base/128) base=meas/128+127*(base/128) Table28.TrackingSettingsinDirectionofInterest Setting Description RO(measbase) RC,FastRO(meas�base) 3 Fast base=meas/2+base/2 base=meas/2+base/2 2 Medium base=meas/4+3*base/4 base=meas/4+3*base/4 1 Slow(Default) base=base–2 base=base+2 0 VerySlow base=base–1 base=base+1 57 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated MeasurementFunctionswww.ti.com A.3MeasurementFunctions A.3.1DeltaMeasurement+BaseCapacitanceTracking:CustomAPICall The'custom'APImeasuresthechangeincapacitancefortheelementsofagivenstructure.Theinputsfor thecustomAPIfunctionarethepointertothesensorandapointertothefirstelementofthearrayin whichthecapacitancechangeisrecorded.ThecustomAPIcallmeasuresthecapacitanceofeach elementwiththe'raw'function. A.3.1.1DeltaCalculation TheHALdefinition(hal_definition)andthedirectionofinterestdeterminethedeltacalculation.The hal_definitionsarearrangedsothatallvalueslessthan64aremethodswho'scountvaluesdirectlyrelate tothechangeincapacitance(thatis,anincreaseincountsmeansanincreaseincapacitance)whenthe hal_definitiongreaterthan64relateinversely(thatis,anincreaseincapacitanceresultsinadecreasein counts).WiththeRCandFastScanROmethodsanincreaseincapacitanceisindicatedbyanincrease incounts.ConverselywiththeROmethod,anincreaseincapacitanceisindicatedbyadecreasein counts. ThedeltacalculationperformedwithinthecustomAPIresultsineithera0ornon-zerovalue.Thenon- zerovalueissimplythedifferencebetweenthemeasuredcapacitanceandthebaselinecapacitanceofa givenelement.A0valueindicatesthatthechangeincapacitanceisopposite(against)thedirectionof interest. Figure36.DeltaMeasurementBlockDiagram 58 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comMeasurementFunctions A.3.2RawCapacitanceMeasurement:RawAPICall ThesinglepurposeoftheRAWmeasurementfunctionistocalltheappropriateHALfunctionbasedupon theuserconfiguration.ThisfunctionupdatestheRAMvariablesprovidedwithinthefunctioncall,whichis usedbythehigherlevelcallingfunction. The'Raw'featurecallstheappropriateHALfunction.TheHALdefinitionforagroupofelementsisfound inthesensorstructure. sensor0.halDefinition Thehal_definitionrepresentsacombinationofMSP430peripheralstoaccomplishthecaptouchfunction. Table29.ExampleHALDefinitions Name Type Number Measurement Measurement GateTimer Hardware Timer RC_PAIR_TA0 RC 1 DigitalI/O TimerA0 SW fRO_PINOSC_TA0_SW fRO 25 DigitalI/O SW TimerA0 fRO_COMPB_TA1_TA0 fRO 31 COMP_B TimerA0 TimerA1 RO_COMPAp_TA0_WDTp RO 64 COMP_A+ TimerA0 WDTp RO_PINOSC_TA0_WDTp RO 65 DigitalI/O TimerA0 WDTp A.4SensorAbstractions A.4.1Button,Buttons uint8_tTI_CAPT_Button(Sensor*); Inputs:pointertoSensorthatdefinesbutton Outputs:0/1, Function:Measurethebutton.A0meansthatthechangeincapacitanceislessthanorequaltothe thresholdsetintheSensorand1meansthatthechangeincapacitancehasexceededthethreshold. Figure37.SingleButtonAlgorithm 59 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated SensorAbstractionswww.ti.com Element*TI_CAPT_Buttons(Sensor*); Inputs:pointertoSensorthatdefinesgroupofelementswhereeachelementrepresentsabutton Outputs:pointertoanelementstructure Function:Thisfunctionreturnisthestructurepointertotheelementthatexceedsitsthresholdbythe largestmargin:normalizedto(maxResponse-thresholdvalue)foreachelement.Ifnobuttonexceedsits threshold(setintheelementstructure),thenthisfunctionreturnsa0or'NullPointer'. Figure38.ArrayofButtonsAlgorithm A.4.2SliderandWheel Awheelorsliderisasensortypeconsistingofanarrayofelements.Thesensorisdividedintoanumber ofpointsdefinedbytheuser.Theorientationofthearray(firsttolast)islefttotheinterpretationofthe application.Fromtheperspectiveofthelibrarythefirstelementwithinthearraydefinitioncorrespondsto the0valueonthesliderandthelastelementcorrespondstothenumberofpointsdefinedbytheuser. ThealgorithmforthesliderandwheelfunctionsisshowninFigure39.TheTI_CAPT_Customfunctionis usedtomeasurethechangeincapacitanceforeachelementdefinedinthesensor.Thisfunctionalso updatesthebaselinetrackingandtheeventflagstatus(seeSectionA.3.1) Anadditionaldetectionmechanismisprovidedatthesensorlevelforwheelsandsliders.Theeventflagis themeanstodetermineathresholdcrossingattheelementlevelwhilethesensorThresholdvariable providesathresholdatthesensorlevel.Theintentofthismechanismistodistinguishagenuine interactionwiththesensorfromanunintentionalinteractionthatmayactivateonlyoneelement. Finallythesliderandwheelfunctionscalculatethepositionwheretheinteraction(touch)takesplace.The sliderandwheelrequirefourtypesofconfigurationparameterstopresentalocation.Thesefour parametersarethenumberofresolvablepoints,thesensorlevelthreshold,theelementlevelthresholdfor eachelement,andthemaximumresponseforeachelement. 60 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comSensorAbstractions Figure39.SliderandWheelAlgorithm 61 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated SensorAbstractionswww.ti.com A.4.2.1SliderDetection TheslidersensorThresholdisacomparedwiththeresponseofthedominantelementanditsneighbors. AsshowninFigure40,Theendpointsareaspecialcasewhichrequiresacomparisonofonlytheend element(thedominantelement)andtheoneneighbor. Figure40.SliderThresholdDetection Astheinteractionmoves(slides)beyondthecenterofthelastelementthecontributionfromtheneighbor goesto0andthethresholdofthesensorisonlyafunctionofthelastelement.Thereforethe sensorThresholddefineshowfarthefingercandeviatefromthecenterpositionoftheendsandstillbea partoftheslider.AslongasthesensorresponseexceedsthesensorThreshold,thepositioniscalculated. A.4.2.2SliderPosition Calculationofthesliderpositionispredicateduponpassingthesensorthresholdcriteria.Ifthecriterionis notmet,thenthefunctionsimplyreturnsapredefinedvaluetoindicatenointeractionwasdetected.When thereisavalidinteraction,thefunctiondeterminesthepositionfromtheresponseofthedominantelement anditsnearestneighbors.Thedominantelementfunctiondeterminesthemiddleelementforestablishing a'base'positionwhileoneortwoneighboringelementsareusedtopullorweightthefinalposition.Inthe exampleinFigure41,thesliderhas64positionsandtherearefourelementsinthesliderarray. 62 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comSensorAbstractions Figure41.SliderandWheelProcessMiddleAlgorithm Inthespecialcasewherethedominantelementiseitherthebeginningorendelementoftheslider,then onlythenearestneighborisusedtoweightorinfluencetheposition. Figure42.SliderAlgorithm:BeginningofSlider 63 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated SensorAbstractionswww.ti.com Figure43.SliderAlgorithm:EndOfSlider A.4.2.3WheelDetection ThewheelsensorThresholdisacomparedwiththeresponseofthedominantelementanditsneighbors (summationofx-1,x,andx+1).Theendpointsareaspecialcasewhichrequiresthe'wraparound'tobe accountedfor,seeFigure44.Oncethenormalizedresponsesofthesethreeelementsareaddedthenthe valueiscomparedwiththesensorThreshold.Ifthethresholdisexceeded,thenthefunctioncontinueson tocalculatetheposition. Figure44.WheelThresholdDetection 64 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comSensorAbstractions A.4.2.4WheelPosition Aspreviouslymentionedthewheelissimplyaspecialcaseoftheslider.Additionalhandlingneedstobe putinplacetoaccountforthe'wraparound'fromtheendofthearraybacktothebeginning.Figure45 andFigure46showthealgorithmforcalculatingthepositionwhenthedominantelementisthebeginning andendelementsofthearray, Figure45.WheelAlgorithm:Beginning 65 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated SensorAbstractionswww.ti.com Figure46.WheelAlgorithm:Ending 66 CTS_Layer.candCTS_Layer.hDetailedDescription SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated www.ti.comDominantElementIdentification A.5DominantElementIdentification Theidentificationofathresholdcrossingactuallytakesplaceinthebasecapacitanceupdatefunction(see SectionA.3.1).Whenathresholdcrossingeventhasoccurredthenthefollowingisusedtodeterminethe dominantelementwithinthesensorstructureandscaletheresponsetoarangefrom0to100.Azero indicatesthattheresponseisequaltothethreshold,andavalueof100indicatesaresponseequaltothe maxResponse. Figure47.DominantElementIdentificationFunction 67 SLAA490D–April2011–RevisedAugust2015 CTS_Layer.candCTS_Layer.hDetailedDescription SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated RevisionHistorywww.ti.com RevisionHistory ChangesfromAugust10,2014toAugust20,2015.......................................................................................................Page •AddedmissingcrossreferencetoTable19..........................................................................................41 •AddedmissingcrossreferencetoTable20..........................................................................................42 •AddedmissingcrossreferencetoTable23..........................................................................................51 •AddedmissingcrossreferencestoTable24andTable23........................................................................52 •UpdatedFigure34andTable26,Status/BaselineControlRegister(RAM).....................................................55 NOTE:Pagenumbersforpreviousrevisionsmaydifferfrompagenumbersinthecurrentversion. 68 RevisionHistory SLAA490D–April2011–RevisedAugust2015 SubmitDocumentationFeedback Copyright©2011–2015,TexasInstrumentsIncorporated IMPORTANTNOTICE TexasInstrumentsIncorporatedanditssubsidiaries(TI)reservetherighttomakecorrections,enhancements,improvementsandother changestoitssemiconductorproductsandservicesperJESD46,latestissue,andtodiscontinueanyproductorserviceperJESD48,latest issue.Buyersshouldobtainthelatestrelevantinformationbeforeplacingordersandshouldverifythatsuchinformationiscurrentand complete.Allsemiconductorproducts(alsoreferredtohereinas“components”)aresoldsubjecttoTI’stermsandconditionsofsale suppliedatthetimeoforderacknowledgment. TIwarrantsperformanceofitscomponentstothespecificationsapplicableatthetimeofsale,inaccordancewiththewarrantyinTI’sterms andconditionsofsaleofsemiconductorproducts.TestingandotherqualitycontroltechniquesareusedtotheextentTIdeemsnecessary tosupportthiswarranty.Exceptwheremandatedbyapplicablelaw,testingofallparametersofeachcomponentisnotnecessarily performed. TIassumesnoliabilityforapplicationsassistanceorthedesignofBuyers’products.Buyersareresponsiblefortheirproductsand applicationsusingTIcomponents.TominimizetherisksassociatedwithBuyers’productsandapplications,Buyersshouldprovide adequatedesignandoperatingsafeguards. TIdoesnotwarrantorrepresentthatanylicense,eitherexpressorimplied,isgrantedunderanypatentright,copyright,maskworkright,or otherintellectualpropertyrightrelatingtoanycombination,machine,orprocessinwhichTIcomponentsorservicesareused.Information publishedbyTIregardingthird-partyproductsorservicesdoesnotconstitutealicensetousesuchproductsorservicesorawarrantyor endorsementthereof.Useofsuchinformationmayrequirealicensefromathirdpartyunderthepatentsorotherintellectualpropertyofthe thirdparty,oralicensefromTIunderthepatentsorotherintellectualpropertyofTI. ReproductionofsignificantportionsofTIinformationinTIdatabooksordatasheetsispermissibleonlyifreproductioniswithoutalteration andisaccompaniedbyallassociatedwarranties,conditions,limitations,andnotices.TIisnotresponsibleorliableforsuchaltered documentation.Informationofthirdpartiesmaybesubjecttoadditionalrestrictions. ResaleofTIcomponentsorserviceswithstatementsdifferentfromorbeyondtheparametersstatedbyTIforthatcomponentorservice voidsallexpressandanyimpliedwarrantiesfortheassociatedTIcomponentorserviceandisanunfairanddeceptivebusinesspractice. TIisnotresponsibleorliableforanysuchstatements. Buyeracknowledgesandagreesthatitissolelyresponsibleforcompliancewithalllegal,regulatoryandsafety-relatedrequirements concerningitsproducts,andanyuseofTIcomponentsinitsapplications,notwithstandinganyapplications-relatedinformationorsupport thatmaybeprovidedbyTI.Buyerrepresentsandagreesthatithasallthenecessaryexpertisetocreateandimplementsafeguardswhich anticipatedangerousconsequencesoffailures,monitorfailuresandtheirconsequences,lessenthelikelihoodoffailuresthatmightcause harmandtakeappropriateremedialactions.BuyerwillfullyindemnifyTIanditsrepresentativesagainstanydamagesarisingoutoftheuse ofanyTIcomponentsinsafety-criticalapplications. Insomecases,TIcomponentsmaybepromotedspecificallytofacilitatesafety-relatedapplications.Withsuchcomponents,TI’sgoalisto helpenablecustomerstodesignandcreatetheirownend-productsolutionsthatmeetapplicablefunctionalsafetystandardsand requirements.Nonetheless,suchcomponentsaresubjecttotheseterms. NoTIcomponentsareauthorizedforuseinFDAClassIII(orsimilarlife-criticalmedicalequipment)unlessauthorizedofficersoftheparties haveexecutedaspecialagreementspecificallygoverningsuchuse. OnlythoseTIcomponentswhichTIhasspecificallydesignatedasmilitarygradeor“enhancedplastic”aredesignedandintendedforusein military/aerospaceapplicationsorenvironments.BuyeracknowledgesandagreesthatanymilitaryoraerospaceuseofTIcomponents whichhavenotbeensodesignatedissolelyattheBuyer'srisk,andthatBuyerissolelyresponsibleforcompliancewithalllegaland regulatoryrequirementsinconnectionwithsuchuse. TIhasspecificallydesignatedcertaincomponentsasmeetingISO/TS16949requirements,mainlyforautomotiveuse.Inanycaseofuseof non-designatedproducts,TIwillnotberesponsibleforanyfailuretomeetISO/TS16949. Products Applications Audio www.ti.com/audio AutomotiveandTransportation www.ti.com/automotive Amplifiers amplifier.ti.com CommunicationsandTelecom www.ti.com/communications DataConverters dataconverter.ti.com ComputersandPeripherals www.ti.com/computers DLP®Products www.dlp.com ConsumerElectronics www.ti.com/consumer-apps DSP dsp.ti.com EnergyandLighting www.ti.com/energy ClocksandTimers www.ti.com/clocks Industrial www.ti.com/industrial Interface interface.ti.com Medical www.ti.com/medical Logic logic.ti.com Security www.ti.com/security PowerMgmt power.ti.com Space,AvionicsandDefense www.ti.com/space-avionics-defense Microcontrollers microcontroller.ti.com VideoandImaging www.ti.com/video RFID www.ti-rfid.com OMAPApplicationsProcessors www.ti.com/omap TIE2ECommunity e2e.ti.com WirelessConnectivity www.ti.com/wirelessconnectivity MailingAddress:TexasInstruments,PostOfficeBox655303,Dallas,Texas75265 Copyright©2015,TexasInstrumentsIncorporated