You are here

Frequency Counter, How to reduce UDB | Cypress Semiconductor

Frequency Counter, How to reduce UDB

Summary: 8 Replies, Latest post by DhruvAcharya on 02 Mar 2015 01:26 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
user_202683688's picture
42 posts


Hi there,
I have implemented Frequency (RPM) measurement using ideas displayed on various thread by Dana. I have attached project. I have two issues now:
1.      I want to reduce the usage of UDB as I have four channels of RPM to be measured and many other function needs to implement. I think I will need extra space in UDB. How can I change Counter Block to fixed functions? I have tried it but it says :
Timer "\RPMCounter_1:CounterHW\" can only use one of the digital clock dividers or bus clock as the clock source.
2.       See in attached project I have used 12KHz clock to simulate RPM. I have connected external wire link from this RPM_Freq output (P0[6]) to RPMSig_1 input(P0[2]). For 12KHz it displays perfect values on LCD, but for 15KHz it displays ‘zero’ on LCD. If I try to give direct 15KHz on schematic page (as direct clock source internally in silicon, no external link). It perfectly displays Frequency and RPM. Do I missing something here? Will my development work when I connect actual RPM signal (0-50KHz)?


user_14586677's picture
7646 posts

Some questions -


1) Given you want to measure 0 - 50 Khz (0 - 50 KRPM ?), what

resolution of the measurement do you want ?

2) Accuracy of measurement ?

3) Do you need to make 4 simultaneous measurments of RPM or could

you use a 4 channel mux and measure them sequentially ? If latter any

restrictions on latency of measurement ?


Regards, Dana.

user_78878863's picture
2553 posts

Regarding the UDBs: you are using a 16-bit counter, which needs 2 UDBs AFAIR. Since all other components don't need to be duplicated,, this means you need 8 UDBs to count for 4 channels - and the PSoC5 has 24. So there should be room to spare.

For the routing error - the FF counter can just count clocks, it works that way (says even so in the data sheet).

Regarding your second question: The code is quite difficult to follow with all these states. Mayb reduce the RPM_Convert_Process function into a simple loop that waits until the counter has captured (FIFO not empty) and then calculates the resulting RPM directly. Having done that you can directly display the value on the LCD.

Even better: use an ISR to read the capture value which is triggered by a capture event.

user_202683688's picture
42 posts




/* Style Definitions */
{mso-style-name:"Table Normal";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-fareast-font-family:"Times New Roman";

Thank Dana and Hli for reply.


Dana, I think 16 Bits with 5Hz for Gate frequency will do the work for me and that is what I have tested with my application.


As of now 4 simultaneous measurement is required, so I will use separate counters and as hli said it will consume only 8 UDBs (I have tested with four 32 bit counters previously that is why I was out of UDB I think). But if four 16 bit counter will not serve purpose then I will definitely consider MUX.


Hli, for your confusion, sorry. Now I have taken bob’s example from this thread:


and modified according to my Hardware.


Now see, schematic page “Measure”, I have made RPM_Out (P0[6]) and RPMSig_1 (P0[2]). I have made a wire link between this two pin on kit “CY8CKIT-050”. See on schematic page “Clocks”, Clock_3 = 15KHz. Now if I program kit, it shows 0 Hz on screen. Now if I connect direct wire on schematic page “Measure”, and delete the pins and program on kit it shows 15000 Hz.


Got it? Please help me with that. Thanks in advance


user_14586677's picture
7646 posts

There is confusion regarding the function of HW connection on a pin, hopefully

this will illuminate why your schematic wired connection not working -



user_202683688's picture
42 posts

Thanks Dana for the reply, and sorry for the confusing posts of mine. I think Hardware connection setting is fine. Here I am attaching a picture, hoping that it will make my issue clearer to you.

Case 1)

RPM frequency is generated 12 KHz, Routed to PIN P0[6], through a external wire(jumper) connected to PIN P0[2]. Result working fine

Case 2)

RPM frequency is generated 15 KHz, Routed to PIN P0[6], through a external wire(jumper) connected to PIN P0[2]. Result working not OK.

Case 3)

RPM frequency is generated 15 KHz, directly connected on schematic with Frequency Counter. Result working not OK.

user_14586677's picture
7646 posts

You mentioned you wanted to minimize UDBs, this project measures PW as well

as period (therefore frequency) and uses a fixed function counter.




user_202683688's picture
42 posts

Thanks dana for the point. But I got confused. If you have some link or project related to that, I would request you to share it. Thanks again.

user_202683688's picture
42 posts


As I sees that the two issue I facing is different from one another so I think I should create second thread for second issue.

Here is the link for the second issue of "external link" problem.

Log in to post new comments.