Professional Documents
Culture Documents
V ADC = Vref
1023
ConvertingtheanswerfromtheADCbacktovoltagerequiressolvingforV.
Figure1.10bitADCblockdiagram.
Operation: TheADRESH:ADRESLregisterscontainsthe10bitresultoftheA/Dconversion.WhentheA/D conversioniscomplete,theresultisloadedintothisA/Dresultregisterpair,theGO/DONEbit (ADCON0<2>)iscleared,andA/Dinterruptflagbit,ADIF,isset. AftertheA/Dmodulehasbeenconfiguredasdesired,theselectedchannelmustbeacquiredbeforethe conversionisstarted.TheanaloginputchannelsmusthavetheircorrespondingTRISbitsselectedas inputs. SamplingtimeisalsoconfiguredinADCON1register.ADCON1selectstheratiobetweenprocessorclock speedandconversionspeed.ThisisimportantbecausetheADCneedsatleast1.6sperbit.Accuracy degradesiftheclockspeedistoohigh.Astheprocessorclockspeedincreases,anincreasinglylarge dividerisnecessarytokeeptheconversionspeed.FourMHzisfastestat8:1ratiowithaconversion speedof2sperbit.AfterthisacquisitiontimehaselapsedtheA/Dconversioncanbestarted. ItshouldbenotedatthispointthatsinceADCmoduleofPICmicrousesacapacitortoholdthesampled voltage,impedancemustbeconsidered.FormoreinformationaboutacquisitiontimeandA/D acquisitionrequirements,refertothedatasheet.Thefollowingstepsshouldbefollowedfordoingan A/Dconversion: 1. ConfiguretheA/Dmodule: Configureanalogpins/voltagereference/anddigitalI/O(ADCON1) SelectA/Dinputchannel(ADCON0) SelectA/Dconversionclock(ADCON0) TurnonA/Dmodule(ADCON0) 2. ConfigureA/Dinterrupt(ifdesired): CleartheADIFbit SettheADIEbit SettheGIEbit 2
3. Waittherequiredacquisitiontime. 4. Startconversion: SettheGO/DONEbit(ADCON0) 5. WaitforA/Dconversiontocomplete,byeither: PollingfortheGO/DONEbittobeclearedorADIFbittobeset OR WaitingfortheA/Dinterrupt 6. ReadA/DResultregisterpair(ADRESH:ADRESL),cleartheADIFbit,ifrequired. 7. Fornextconversion,gotostep1orstep2asrequired. SampleCode: RefertothesampleMPLABXprojectincluded. Schematic: