cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

DaHu_285096
Contributor II

I am having trouble understanding how to use the counter component to measure frequency. I did google and find the example for frequency counter and thought I could use software to enable the timer instead of the PWM. But the document does not give any example code for reading the counter - so I assume you simply Counter_ReadCounter().

Attached is the code snippet I am trying and the settings I used for the counter.

The input signal is 125.05 kHz and the sample window is 10ms

The input signal is correct (I am viewing on a scope and have frequency counter attached).

The count should be 1250 but I am getting wild values from 1100 to 2000

From what I read, the counter is enabled and reset when the component is Started, it then starts counting up and when stopped, the count register holds the number of transitions over the period.

Thanks in advance

0 Likes
Reply
1 Solution
odissey1
Honored Contributor II

There are many ways to measure frequency. It is a balance between accuracy and dedicated system resources. I recommend to start with simple working example above and then modify it to your needs. Best counting accuracy which can be achieved this way is ~(1/2) x 125kHz x 10 ms = 625, e.g. 9-bit. Using software delay can only worsen it. Solution depends on what accuracy needed.

If result is needed only once on startup and h/w resources are limited, it all can be done in software by counting pulses directly using interrupt and utilizing SysTick timer to count delay window - no hardware needed. The 125kHz is low enough to use pin interrupt. Of course, the system will hang for some 10ms, but there is no penalty for that on startup.

/odissey1

View solution in original post

0 Likes
Reply
5 Replies