Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

very accurate frequency counter

Status
Not open for further replies.

dope40

Member level 4
Joined
Oct 3, 2011
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bulgaria
Activity points
1,777
Hi , i want to build very accurate frequency counter (0.1Hz accurate ) . The range is from ~15 Hz to ~1.5 KHz.I am using PIC and uC , also i am using flowcode , so if any has any sugestion i would be very happy to hear them.

P.S Sorry for the bad grammar but English is not my native language.
 

I think (and I could be wrong) the way to approach this is as follows: the difference in period between 1500 Hz and 1500.1 Hz is 44.44 nS. 1/44.44ns==> 22.5MHz. Thus, you'll need to sample at least that fast.

Another way to do this (if your signal is periodic) is to enable a counter for a relatively long period of time. That counter would be clocked by your input signal. Thus, if you know the for how long your counter is enabled you can determine the frequency by the number of accumulated counts. For example, if you enable your counter for 0.1 second, and the value it holds is 1,500,000 you would know that your input frequency is 15MHz. The problem with this method is that your frequencies are relatively low and you would have to enable your counter for a long time in order to get the accuracy you require.
 
Take a 1 second sample. A long sample will create a very accurate result.
Especially for 15Hz. You will need to start your sampling when the waveform has reached a peak and and then remember the instant for the actual starting of the sample.
 

dope40,

barry's first approach is probably the most feasible of the two methods the second method works very well when the input frequency is in the MHz range. I would use something significantly higher than the 22.5MHz that barry suggest as the lower limit. With that value you'll likely end up with between 0.1 to 0.2 Hz error. I would suggest using 50 MHz or greater. You can then convert the resulting period count into a frequency value for that period. I would also allow for some means of performing a running average of the values to reduce the amount of "noise" in the frequency value output.

Regardless of which method you use the accuracy of the clock driving the "counter" has a direct effect on the accuracy of the measurement.
 

The usual method for accurate measurement of relative low frequency signals is multi-period measurement, an extension of single period measurement.

For single period measurement, you count the cycles of a reference frequency signal over one input signal cycle. Then calculate the frequency as Fref/Ncount. In multi-period measurement you count over multiple cycles of the input signal, up to a predefined measurement time, e.g. 0.1 or 1 sec.

PIC input capture function can be used for an crystal accurate timing measurement.
 

I am trying to get engine rpm . The frequency depends on the number of cylinders and RPM thats why it needs to be between 15Hz and 1.5KHz . The accurasity needs to be 10 RPM (on a 16 cylinder engine that is 1.3 Hz , but on a 4 cylinder engine that is 0,3 Hz ) . I just recenty started using PIC so i need somme help with the code . Also this is not just a frequency meter but it plays as rev limiter , launch control , flat shift , shift light .. and ETC. So it needs to allow the pic to do other stuff along with mesuring the frequency.
 

hello,

4 cylinder engine that is 0,3 Hz

there is something wrong ?
What is the minimum speed (in RPM value) ?
Usualy, it could be >500Tr/mn so 8.3Hz is the minimum if only one pulse per tour ...

to measure the frequency you can use the Capture mode associated to a timer..
and this mode can work for only one pulse, or average for 16 pulses to increase the accuracy..
i did some test on PIC18F , mainly with MPLAB C18
if you are interessted follow **broken link removed**
uses a time windows of 1sec or 4 secondes..
 
Last edited:

hello,



there is something wrong ?
What is the minimum speed (in RPM value) ?

The formula to convert the RPM to Hz (on the ignition coil ) is X=((number of cylinders/2)/60)*RPM
The engine will be working around 900 RPM but i need to be able to control it with 10 RPM interval.


Here is a simple calculator that i made to calculate the RPM in Hz (number of sparks)
View attachment calculator.exe
 

:thumbsup:
Ok, i didn't take care that 0,3Hz represent the resolution of the measurement ..
 

Clearly to measure 1Hz with 0.1Hz accuracy is easy but to measure quickly in 0.1 second or less is impossible without interpolation.

The short measurement interval requirement ( unspecified ) is your challenge especially with rapid changing frequency from 1 to 20 Hz in < 1 sec.

THis might be possible in software or hardware, if you know how.

This requires calculations of period between pulses and 20 calculations per second to estimate period based on rate of changes in previous pulses.
If you need to make rapid rate change in RPM polarity, none of these methods are good and shaft encoder is necessary. ( perhaps why some cars lag by 1 second to shift when driver changes mind from slow down to speed up fast)

Another method in hardware is use a PLL to track the RPM pulse with a 100:1 tracking range on the VCO or using digital tuned oscillator. Now we can scale 1Hz up to 1000Hz and 10 to 10kHz then measure the number of cycles in 0.05 seconds, except now we need to condition the mixer error to use 1st and 2nd order derivative feedback using signal conditioners and make it stable tracking the slow pulse rate. But I think it is better to calculate in uC so that precise calculations can be made on period, rate of change of period, and 2nd & 3rd order error from last period used for predicting next period. 1st derivative uses last two cycles, 2nd derivative uses last 3 cycles and t some point you need to factor gear changes with prediction correction for gear ratios and overshoot on shifting.

A. The best solution is analog or digital engine shaft encoder. with 5 degree resolution or similar.
B. Next best is use all pulses from distributor not just 1 cylinder.
C. Worst case is use only 1 cylinder !! but more challenge. :cool:
C1 Use digital estimator of RPM
C2 use PLL scaler to increase HZ to measure frequency

C2: How to design VCO from or DTO ( digital tune oscillator) from 1k to 50KHz. Type II mixer, special VCO and divide by 1000 counter with fancy RC signal conditioner to control, VCO with integrators & derivatives in feedback. i.e. a complex PID loop control system)?

C1: I would use this method and calculate error for PID (Proportional, Integral & Derivative) and 2nd order derivative in estimating next period.

With 20 computations per second a PIC can manage the estimate of RPM and other tasks. YOu will ned some background in COntrol System Theory and Least Squares Estimate of estimated error for varying frequency signal inputs ( Step, ramp and Pulse (step down then up on gas peddle)
 
Last edited:

If i use x10 Frequency multiplier ? Then the Frequency for 10 RPM is 3Hz. so the resulution has to be 1 Hz , but it has to go from 150Hz to 15KHz.(So if i messure 313 Hz > when i divide it by 10 i get 31.1 Hz > or in a 4 cylinder engine 940 RPM )
 

hello,

Suppose you are using a MCU at FOSC=16x4=64Mhz so cycle is 62,5nS
With CCP + timer mode you can measure the period of one signal ou cumul of 16 signals
16 edges mode (like on 18F46K22 serie)

for 15Hz , resolution colud be 113024 counts for delta=0,1Hz and takes ~1second of measurement
(or 7064 counts for 1 edge mode) within 0,66 sec
for 150Hz , ......1137 counts for delta=0,1Hz
for 850Hz .......35 counts .. for delta =0,1Hz
for 1500Hz .... 11 counts .... for delta =0,1Hz

is it enough for your application ?

but resolution decrease until 1 count for 15000Hz and for a delta=1Hz = 0.0067%

Resolution of 0,1Hz at 15Hz could not be the same at 1500Hz and over !
with the same alogrihm of measurement
maybe, you can switch the model of measurment between
Periode or Frequency , depending of actual measure
 

maybe, you can switch the model of measurment between
Periode or Frequency , depending of actual measure

With multi-period measurement over a fixed gate time as mentioned in post #5, you get optimal resolution for any input frequency.
 

When i am done counting the pulses of the multiple times how do i convert it into a single frequency.
 

I did not get a reply to my comments in #11.
In particular you said in addition to frequency you need to contol
" launch control , flat shift , shift light .. and ETC."

This implies rapid change of RPM and gear changing must have low lag or latency in measurement.

If velocity of engine is RPM, can you define maximum acceleration? and what range of RPM this occurs at?
Just define the worst case.

Please confirm number of spark plugs being detected again ( 1 or all) and range of spark frequency, where acceleration and shift light must be computed ?

What is the maximum delay of computing RPM allowed?
e.g. 1 cycle of 0.3Hz is 3.3 seconds lag minimum.

- Fastest RPM measurement is Time Interval for each cycle then calc. division of time interval to frequency or RPM can be quick.

- Easiest RPM measurement is Fixed Time but requires more time for pulse counts to be totalized and average ratio computed (which may be too long) also has more jitter (alias, wandering) with low input cycles per measurment

- to get 10 RPM resolution in 900 or 1:90, do you mean 10 RPM accuracy?
,if not what is accuracy?
If a fixed period RPM measurement produces say 3 or 4 input pulses, you get a resolution of 1 in 3.5 pulses when you need 1 in 90 minimum.
See the problem? ( this is what I meant in #11)

Here is a division routine for PIC http://www.piclist.org/techref/postbot.asp?by=time&id=piclist\2001\03\05\121349a where 1/t= Hz
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top