Вы находитесь на странице: 1из 3

21.7.2015.

Lab3LaboratoryforExperimentalComputerScience

LaboratoryforExperimentalComputerScience
attheAcademyofMediaArtsCologne
logoKHM
Home/Lab/InterfacesAdvanced

ArduinoFrequencyCounterLibrary

FromourThereminProjectIderivedthisFrequencyCounterLibrary.Thelibrarymakesitpossible
tomeasurefrequencieswithahighresolutionandaccuracy.

TheFrequencyinputisfixedtodigitalpin5.ThispinismappedtothealternateportfunctionT1
whichistheinput16BitHardwareCounter1.Toobtainahigherresolutionthan16Bit,thecounter
overflowsarecountedalsoandarecalculatedwiththecountervaluetothefinallongintegerresult.
TheFrequencySourceoutputmusthaveadigitallevelsothatweakSignalshavetobeamplifiedfor
instancebyansingletransistorora74HC14inverter.Themaximuminputfrequencyisabout8MHz
whensignaldutycycleis50%.

Ifyouliketomeasurehigherfrequenciesyouhavetouseanprescalerordividercircuitwhichcanbe
usedfromothercounterprojectspublishedintheweb.TheGateTimeforthecountingperiodcanbe
choseninthestart()functionwherevaluesof10,100or1000msarepracticableforaresolutionof
100,10and1Hzbutanyvaluecanbeused.Theinternalresolutionofthegatetimeis2mssothatthe
timecanbevariedintheincrementof2.Ifyouwishtominimizetheindicationerrorthevalueof
FreqCounter::f_compvariablecancompensateslightgatetimeerrors.Comparedtoancommercial
ACECOcounteritispossibletotrimthedeviationtoalmostzerooverthewholerange.Forgatetimes
of10,100,100thevalues1,10and100wherefoundtobegoodforourDuemilanovaboards.

http://interface.khm.de/index.php/lab/interfacesadvanced/arduinofrequencycounterlibrary/

1/3

21.7.2015.

Lab3LaboratoryforExperimentalComputerScience

ExampleProgramm
#include<FreqCounter.h>
voidsetup(){
Serial.begin(57600);//connecttotheserialport
Serial.println("FrequencyCounter");
}
longintfrq;
Voidloop(){
FreqCounter::f_comp=8;//Setcompensationto12
FreqCounter::start(100);//Startcountingwithgatetimeof100ms
while(FreqCounter::f_ready==0)//waituntilcounterready

frq=FreqCounter::f_freq;//readresult
Serial.println(frq);//printresult
delay(20);
}

Preamplifierschematics

SourceCodes
Updated10/2010workswithatmega328removedsomeglitches
Updated1/2012Arduino1.0
Download>FreqCounterLibrary

Forum
http://interface.khm.de/index.php/lab/interfacesadvanced/arduinofrequencycounterlibrary/

2/3

21.7.2015.

Lab3LaboratoryforExperimentalComputerScience

furtherquestionstothistopiccanbediscussedhere:
http://arduino.cc/forum/index.php/topic,64219.0.html
http://www.arduino.cc/cgibin/yabb2/YaBB.pl?num=1231326297

Contact
MartinNawrath,nawrath@khm.de
Lab3,AcademyofMediaArtsCologne,PeterWelterPlatz250676Cologne,Imprint
LabLog
Events
Awards
StudentWorks
Research
Experiments
Current
Past
Lab
InterfacesBasics
InterfacesAdvanced
Material
Teaching
Seminars
GuestLectures
People
Staff
DoctoralCandidates
Alumni
Publications
OnTopic
Books
Articles
Lectures
Galleries
Contact
search

RSSFeed

http://interface.khm.de/index.php/lab/interfacesadvanced/arduinofrequencycounterlibrary/

3/3

Вам также может понравиться