Você está na página 1de 5

11/29/2014

APICfrequencycounterprojectwritteninCusingTMR1andanLCD.

Home

Home

PICResources

Projects

Resources

ECourses

Other

RecentArticles

ClaimYour:Useful

PICResources

AnUltrasonic
Distancemeter
project.

"ArduinoSoftwareGuide"

PICIntroduction
RightNow...

PICICSP

Nov25,1412:00PM

ProgrammerTypes

Name:FirstName

Projects

AnPICUltrasonicDistance
meterprojectusingaPIC
microcontrollerwhichisideal
sinceithasacapturetimer
thatcanaccuratelymeasure
theultrasonicechotime,so
calculatingthedistanceis
ea

Email: PrimaryEmail

PICProjects
ProjectIdeas

Download

Resources
Tips&Techniques
PICTutorials

ECourses
PICCCourse

Readmore

APICfrequencycounteroperating
uptoabout50MHz.

PICTraining

AdotmatrixLED
displayprojectforan
8x8or5x7led
matrix.
Nov20,1404:58AM

Other

StratixV
DevelopmentKit

Oscilloscopes
Articles
Forum

HighendPCIe3.0Stratix
VDevKit,10G/40G
Ethernet,DDR3,QDR2+

Books

ThisPICfrequencycounter
projectusesanLCDtodisplay
thefrequencyandPICtimer1
tomeasuretheinputsignal
andTimer0tomeasurethe
timingperiod.
ItusesTimer1in16bit
countermodetocountthe
inputsignaledgesand
overflowsofthecounterare
accumulatedtogivethetotal
countinmultiplesof
65536.Addingthecurrent
valueofthecounterattheend
givesthetotalcount.

Thecrystaloscillatorischosentobe4MHz(Fosc)sothattheprocessor
internalclockis1MHz(Fosc/4).Allyoudoiscount1e6processorclocks
(Timer0)togivea1secondcountperiod.
Sincethemeasurementtimeis1secondthefinalcountisactuallythe
frequencyoftheinputsignal.

Howtodriveadotmatrix
LEDdisplay.Thisproject
showsyouhowtodriveone
with64LEDs(8rowsby8
columns)orlesse.g.35LEDs
(7rowsby5columns).
Readmore

USBSerialPort:How
tosetupanRS232
seriallinkthrougha
USBport.
Nov20,1404:55AM

USBserialport:Howto
setupanRS232seriallink
whenyouonlyhaveaUSB
port.Therearetwotypesof
digitalinterfacesto
consider...
Readmore
Search
CustomSearch

SignupforMicroZine:
''The''Microcontroller
Newsletter

Usingthe1secondmeasurementtimealsogivesafrequencyresolution
of1Hz.
Specification
Minfrequency

Maxfrequency

1Hz
~50MHz(limitedbyinputpin
characteristics).

http://www.bestmicrocontrollerprojects.com/picfrequencycounter.html

Enteryourfirst
Nameandprimary
emailaddressinthe
formbelow:
Andreceiveabsolutely
FREEafullprojectfor:

"Measuring
1/5

11/29/2014

APICfrequencycounterprojectwritteninCusingTMR1andanLCD.
(TestedusingTTLoscillatorat20MHz).
Inputsignallevel

TTL

Note:TheexactmaximumoperatingfrequencyisdeterminedbythePIC
inputpincharacteristic.
Compiler

MikroelectronikaMikroCCompilerFree!

Target

16F877A(retargetabletootherPICsthathave
TMR1)

Softwarelevel

Advanced.

Softwarenotes

InterruptDrivencountingandtimemeasurement.

Hardwarelevel

Easy.

Hardwarenotes

None

Projectversion

1.03
EnteryourdetailstogettheDownloadLink
andgetthemicrocontrollernewsletter:

AnalogueVoltages
WithoutAnADC"
(Usingonlyonepin).
InstantDownload:
YouCan
GetItRightNow
Warning:This
projectcouldbe
Removed
atanytime.
ItwillNOTbe
available
indefinitelySO
Toavoid
disappointment
getit:

Name:

Now

Email:
FreeInstantAccess!

Projectfiles

(Note:Youremailissafeitwillneverbesoldorrented).

YouwillgetAlltheCsourcecodeandhexfile.
Note:Checkyouremailfortheprojectcode
downloadlink.

Name:

FirstName

EMail:

PrimaryEmail

FREEAccessHere
Don'tworryyouremail
addressistotallysecure.I
promisetouseitonlyto
sendyouMicroZine

Forthegeneraltheoryofoperationofthiscircuitandnotesonfrequency
countingofthispicfrequencycounterclickhere.
PICfrequencycounterschematicusingLCDandTMR0andTMR1.
(Clickdiagramtoopenapdf.)

Rememberthisisaproject
withfulldescription
andfullydebuggedCSource
codeandit'snotavailable
fromthemainwebsite.
Youcanonlygetit
throughthisnewsletter.
Togetexclusiveaccess
EnteryourfirstnameName
andprimaryemailaddress
Nowintheformabove.:

Butwait!
There'smore...
You'llreceivemore
freeandexclusive
reportsaswellas
siteinformationand
siteproduct
updates.

PicfrequencycounterHardware
Thehardwareissimpleandthemainblocksareshowninthediagram
below.

http://www.bestmicrocontrollerprojects.com/picfrequencycounter.html

Scrolluptotheformabove
andsignupNOW.Don't
forgetit'sFREEandifyou
don'tlikeityoucan
unsubscribeatanytime.
ClickHereNowtousethe
formabovetogetyour
Valuableinformation
absolutelyfree.

2/5

11/29/2014

APICfrequencycounterprojectwritteninCusingTMR1andanLCD.

PicProjects
Schematic
PicCircuits

SocialBookmarking

TheLCDisusedin4bitmodeinterfacesoyouonlyneed4datalinesand
threecontrollinesanditthenfitsintoasingle8bitport.
Thecrystaloscillatorissimplyacrystalandtwocapacitorsconnectedtothe
PICoscillatorportatOSC1andOSC2.Thecapacitorscanbothbefixedat
thesamevalueunlessyouwanttotuneitusingafrequencyreference.If
youdon'thaveanaccuratereferencethenusefixedcapacitors.
ThePICmicrocanbeanytypethathasTimer0andTimer1hardware
modulesandandhasenoughmemorytoholdtheprogram~1.6kwords.
TheLEDistoggledtoindicatethattheprocessorisalivesoifthereisno
inputsignalyoucantellthatthesoftwareisworking.Alsoifthereisno
inputsignalthetheLCDdisplaysaflashingzero.
YoucanprogramthePICincircuitthroughtheICSPconnectorincircuit.

Description
Totimea1secondcountTimer0isused.Sincethemainclockisrunningat
4MHzthentheprocessorclock(Fosc/4)is1MHzwhichistheratethat
Timer0issetuptousei.e.theinternalclock.Thereforeweneedtogeta1
secondcountusingthattimer.Sincethetimerisonly8bitslongyoucan
usethefactthataninterruptisgeneratedwhenitoverflowsyoucanthen
counttheseoverflowstogetnearto1e6counts.
Sincetheoverflowoccurseverytimethatthecounterpasses256weneed
tocount1e6/256overflows
1e6/256=3906.25
Wecanonlycountintegeroverflowssomustmanipulatethelastcountto
gettheexacttime.Soweneedthemodulusof1e6and256:
1e6%256is64(0.25*256is64).
Theinterruptroutinestartsoffafterbeingzeroedbycounting3906
overflows,itthencontrolsaflagvariable(do_TMR0_end_count)that
indicatesthisisthelastoverflowforwhichtheTimer0valueissetto
overflowafter64Fosc/4cycles:
TMR0=25664+2//2cycleslostwhenwritingtoTMR0soadd2.
AttheendofthelastoverflowthevaluesofTimer1arecapturedto:
st_TMR1L
st_TMR1H

Click&Add:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Technorati

Y!MyWeb

Readerscomments
"Iwantedtothank
yousososomuch
foralltheinformation
youhaveprovidedin
yoursiteit's
SUPERBandFANTASTIC."

RanishPottath

"Thissitereallyis
thebestandmyfavorite.
Ifindheremanyuseful
projectsandtips."
Milan
bursach<at>gmail.com

LearnPICCNow

Wondering
howto
programyour
nextproject
usingCand
needagreat
start?
"FirstModule
Free:"CLICK
HERE

st_TMR1_ovfl
AnLCDupdaterequestissentfromtheinterruptroutinetothemainroutine
bysettingaflag(update_LCD)andthemainroutinethenusesltoato
calculateandoutputthefrequencymeasurementtothendisplayonLCD.

PICfrequencycounterSoftware
ProjectfilesforthePICfrequencycounter

"Awesomesite,
very,veryeasyandnice
tonavigate!"
Matt
matt_tr<at>
wolf359.cjb.net

Compilerprojectfiles
frequency_counter_4MHz_LCD_TMR1.mcppi
Thisisthemainprojectfile.

http://www.bestmicrocontrollerprojects.com/picfrequencycounter.html

"IamanewbietoPIC
andIwantedtosay
howgreatyour

3/5

11/29/2014

APICfrequencycounterprojectwritteninCusingTMR1andanLCD.
ThereareotherfilessinceMikroCversion6.0.4seemstoneedalotmore
thanV5!justkeeptheminyourprojectfolder.

sitehasbeenforme."
Dave

CSourcefiles.
Frequency_counter_4MHz_LCD_TMR1.c
ltoa.c

de_scott<at>bellsouth.net

Headerfiles.
bit.h
ltoa.h

LearnMicrocontrollers

Outputfiles
Frequency_counter_4MHz_LCD_TMR1.hex
Foratutorialoncompilingthesefilesclickhere.
Youonlyneedtorecompilethepicfrequencycounterfilesifyouwantto
changethesourcecodeorexaminehowthecodeworksusingthebuiltin
simulatorsincethehexfiletoprogramthechipisincludedinthedownload.

"Interestedin
Microcontrollers?"
SignupforThe
Free7dayguide:
FREEGUIDE:
CLICKHERE

Briefdescription
frequency_counter...c:containsthecodestartpoint(inroutine
'main')andtheinterruptroutine.
ltoa.ccontainsalongtoasciiconverterusedfordisplayofthe
frequencycount.
bit.h:containsmacrosforbitmanipulation.
Allotherheaderfilescontainprototypes.

PICfrequencycountercodeoperation.
ThecodeusesthebuiltinLCDdriverroutineswhichareautomatically
includedbythecompiler.Noteautomaticincludeisunusualbutitseemsto
workwellinmikroC.
Interruptsarenotusedonlytheflagsthatcanbepolled(timeroverflow)
areactivated.
frequency_counter_4MHz_LCD_TMR1.c
Thisfilecontainstheportinitialization,interruptandmainroutine.
Afterinitializationthecodeentersanendlessloopwhereitcontinuously
performsameasurementanddisplayoperation.Afteranaccurate1second
delaythecounterresultisprocessedanddisplayedontheLCD.

"Yoursiteisagreat
andperfectwork.
congratulations."
Suresh
integratredinfosys<at>
yahoo.com
"Icouldn'tfindthecorrect
wordstodefine
yourwebsite.
Veryuseful,uncovered,
honestandclear.
Thankssomuchfor
yourtimeandworks.
Regards."
Anon

Themainoperationofthiscodeiswithintheinterruptroutinethatboth
countstheinputedgesandobtainsanaccurate1stimebycountingthe
edgesoftheinternaloscillatorclock(Fosc/4).
Interrupts
Themostimportantpartofthiscounteristheinterrupt()routine.Thisis
wherealltheactionanddecisionsaremade.
TheinterruptcodeforTimer1isverysimpleandallitdoesisincrementa
longvariableforcountingmultipleinputevents.
Themoretrickyinterruptcode,forTimer0,countstimeasdescribed
above.Itcounts3906overflowsfollowedbyasingle64cyclecounttoreach
atimeof1secondafterwhichitcapturestheeventcountandthentriggers
anupdatetotheLCDtocalculateanddisplaythefrequency.Theupdate
triggerstheactionsinmain().
bit.h
Thiscontainsmacrosforbitmanipulationwhichshouldbecompiler
independent.

LearntoprograminC
ineasysteps.

http://www.bestmicrocontrollerprojects.com/picfrequencycounter.html

4/5

11/29/2014

APICfrequencycounterprojectwritteninCusingTMR1andanLCD.
Essential&EASY:
PICCProgrammingCourse:
CLICKHERE.

Jumpfrompicfrequencycounterpageto
toBestMicrocontrollerProjectsHomePage.

PrivacyPolicy|Contact|AboutMe
SiteMap|TermsofUse|Links

Sharethispage:
What'sThis?

Enjoythispage?Pleasepayitforward.Here'show...

Search
Web

www.bestmicrocontrollerprojects.com

Copyright and TM 2005-2014 Best-Microcontroller-Projects.com.


All rights reserved.
No reproduction permitted without permission.

http://www.bestmicrocontrollerprojects.com/picfrequencycounter.html

5/5

Você também pode gostar