signal processing in soware and electric field sensing · electric field sensors: applicaons •...
TRANSCRIPT
SignalProcessinginSo.wareandElectricFieldSensingCSE466:So.wareforEmbeddedSystems
Winter2009
B.Mayton<[email protected]>UniversityofWashingtonCSE&IntelResearchSeaMle
CSE466Winter2009 1ElectricFieldSensing
Labs3and4:BuildingaSensor
• You’llbuildanelectricfieldsensorwithbasiccomponentsandyourAVRmicrocontroller– Cansenseyourhandabovetheboardwithoutactuallytouchingit
– Transmitandreceivesignalsaregeneratedanddemodulatedinso.ware
– WillsendthesensorreadingstoaPCforfurtherprocessingandmovingaroundinacolorspace
CSE466Winter2009 2ElectricFieldSensing
E‐FieldSensinginNature
• Generatesanelectricfieldaround1kHz
• UsesE‐fieldtodetectprey,avoidobjects,andcommunicate
CSE466Winter2009 ElectricFieldSensing 3
BlackGhostKnifefish(Apteronotusalbifrons)
ElectricFieldSensors:Applicacons
• CSE466Winter2008– added4‐channelE‐fieldsensor(the“AirScck”)totheiMote2toallowcontrolofasoccerplayerinamulcplayergame
CSE466Winter2009 ElectricFieldSensing 4
ElectricFieldSensors:Applicacons
• PersonalRoboccsatIntelResearchSeaMle
CSE466Winter2009 ElectricFieldSensing 5
• E‐Fieldaddssenseof“Pretouch”toarobothandandarm,allowingittodetectthatitisclosetoobjectswithouttouchingthem
TheoryofOperacon
• CreateanACelectricfieldwithconstantamplitudewithtransmitelectrode
• Measurecurrentinducedinreceiveelectrode• Nearbygroundedobjectsshuntsomecurrenttoground,reducingthereceivedcurrent.
CSE466Winter2009 ElectricFieldSensing 6
TransmitReceive
Objectinrangeofsensor
PartsoftheSensor
CSE466Winter2009 ElectricFieldSensing 7
TransmitAntennaReceiveAntenna
AnalogFront‐EndTransmitResonator
WaveformGeneracon(Timer0OutputCompare)
Sampling(ADC)
Demodulacon(So.ware)
TransmiknganElectricField
• UsecmerhardwareonAVRtogenerateasquarewave;frequencycanbetunedwithprescalervalueandoutputcomparevalue
• Resonatorcircuitboosts5Vsquarewavetoasinewavewithanamplitudeofaround100V
• TransmitinthetensofkHzrange;higherfrequenciesworkbeMerbutgivelesscmetoprocessinterrupts
CSE466Winter2009 ElectricFieldSensing 8
ResonantCircuits
• Drivingaresonantcircuitwithsmallamountsofenergyattherightcmes(attheresonantfrequency)willcausehigh‐amplitudeoscillacons
CSE466Winter2009 ElectricFieldSensing 9
• TheLCresonatoronthesensorboardallowstheAVRtocreatealargeelectricfieldfromasupplyofonly5V
• TheresonantfrequencyofanLCcircuitis
€
f =1
2π LC
AmplifyingtheReceivedSignal
• Transimpedanceamplifierconvertscurrentflowingintoreceivedelectrodeintovoltage
• VoltagegainstageamplifiesthesignaltolevelsthatworkwellwiththeADCintheAVR
CSE466Winter2009 ElectricFieldSensing 10
OperaconalAmplifiers
• Veryuseful,versacle,andubiquitousanalogcircuitdevices– amplifyvoltages– canturnhigh‐impedancesignalsintolow‐impedancesignals(weaksignalsintorobustsignals)
– performmathemaccaloperaconsonsignalsintheanalogdomain(usedtobehowmostsignalprocessingwasdone)
• Signalprocessinghasmovedintothedigitaldomain,butopampsaresclluseful,parccularlywhenitcomestointerfacingsensorswithmicrocontrollers
CSE466Winter2009 ElectricFieldSensing 11
OperaconalAmplifiers
• Twoinputterminals:invercng(‐)andnon‐invercng(+)– almostnocurrentflowsintotheinputs
(theyarehighimpedance)• Voltageatoutputterminalisthe
differencebetweenthetwoinputsmulcpliedbysomegain
• Outputchangestotrytokeepthevoltagesatbothinputsequaltoeachother
• Outputislowimpedance:wecandrawsomecurrentfromitwithoutaffeccngitsvoltagesignificantly
CSE466Winter2009 ElectricFieldSensing 12
TheAnalogFront‐End
• Nowthatweknowaboutopamps,we’lllookatthetwostagesoftheanalogfront‐end.
• AGNDisat2.5V;thiswilladdaDCoffsettotheoutputvoltage,bringing“zero”intothemiddleofourusablerangefortheADC
CSE466Winter2009 ElectricFieldSensing 13
TheTransimpedanceAmplifier
• Convertscurrententeringthereceiveelectrodeintoavoltagesignal– Whennocurrentisflowinginfromthele.,thereisnovoltagedropacrosstheresistor,andtheoutputvoltagewillbethesameasthetwoinputterminals.
CSE466Winter2009 ElectricFieldSensing 14
0µA
0V+ ‐
2.5V2.5V
TheTransimpedanceAmplifier
• Convertscurrententeringthereceiveelectrodeintoavoltagesignal– Currententeringfromthe
le.can’tgointotheinvercnginput,soitgoesthroughR3andcreatesavoltagedrop
– Inordertokeepthevoltageattheinvercnginputequaltothenon‐invercnginput,theoutputvoltagemustbedecreased
CSE466Winter2009 ElectricFieldSensing 15
1µA
1V+ ‐
2.5V1.5V
TheVoltageAmplifier
• Amplifies(andinverts)theinputvoltage.
• Basicinvercngop‐ampconfiguracon
• Outputvoltageforthecircuitattherightis
CSE466Winter2009 ElectricFieldSensing 16
€
vout = −vinR5R4
Wherearewenow?
• We’vecreatedanelectricfieldandit’sinducedacurrentinourreceiveelectrode.
• We’veamplifiedthereceivedsignalandbroughtitintoausablerangeforourAVR’sADCtosample.
• Now,weneedtomakesenseofthesignal
CSE466Winter2009 ElectricFieldSensing 17
Demodulacon
• We’llbereceivingoursignal,buttherewillalsobealotofnoise.
• Needtorecovertheamplitudeofoursignal,butignorethenoise.
CSE466Winter2009 ElectricFieldSensing 18
Demodulacon:BasicIdea• Insteadofonesample,we’ll
accumulatemulcplesamplesinanintelligentmanner.
• Sampleatmulcplepointsonthereceivedwaveform
• Ifweaddsampleswhenwe’retransmikngaposicvesignalandsubtractsignalswhenwe’retransmikngnegacvesignal,wecanceloutalotofunwantednoise(andtheDCoffset)
• Accumulateabout20to255samplesforameasurement
• Resultofaccumulaconrepresentsamplitude
CSE466Winter2009 ElectricFieldSensing 19
+ ‐ + ‐ ...
Whataboutphaseshi.s?
• Ifthesamplesaren’tperfectlyinphasewiththereceivedwaveform,we’remissingoutonsignal‐to‐noise
• Gekngperfectlylinedupisdifficult—athightransmitfrequencies,evenoneinstrucconcycleshi.sthesamplebyquiteabit
• Solucon:alsosampleat90˚and270˚inaddiconto0˚and180˚,inaseparateaccumulator
• Theaccumulatorfor0˚and180˚isthein‐phasecomponent,andthe90˚and270˚accumulatoristhequadraturecomponent
• Wecannowrecoverthemagnitudeofthereceivedsignalregardlessofitsphase:
CSE466Winter2009 ElectricFieldSensing 20
€
magnitude = inphase2 + quad2
TimingIssues• TheADCisn’tfastenoughtomakeallthesesamplesonevery
periodofthereceivedwaveform.• Liningupthesampleswiththerightpartsofthewaveformisa
challenge.
CSE466Winter2009 ElectricFieldSensing 21
• TheADCtakessomecmetoperformconversions,buttheactualsample‐and‐holdwindowisshortandcanbepreciselyplaced.
• WecanmaketheADC’ssamplessynchronouswiththetransmiMedwaveformbyusingfree‐runningmodeandseknguptheprescalerssothattheADCsampleseveryn+¼periodsofthetransmiMedwaveform.
but...
Timing• Theresultisthatwe’reonly
samplingeveryfewperiodsofthewaveform,butwestaylinedupbecausewe’reusingthesameclockforthetransmiMedsignalandtheADC.
• SincewesetuptheADCtosampleeveryn+¼periodsofthetransmiMedwaveform,eachsamplewillbeoffsetby90˚.
• Eachsetoffoursamplesgivesustheposicveandnegacvevaluestoaddtoeachofourtwoaccumulators.
CSE466Winter2009 ElectricFieldSensing 22
ImplementaconinLabs3and4• Forlabs3and4,youwill:
– calculateprescalerandoutputcomparevaluestoenablesynchronousundersamplinganddemodulacon
– calculatethecapacitorvalueneededtomakethetransmiMerresonantatyourtransmitfrequency
– buildthee‐fieldsensorhardware– useSPIandUSBtosendthevaluesofthein‐phaseandquadrature
accumulatorstoaPC– usethePCtocomputethemagnitudeofthereceivedwaveformfrom
itscomponents– usethevaluefromthesensorasavirtualknobtomovearoundina
colorspace– displayacolorwheelindicacngthecurrentcoloronthePCscreen,and
senditbacktoyourAVRtobedisplayedonyourtri‐colorLED
CSE466Winter2009 ElectricFieldSensing 23