Help with counter for frequency measurement

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

Hi,

   

I am looking for some help to measure frequency on a digital input pin. I found some information online and attempted to implement it but I am not getting correct results.

   

The attached test code is supposed to enable the counter for a period of 10ms and then read the count accumulated. My input signal is 3V Square wave with frequency = 125 kHz. The period of the input frequency is 8us. I am expecting to accumulate a count of around 1250 but actually getting 19595.

   

Processor is PSOC 5LP and I am using Creator version 3.3

   

I have attached my little test code workspace.

   

Thanks in Advance

   

David

0 Likes
1 Solution
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

I found the issue. It was the very first read was putting erroneous count into my calculation. Now I do a dummy read first (enable, wait, disable and read counter) to ensure first actual sample is valid.

   

I tried ClearFIFO but I still get rubbish in first sample.

View solution in original post

0 Likes
1 Reply
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

I found the issue. It was the very first read was putting erroneous count into my calculation. Now I do a dummy read first (enable, wait, disable and read counter) to ensure first actual sample is valid.

   

I tried ClearFIFO but I still get rubbish in first sample.

0 Likes