You are here

Modify Frequency Measure Code | Cypress Semiconductor

Modify Frequency Measure Code

Summary: 7 Replies, Latest post by danaaknight on 09 Nov 2013 07:32 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
user_272923555's picture
17 posts

Would you be able to help direct me in modifying this code/program on this link above to measure frequency to measure the frequency of an AC generated sin wave input into the PSoC. The output of the AC sine wave is my phone so the peak to peak voltage is going to be small somewhere around 10mV. Just a note I am using the GND pin on the PSoC so I believe I have to use a resistor and a capacitor (link below).


user_1377889's picture
9274 posts

A micro capturing sound will not easily deliver a pure sinus since you will get a mixture of different frequencies. Amplifying the signal up to limitation will give an approximation but will jitter due to the other frequencies.


I suggets you to spend some thoughts into signal-conditioning (Input with a C,level shifting with R,Amplifying with 1 or more PGAs, band pass filtering etc). The usual method with a timer / counter (depending on the frequency to analyze) will give the first result. Since this will be distorted by noise the next step could (should) be some calculations (averaging) to math-out jitter and / or noise.


Happy coding


user_14586677's picture
7646 posts

Some questions -


1) What is the range of frequencies coming from phone ?

2) How long is the frequency transmited to PSOC ?

3) Frequency you want to measure -

     a Accuracy ?

     b Range ?

     c Resolution ?

4) What causes the phone to have only 10 mV to the PSOC ? Eg, what

comprises the signal path ? Is the phone speaker the generator, a seperate

mic on PSOC the transducer for the frequency ?

5) Tolerable latency of the measurment ?

6) Overall function of the design ? General terms.


Regards, Dana.

user_272923555's picture
17 posts

The range of frequencies would be from 500hz to 2kHz. The reason the phone only generates 10mV is because that is the signal coming from a 3.5mm cord jack.

I would have to amplify this voltage with a PGA/buffer in order to get an appropriate signal?

What would be an appropriate gain?

Do you know the operating range for the PSoC analog voltage inputs?

Do you know how I would modify the AN2283 program for measuring frequency in order to measure a generated sin wave from my phone?

I tried modifying the program for measuring frequency and put in a PGA and still was not getting a read at all the result was "underrange" because the f=0 meaning it was not working. Would I have to use an ADC? From what I know I can just use the comparator to measure analog frequencies correct?

Thanks so much for your help!


user_14586677's picture
7646 posts





Several possibilities –


1)      PGA followed by comparator. Experiment with G of PGA, but I would start around

10, then feed that to comparator. Comparator out goes to counter or timer to do the measurement.


2)      If you have a lot of noise use a BP filter in front of PGA. Since BW is large might want to use 4 pole solution.


3)      Use the module and device datasheet to get at CM in range for analog signals.


4)      To measure freq supply a counter enable with a timer gate. If you want 1 Hz resolution, then gate = 1 sec, 10 Hz gate = 100 mS……Then supply counter input with Fx. Note they are down counters, so when gate is low, counter not enabled, load max value into counter (8 bit counter max = 255, 16 bit = 65535) then when gate goes high it will count down from there. When gate goes low read counter, subtract from max value, and that is the number of Hz (1 sec gate) Fx is.


5)      Basic counter ap notes attached.


Regards, Dana.

/* Style Definitions */
{mso-style-name:"Table Normal";
mso-padding-alt:0in 5.4pt 0in 5.4pt;

user_14586677's picture
7646 posts

Forgot the ap notes. Attached.

user_14586677's picture
7646 posts

Here is a very basic freq cntr, 24 bit, 1 Hz gate = 1 Hz resolution, you can alter

as needed. Note no signal conditioning done, assumed logic levels from



Many notes in main.c file as to how it operates. Also you can eliminate the

test counter I sued to test the F cntr.


Regards, Dana.

user_14586677's picture
7646 posts

If you need a filter something like below, you would have to optimize to get equal

response at Hi and Low BW limits. -


Log in to post new comments.