Multi-Input Frequency Measurement Tutorial

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.
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

I decided to create a tutorial on various design strategies of reading multiple digital inputs (up to 16) and calculating each frequency.

Although intended to help students and those new to embedded processing, it can be used by anyone for the attached example projects and as a refresher.

I've attached a workspace with 8 projects each implementing different methods in different combinations.  Each project is an improvement on the previous one.

Here are the different methods used:

  • Polling
  • Interrupt Service Routines (ISRs)
  • Status Register Capture (SRs)
  • Direct Memory Access (DMA)
  • Multi-sample Averaging
  • Frequency Down-scaling

I've also attached a document describing each of the 8 projects with:

  • Theory of Operation
  • Design Tradeoffs
  • Design Improvements
  • Design Scalability.

The document includes Appendices about:

  • Measurement Accuracy
  • Jitter Factors
  • Measurement Range
  • Measurement Resolution

Requirements:

  • PSoC Creator 4.2

Target Hardware:

  • CY8CKIT-059.   However, little to no modifications need to be make to work on other PSoC5 platforms.  Many of the projects can be modified to run on other PSoC chips.

The example code is free to be used and modified for your own projects.

Enjoy!

Len

Len
"Engineering is an Art. The Art of Compromise."
4 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Len,

Thank you for sharing your example project with the community.

Best regards,
Hari

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Len-san,

Nice Work!

It requires a lot of jumper wires (@ @)

001_TeraTerm-log.JPG

Coincidentally, yesterday, my new 4ch oscilloscope which I ordered this week arrived.

So your project got to be the first signal(s) I viewed with my new oscilloscope 😉

IMG_4551.JPG

Ch1: UART_TX

Ch2: Stim1 - PC_1

Ch3: Stim2 - PC_2

Ch4: Stim3 - PC_3

As PC3 (P3[2]) has a bypass cap attached on the CY8CKIT-059,

the slow edge of ch4 shows that both your project and my oscilloscope are working OK.

Best Regards,

13-Dec-2020

Motoo Tanaka

0 Likes

Motoo-san,

Thank you.

You are correct.  You can connect as many inputs as you want.

If you want to reduce the external wires, 6 of the 8 projects have an additional schematic page that is currently disabled.

This disabled page internally routes the stimuli to the inputs without need of external connections.

To use the disabled page, you need to first disable the page with the pins.  Next enable the 0 pins page.  It will give some warnings.   Answer "OK".   Rebuild the project and ... viola!  All the inputs will have stimuli.   Although the input pins are eliminated, the stimuli is still routed to the output pins.

It appears you compiled Project#1 using Polling strategy.   CPU utilization: Scan = 99%.   Highly inaccurate results at higher frequency inputs.

Spoiler Alert:  Projects #8 has the best performance.  CPU utilization: DMA = 0.05%   ISR=0.0% Task = 4.8%   The application can have 95.1% CPU cycles available.

It also provided the best measurement performance even for high frequencies.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Len-san,

So, this morning I connected all 16 Stims to PC_1 ~ PC_16 and tried the #8 project.

010-TeraTerm-log-8.JPG

Yes, the accuracy of higher frequencies seem to be much better now.

Best Regards,

14-Dec-2020

Motoo Tanaka

0 Likes