cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

I am trying to measure frequency of an input analog signal using Comparator (to create digital signal) that feeds into a counter. I am also utilizing a window PWM as capture to the counter.

   

However, it doesn't show the correct frequency when I connect AC_in and AC_ref to a function generator that produces 50Hz sine wave. I am also using a limiting and biasing external circuit as shown in my Top Design. 

   

It works well with only square wave. I have attached my project below. 

0 Likes
12 Replies
JoMe_264151
Expert II

Welcome in the forum.

   

Your counter is not reset after one measure, so the next time you will read 100 as captured value.

   

Better is: use measure_StartEx() API and provide your own handler in your own file. That avoids editing in generated files.

   

As a general rule: Global variables that get changed in an interrupt handler must be declared as volatile.

   

You get design errors because you have put the comparator pin connections at the wrong end of your schematic components:

   

The pin ends the PSoC and your caps and diodes are outside the PSoC. Confirm that outside connections are drawn in blue lines.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

Thank you for your suggestions!

   

My counter is reset at the rising edge of my capture (which comes from my generated window PWM signal).

   

I put those external connections there as a reference, I will correct them to the right end.

   

My problem is however when the connections are in the right order (as you suggested), and I drive my Sine wave signal through,  it doesn't show the correct frequency. It shows random values from 01 to 99 on my LCD screen.

   

It does on the other hand, work well with square wave signals. 

0 Likes
JoMe_264151
Expert II

What does your comp_test output look like on a logic analyzer? Can there be too much noise on your sine output of function generator?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I have attached the screen from my oscilloscope. 

   

Channel 1 (Yellow) is my input signal which has mean at 2.5V and peak to peak 1.3V

   

Channel 2 (Green) is the comparator signal.

   

Both of them have 50 Hz frequency. I have used hysteresis in my comparator to account for some of the noise.

   

The funny thing is that it now works okay for frequencies ranging from 0 - 60 Hz after I change my input reference pin from 3.1 to 3.2 on Psoc. Higher frequencies couldn't work as reliably.

0 Likes
EvPa_264126
Valued Contributor II

Try increasing the hysteresis and counter_1   period

   

 

   

0 Likes
Anonymous
Not applicable

Does using R2 help to increase the hysteresis? Or do we have to do that through API?

   

What does increasing counter period do? My signal is only 50-100 Hz so the counter doesnot have to count that much?

0 Likes
JoMe_264151
Expert II

When you are using a CY8CKIT-059: There is a cap to GND on P3_2.

   

Which Kit are you using??

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I am just using CY8CKIT-059 PSoC® 5LP

   

http://www.cypress.com/documentation/development-kitsboards/cy8ckit-059-psoc-5lp-prototyping-kit-onb...

   

I have tried to look at the datasheet for this device and couldn't find the section that has pins and bypass capacitors. Can you refer me to that section?

0 Likes
JoMe_264151
Expert II

Here it is.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Would it not matter anyways because I am passing a DC reference input into pin 3.2 so a bypass capacitor would just smooth out the signal?

   

Anthony.

0 Likes
JoMe_264151
Expert II

Didn't you say that running on P3_2 was better than P3_1? That might be the reason.

   

 

   

Bob

0 Likes
rola_264706
Honored Contributor II

I found some issues with your program in the area of the matching network on AC in . Resistor R_1 is shorted out by wire from AC_in to the Diode D-1. This entire network is not connected correctly. Pavloven example above is done correctly.  I also found an error in your interrupt routine it had two errors.  I have commented these and you will need to fix it. As a standard practice you should not make changes to Auto generated parts of the Program. 

0 Likes