Vous êtes sur la page 1sur 2

Frequency Meter

Prinziple: Building a frequency meter was quite simple: At first you feed the known frequency FREF over the prescaler K into the counter M and the input frequency F ! over the prescaler " into a second counter !# $hen after a certain time you read %oth counter and the frequency can %e calculated as: F ! & FREF ' "(K ' !(M )ince %oth counter can only count full periods* you get an error of !+(,- and M+(,-# )o for high resolution you schould count long enough to get high values for M and also for !# Especially on lower input frequency this time can %e many seconds long# )o a modification of the prin.iple was needed: Both counter are no longer started and stopped at the same time %ut also one counter start and stop the other# $hen this counter count always full signal periods and no error of +(,count was added# /nly the other counter* which was started and stopped add an error of +(,- counts and thus it should %e this one with the higher counting value# $he second descri%ed principle looks complicated to %uild it only with logic circuits especially* if a wide range of input frequency would %e supported# )o a micro controller seem ideally suited to do the 0o%# Hardware considerations: $he A$123456- can work with a crystal of 47M8.# )o used it also# )ince all calculations are done with floating point num%ers the deviation of the real crystal frequency can %e considered in the definition inside the 9main#h9 file :e#g ;define <$A" -4#555-6e=># $o measure up to -45M8. a prescaler of -(46= was used to get an input frequency %elow -Mh. for the counter inside A$123456-# $his prescaler was %uild with two ?7F-2@ %inary counters# For measuring of frequency %elow 6558. a second prescaler value of only -(4 can %e selected# Aith the two control signals the prescaler can %e set into one of three different states:

prescaler reset divide %y 46= divide %y 4

$he prescaler of the reference crystal was given %y the internal timer prescaler of -(-4 of the A$123456-#

$he display resolution should %e a%out 6 digits and every 5#6sec a new value schould %e displayed# Description: $here are %oth timer interrupts used* one as timer to count the internal reference frequency and the other as counter to count the prescaled input frequency# Additional the eBternal interrupt E<5 was used to start and stop the timer# Both counters are %uild with $5 in mode @ as two separate 1,%it counters# )o $- can %e used as %aud rate generator to send the measuring result over the CAR$# For a measuring time of 5#6sec a counting range of 47 %it was needed# But there is no pro%lem* since inside the timer interrupts additional software register can %e incremented to eBpand the counter from 1,%it up to 47,%it# $o hold the interrupts as short as possi%le the additional counter %ytes are decremented %y using the 9DE!F9 instruction# $hen no flags altered and no registers must %e GC)8ed# Program example: $he given eBample was written for the A$123456-# $he )chematic was given with a 1, digit ?,segment display# But the eBample code send the measuring result over the CAR$# But the ?,segment display on using the MA<?4-2 can already %e found on my other programming eBample# )o com%ining %oth should %e easy# Also range detection and implementation of the lower range :68. ### -Mh.> can easy %e added#

measure#c6measure#h display#c6display#h main#c6main#h schematic#pdf