CircuitCellarINK®Issue97August19981www.circuitcellar.comBitScopeFEATUREARTICLENormanJacksonsHasyourofficebecomesoclutteredthatyoucan’tfindyouroscilloscopeorlogicanalyzer?Noproblem,Normanwillhelpyoubuildalow-cost,mixed-signalcaptureenginethatconnectstoyourcomputerviatheserialport.ometimeago,Ihadabadexperi-encewithabus—alogicbus.Ithadsixram-pagingDSPcardsandaSCSIcontrol-leralltryingtorideatthesametime.Aboutonceanhour,therewasasickeningcrash.Aftergoingthroughtheusualstagesofblamingthesoft-ware,Irelented,admittedpossibleculpability,andborrowedamixed-modeDSO.Thismachinehasadigitalsamplingoscilloscopeandalogicanalyzereffec-tivelyjoinedatthehip.Theyshareacommontriggermodulethatenablestheusertoidentifyacomplexeventandrecordthestateofthetargethard-warebeforeandafterthetrigger—inboththeanaloganddigitaldomains.Inthecaseofmyerraticbuslogic,theculpritturnedouttobeadelin-quentGALwithagroundbounceproblem.Theoffendingchiphaditsdutiesreassignedandthedocumenta-tionpolicewerealerted.EngineerAMixed-SignalCaptureEngineTHECOMPUTERAPPLICATIONSJOURNAL®INKtriumphsoverbug.Byemployingahigh-techpieceoftestequipment,Icouldtriggeronacomplexdigitaleventandcorrelatethiseventtoanoscilloscopetracethatshowedwhatwasreallyhappeningintheanalogdomain.Iwassavedinthenickoftime,butdespitehavingformedadeepattachmenttothetrusty’scope,Ihadtogiveitback.Followingthisadventure,Istartedmusingabouthowtorollmyownversionofthatusefulelectronicgadget.AftersomementaltinkeringandwiththeaddedincentiveofDesign98,Iwassoonsketchingelectronicstuffonthegridpad.BitScopebegantoemerge(seePhoto1).THEBIGPICTUREThebasicideabehindBitScopeisthatofaspecializedpieceofdata-capturehardwarethatdoesn’tincludeanyuserinterfaceotherthananRS-232plug.Mostengineershavemorecom-puters,mice,andkeyboardsthanthey2Issue97August1998CircuitCellarINK®www.circuitcellar.comSERIALCONNECTIONWhileaserialinterfacemayseemabottleneckforacaptureenginethatcanpotentiallystore64KBofdata,thisisnotaproblem.ThankstotheInternetand56kmodems,mostPCsnowhavefast,bufferedUARTs.ThetransmissionspeedoftheBit-Scopeseriallinkcanbescaledto115kbpsusingafastmicrocontroller.Atthisrate,youcantransferenoughtrollerfirmwareisdesignedasavirtualmachine(VM).TheBitScopedesignisnovelbecauseithasanunusualarrangementoftheVMprogramcode.Thein-structionsarenotlocatedinmemoryonthemicrocontrollerbutresideintheuserinterfaceandareexecutedatomicallydirectfromtheserialport.IfyoustudyBitScope’svir-tualinstructionset,youseethatarrangingthingsinthiscrazywayhasitsadvantages.Allinstruc-tionsareatomic.Inotherwords,thereisnoinherentsyntaxassociatedwithanycommandbyte.Allinstructionbytesareechoedtoprovideasimplehandshakemechanism.And,allinstructionsarepreemptive,soyoucanalwaysabortthepreviouscommandandregaincontrolsimplybysendinganewcommand.knowwhattodowith.IfIwasgoingtobuildacheap’scope,Icertainlydidn’twantanymoreofthatstuff.WhatIneededwasanelectronicdronethatcouldcaptureanddisgorgedataoncommand.Nomore,noless.ThecommandshadtobesimpleASCIIcharactersthatareintuitiveandeasytolearn.ThePC-baseduserinterfacecanthensynthesizefunc-tionalityofarbitrarycomplexitybysendingscriptsofcommandcharac-tersandreceivingthereplies.Theanswer:avirtualinstrumentwherespecializedhardwaredoestheelectronictestjobandaPCletstheengineerdriveit.Onebigadvantageofthissetupisthatchangingthewaythevirtualinstrumentworksdoesn’tusuallyinvolvereprogrammingchips(hard)butmaybedonebydownload-inganewprogramfromthe’Net(easy).Asdescribedinthesidebar“VirtualMachineArchitecture,”themicrocon-Figure1—Thisblockdiagramofthemixed-signalcaptureengineshowsbasicdesignarchitecture.ABdivnAnalogSupplyPowerSupplyMuxRangeFlashADCDigitalPodDataMux32K·8SRAM32K·8SRAMClockPLDLogicControlPICCPUSerialFigure2a—TheBitScopeCPUandstorageengineincludesthePIC,PLDlogic,clock,datamuxes,andsampleRAM.CircuitCellarINK®Issue97August19983www.circuitcellar.comVirtual-MachineArchitectureAvirtualmachine(VM)consistsofafullyfunctionalprocessorhostedonanunrelatedsubstratemachine.VMdesignhasadvantagesoverconventionalcoding.Eachinstructionmaybehighlyoptimizedforperfor-mance—unlikeageneral-purposeinterpreterlikeBASIC,whichcandoanythingbutinefficiently.VMinstructionsarecompactlikeassemblybutperformextremelycomplextasks.Oncearegisterandcommandsetaredevised,youcanaddnewinstructionstoenhancethemachine.Theoriginalinstructionsremainthesame,whichpromotesmodularity.SincetheoperationaldefinitionoftheVMisrigid,firmwarechangestendtobestraightforward,eventothepointofhostingthetargetarchitectureonacompletelynewsubstrate.Inthisdesign,thePIC16F84isasubstratetoimple-mentacustomBitScopemachinewithitsinstructionsetbecomingmicrocodetoimplementtheVM.So,theBitScopeVMhasinstructionsandregistersbutthey’reunrelatedtothePICnativeinstructionset.ThevirtualregistersarehostedbyPICmemoryregistersbuthavemeaningonlytotheBitScope.Similarly,BitScopehasnouseforXOR-orDECFSZ-typeinstructions.Instead,ithasinstructionsformanipulatingregisters,startingsampleRAM,anddumpingcaptureddata.BitScoperegistersmaybeoptionbits,timerconstants,sampleaddress,andsoon.Theexactfunctionoftheregist