Sofarinthischapter,ouremphasishasbeenonrelativelyslowswitching.But,ifweswitchaloudspeaker
offandonatanaudiorate,wecanproducesound,perhapstobeusedasanalerttone,orabeeptoconfirm
anactionorstatus.(WewillneedfastswitchingtocontrolaDCmotor’sspeedthroughpulsewidthmodula-tion,andtocontrolsteppermotors,bothtopicsdealtwithinlaterchapters.)
Wecangenerateasoundeitherthroughaself-containedsounder,suchastheSonalert®productsintroduced
byMallory,orthroughthePICproducingtheaudiosignalitself.ASonalertmaybedrivenbyaPICusing
anyofthetechniquesyoulearnedearlierinthischapter.Laterchaptersexploreinsomedetailtheadvantages
anddisadvantagesofvariouswaystogenerateaudiosignalsusingMBasic.Here,however,wewilljustlook
attwosimpleinterfacesandoneofthemanyaudiooutputproceduresavailableinMBasic.
We’llassumeyoudon’tintendtoproduceearsplitting,highfidelityoutputfromaPIC.Rather,youarein-terestedinbeepsandotheralertingtones.Insomecases,itmaybepossible
toobtainadequatevolumelevelsbydrivingthespeakerdirectlyfroma
PIC,asillustratedinFigure3-47.Whenthinkingofaspeaker,lowimped-ancedesignsmostoftencometomind,with3.2,4and8ohmdevicesbeing
common.I’vegenerallybeendisappointedwiththevolumelevelswhen
alowimpedancespeakerisdirectlyconnectedtoaPIC.Indeed,aseries
resistor,R1inFigure3-47,of50ohmsorsoisnecessarytoproduceuseful
soundoutput.
Remember,however,thatahighoutputpinmaybethoughtofasa5Vsourceinserieswithapproximately
85ohms.Workinginto,forexample,a3.2ohmspeakerwitha50ohmseriesresistor,approximately99.8%
ofthetheoreticalmaximumoutputpowerofthepinwillbelostandnottransferredtothespeaker.Thisstill
mayproduceanacceptablevolumelevel.Ifthespeakerhashigherimpedance,sayatleast32ohms,amuch
greaterproportionoftheavailablepowerwillproduceusefulsound.Ifnecessary,asimpleseriesresistor,
shownasR1inFigure3-47,canserveasavolumecontrol.
Ifyou’veexaminedaloudspeakeryouknowthetypicalconstructionconsistsofapaperconethatmovesin
oroutinresponsetocurrentthroughthevoicecoil.OursimpleconnectionofFigure3-47movesthecone
onlyinonedirection,eitherinorout,dependingonwhichspeakerconnectionyougroundandwhichyou
connecttothePIC’spin.Theunidirectionalmotionthrowsawayonehalfthepotentialsoundlevel.Depend-ingonyourdesiredsoundlevelandspeakerrating,thismayormaynotbeimportant.Figure3-48shows
Figure 3-47: Driving a speaker
directlyfromaPIC.
weareabletodevelopapeakcurrentof27mAthrougha
3.2ohmspeaker.Thisparticularspeakeryieldedaweak
soundwith27mAcurrent.Wemaycalculatethepower
deliveredtothespeakerbyrecallingthattheRMSpowera
squarewaveisequaltotheone-halfthepeakpower.(The
RMSoftheonperiodisequaltothepeak;butsincehalf
thecycleisoff,theRMSreducesbyonehalf.)Hence,
theRMSpowerdeliveredtothespeakerisapproximately
1.2mW.(Thisisbaseduponthespeaker’snominal3.2
ohmimpedance.MeasurementsoftheparticularspeakerI
testedshoweditstrueimpedanceat1000Hzis3.09ohms,
representing2.95ohmsresistanceinserieswith149µH
inductance.)
Let’slookatahigherpowerdriverforalowimpedance
speaker.Sincewearenotoverlyconcernedwiththesound
quality—thePICsoundprocedureweuseoutputsasquare
wave,afterall—wewillusea2N4401emitterfollower
todrivethe3.2ohmspeaker,usingthecircuitshownin
Figure3-49.And,topermitthespeaker’svoicecoiltohave
bothinandoutexcursions,weuseC1toblocktheDC
component.
Figure3-50showstheresultingcurrentthoroughthespeaker.
TheRMSpowerdeliveredtothespeakerisnowapproximate-ly45mW,yieldingnearly16dBmoresoundoutput,avery
noticeableimprovementoverthedirectdriveconnection.
Program3-3usesMBasic’ssoundproceduretooutputa
1000Hzsquarewavefor1,000millisecondsonRB0.The
toneoutputisrepeatedendlesslythroughtheGoToMain loop.
Program3-3
;Program3-03 Main
;burstof1000Hzfor1second
w/endlessloop
SoundB0,[1000000\1000]
GoToMain
End
References
[3-1] Horowitz,PaulandHill,Winfield,TheArtofElec-tronics,2nd.Ed.,(1989).Ifyouhaveonlyonebookon
electronicsinyourlibrary,thisshouldbeit.Along-awaited3rdeditionisrumoredtobeintheworks,but
thatshouldn’tdiscourageyoufrompurchasingthe2ndedition.
[3-2] AmericanRadioRelayLeague,TheARRLHandbookforRadioCommunications2003ed.,American
RadioRelayLeague(2003).Althoughaimedatradioamateurs,theARRLHandbookprovidesgood
Figure 3-48: Direct drive of 3.2 ohm speaker
withPICand56ohmseriesresistorCh2:Speaker
current(mA).
Figure3-49:2N4401emitterfollowerspeakerdriver.
Figure3-50:2N4401FollowerDriveof3.2Ohm
SpeakerwithPICand56OhmSeriesResistorCh2:
SpeakerCurrent(mA).
entry-levelcoverageofbasicanaloganddigitalelectronics,testequipmentandconstructionpractices.
TheARRLupdatesitshandbookeveryyear,sopurchasethemostrecentversionavailable.
[3-3] Ludeman,RobertR.,IntroductiontoElectronicDevicesandCircuits,SaundersCollegePublishing
(1990).Writtenasanintroductorytextforcommunitycollegeelectronictechnicianstudents,it’sagood
summaryofbasicsolid-stateelectronicswithoutrequiringadvancedmathematics.
[3-4] LinearTechnologyCorp.makesavailableafreeMicrosoftWindows-basedSPICEsimulatorandsche-maticcapturesoftware,“LTSpice/SwitcherCADIII.”AlthoughaimedasadesigntoolsupportingLTC’s
products,thesoftwareisnotlimitedtoLTCdevices.Itmaybedownloadedathttp://www.linear-tech.
com/software/.Inaddition,add-ondevicelibrariesandexplanatorymaterialforLTSpiceareavailable
intheassociatedYahoousergrouphttp://groups.yahoo.com/group/LTspice/inthefilesfolder.The
schematicsandsimulationsinthisbookuseLTSpice.
[3-5] Barkhordarian,Vrej,PowerMOSFETBasics,InternationalRectifierCorp.TechnicalNote(undated).
[3-6] InternationalRectifierCorp.,TheDo’sandDon’tsofUsingMOS-GatedTransistors,AN-936(v.Int).
(Undated)
[3-7] InternationalRectifierCorp.,CurrentRatingsofPowerSemiconductors,AN-949(v.Int),(Undated).
[3-8] InternationalRectifierCorp.,SelectingandDesigninginTheRightSchottky,AN-968,(Undated)
[3-9] OmronElectronics,Inc.,RelayUser’sGuide(1990).AvailableforfreedownloadatOmron’sreference
centerhttp://oeiwcsnts1.omron.com/pdfcatal.nsf.Fromthispage,selectRelays.Fromtherelayspage
selectManual.
[3-10] DatasheetsforthedevicesusedinthischapterareavailablefordownloadingatthefollowingURLad-dresses:
2N4401:http://www.fairchildsemi.com/ds/2N/2N4401.pdf 2N4403:http://www.fairchildsemi.com/ds/2N/2N4403.pdf
PS710A-1A:http://www.csd-nec.com/opto/english/pdf/PN10268EJ01V0DS.pdf 2N7000:http://www.fairchildsemi.com/ds/2N/2N7000.pdf
4N25:http://www.fairchildsemi.com/ds/4N/4N25.pdf TIP31:http://www.fairchildsemi.com/ds/TI/TIP31.pdf TIP120:http://www.fairchildsemi.com/ds/TI/TIP120.pdf
MV5491ADualLED:http://www.fairchildsemi.com/ds/MV/MV5094A.pdf
IRF510:GotoInternationalRectifier’shomepagehttp://www.irf.com/andenterIRF510inthesearchbox.
IRF9510:GotoInternationalRectifier’shomepagehttp://www.irf.com/andenterIRF9510inthe
searchbox.
IPS021:GotoInternationalRectifier’shomepagehttp://www.irf.com/andenterIPS021inthesearchbox.
IPS511:GotoInternationalRectifier’shomepagehttp://www.irf.com/andenterIPS511inthesearchbox.
G5VRelay:GotoOmron’shomepageforUSrelayproductshttp://oeiweb.omron.com/andenter
G5V-2-H1inthesearchbox.
G2RL-24Relay:GotoOmron’shomepageforUSrelayproductshttp://oeiweb.omron.com/andenter
G2RL-24inthesearchbox.
StandexJG100Relay:http://www.standexelectronics.com/serjg.htm