0% found this document useful (0 votes)
156 views3 pages

Lab3 - Laboratory For Experimental Computer Science

This document describes an Arduino frequency counter library. The library allows for measuring frequencies with high resolution and accuracy by using a 16-bit hardware counter on digital pin 5. It counts overflows to obtain a resolution greater than 16 bits. Gate times of 10, 100, or 1000 ms provide resolutions of 100, 10, or 1 Hz. An example program prints measured frequencies to the serial monitor with a compensation value to minimize errors.

Uploaded by

apofview
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views3 pages

Lab3 - Laboratory For Experimental Computer Science

This document describes an Arduino frequency counter library. The library allows for measuring frequencies with high resolution and accuracy by using a 16-bit hardware counter on digital pin 5. It counts overflows to obtain a resolution greater than 16 bits. Gate times of 10, 100, or 1000 ms provide resolutions of 100, 10, or 1 Hz. An example program prints measured frequencies to the serial monitor with a compensation value to minimize errors.

Uploaded by

apofview
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 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,[email protected]
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

You might also like