Continue to Site

# Frequency scaling

Status
Not open for further replies.

#### Eclipsed

##### New Member
I'm working on a new project and I'm drawing a blank.In need to input a frequency(2000-15000hz), scale it down(0-2400hz) and add/subtract correction(+ or - 15%) in a somewhat efficient/quick manner.I will use a PIC, but the coding is where I draw a blank.I just need an idea to get me going.It doesn't have to be very accurate, but it has to be quick.Thanks a ton.

Eclipsed said:
I'm working on a new project and I'm drawing a blank.In need to input a frequency(2000-15000hz), scale it down(0-2400hz) and add/subtract correction(+ or - 15%) in a somewhat efficient/quick manner.I will use a PIC, but the coding is where I draw a blank.I just need an idea to get me going.It doesn't have to be very accurate, but it has to be quick.Thanks a ton.

There are basically two ways to measure frequency, firstly count the number of cycles during a specific time period - using a 1 second period would give you a direct reading of the frequency, but would take 1 second. Obviously using a 1/10th second gate period would only take 1/10th second, but only give a reading 1/10 of the correct frequency.

For your purposes this probably wouldn't make any difference, and you could always scale the result if required - by choosing the gate period carefully you could make the scaling very easy and fast.

The other method is to measure the length of one cycle of the waveform, or even half a cycle (if it's symmetrical) - the time taken will depend on the frequency, and be faster for higher frequencies.

There's an old MicroChip application note for a frequency counter, it uses a combination of both methods to cover from low audio to 50MHz.

What specifically are you trying to do?.

The counting part really isn't a problem, scaling it down in a timely fashion is.And how to implement the scaling.BTW its to adapt a hotwire mass airflow sensor to be used in place of a karman vortex airflow sensor.

Eclipsed said:
The counting part really isn't a problem, scaling it down in a timely fashion is.And how to implement the scaling.BTW its to adapt a hotwire mass airflow sensor to be used in place of a karman vortex airflow sensor.

Right, although I don't have a clue what they are - at least I know why it needs to be done :lol:

From your previous figures, presumably 2000Hz in should give nothing out, and 15000Hz in should give 2400Hz out, and it should be linear inbetween?. So the first thing to do is subtract 2000 from the incoming frequency - so that gives 0-13000 that needs changing to 0-2400. If you divide 13000 by 2400 you get 5.42 - so by dividing 13000 by 5.42 you get the required frequency.

Now PIC's don't like floating point numbers, so it's a good idea not to use them if you can - there are various ways of avoiding this, but it really depends on your requirements.

You mentioned it doesn't need to be particularly accurate - in that case would dividing by 5 be near enough?.

Do you have a figure for how accurate it has to be?, also how many levels of output do you need? - do you need as much resolution as possible, or would 20-30 discrete frequencies be enough - if so you could divide 13000 by 542, to get a value from 0-24, giving 100Hz output resolution.

You could scale it up, divide 1,300,000 by 542 to get the right answer, but that means going above 16 bit maths.

You also mentioned it has to be fast - how fast?. I'm presuming the sensors aren't particularly fast them selves?.

Yes I need as much output resolution as possible(hopefully <10hz), speed wise I'd like to see near real-time scaling, but I know thats not likely to happen, I guess up to ms range would be acceptable.I was thinking of using a lookup table with values(to load into the timer) corresponding to output frequencies.Which I could use 240 output values, to give me a 10hz resolution.

Eclipsed said:
Yes I need as much output resolution as possible(hopefully <10hz), speed wise I'd like to see near real-time scaling, but I know thats not likely to happen, I guess up to ms range would be acceptable.I was thinking of using a lookup table with values(to load into the timer) corresponding to output frequencies.Which I could use 240 output values, to give me a 10hz resolution.

Not that I am sure how to solve your problem, but I noticed you're using hotwire data? JOOC, double wire, single wire, or some other variety? Is it by any chance data from DLR or DNW? I'm actually working with hotwire data from those facilities at the moment, and it's interesting to see someone else post in this manner.

By hotwire I mean the sensor uses a heated wire to detect airmass.

Have you considered an analog approach? That is, and FV followed to a VF converter.

Yeah I have considered it, in fact that was my original plan, but digital seems to be the simplest solution.

The problem can be broken down into three parts. First, there is frequency detection from 2-15KHz. Second part is scaling the result to range 0-2400Hz. Third problem is generating the frequency out.

Here is my suggestion on solving the third problem. Let's say the range of frequency 0-2400Hz is represented by an 8-bit value 0-255 in register FREQ_VAL. Assuming, you setup the PIC to generate a periodic interrupt of frequency 4800Hz, the interrupt service routine (written in pseudo assembly routine) would be as follows:

Code:
ISR:
SAVE_CONTEXT_MACRO
;
MOVF     FREQ_VAL,W
BTFSS    STATUS,CARRY
GOTO     ISR_END
;
TOGGLE_OUTPIN
ISR_END:
RESTORE_CONTEXT_MACRO
retfie

Frequency scaling can be done via lookup table 256 items long.

Status
Not open for further replies.

Replies
7
Views
2K
Replies
23
Views
4K
Replies
41
Views
6K
Replies
11
Views
4K
Replies
3
Views
2K