Simple Frequency Counter

Newest information
Please refer following.
/users/kenjiArai/notebook/frequency-counters/

1) Summary

I made a very simple frequency counter for checking CPU clock and other purpose.
It runs on following boards.

1) mbed LPC1768
[Input] p30,cpu->P0[23]
2) mbed LPC1114FN28
[Input] dp14,cpu->PIO1_5/CT32B0_CAP0
3) ST Nucleo F401RE
[Input] PA_0,cpu->PA0/TIM2_CH1
4) ST NUcleo F411RE
[Input] PA_0,cpu->PA0/TIM2_CH1

The Library and example program access hardware registers directly on the each CPU.
From this reason, you cannot change the pin assignment for "Frequency Input".
In addition, you cannot import the program for other mbed boards without modification.
The sample program runs with LCD but if you comment out "#define USE_TEXT_LCD" and "#define USE_GRAP_LCD", you don't need any additional hardware.
Just connect to PC via USB com line, you can see the frequency measured data in your terminal software.

2) Picture

/media/uploads/kenjiArai/f411_02.jpg /media/uploads/kenjiArai/lpc1114_02.jpg /media/uploads/kenjiArai/lpc1768_02.jpg /media/uploads/kenjiArai/lpc114_output0.png

3) Hardware Circuit

For a simple test, please connect following pins.

1) mbed LPC1768
p30 connects p21
2) mbed LPC1114FN28
dp14 connects dp18
3) ST Nucleo F401RE
PA_0 connects PA_8 or PC_9
4) ST NUcleo F411RE
PA_0 connects PA_8 or PC_9

4) Software

I referred following programs.

1) 5MHzOSC by fuyono sakura
http://developer.mbed.org/users/mio/code/5MHzOSC/
http://developer.mbed.org/users/mio/
2) fc114 by Tetsuya Suzuki
http://developer.mbed.org/users/rutles/code/fc1114/
http://developer.mbed.org/users/rutles/

Thanks Fuyono-san and Suzuki-san.

Import libraryfreq_counter

Frequency Counter Library. Only for mbed LPC1768, mbed LPC1114FN28, Nucleo-F401 and Nucleo-F411. No way to change pin assign.

Import programFrequency_Counter

Only for mbed LPC1768, mbed LPC1114FN28, Nucleo-F401 and Nucleo-F411. No way to change pin assign.


4 comments on Simple Frequency Counter:

03 Apr 2015

This is great that it works still step 3 Simple Test; I am trying to test run a clock on Nucleo-F401 at 2MHz using the fastPWM code by Eric. I have one board outputting a 2MHz through PB_3. And I try to measure it on the second board with your code freq_counter. However, the board with your code works with the PA_0, but not the PB_3 on another board. I understand these one analog and one digital.

Do you have any advice on how I can check my signal of 2MHz using your code? Thanks.

09 May 2015

Hi Peter,
I'm very sorry not to read your question until today.
For F401 mbed, we can only set PA_0 for "Frequency counter input pin" because Timer 2 input pin is dedicated to PA_0 pin as input capture function.
F401 mbed with this frequency counter PA_0 connects 2MHz PWM Generator mbed board PB_3 (with common GND connection).
I hope you can measure the frequency.
In addition, mbed library has changed to use TIM2 for tick counter.
From this reason, if you update mbed lib., you may have a trouble!!
Don't update mbed lib.!!

14 Jul 2015

I'm controlling a MIT with a inverter that I constructed. Then I need two things, read the actual speed rotor and, after a good math, write the correct spwm. My problem begin when I have to read the pulses of the encoder to calculate the actual speed rotor: I lost pulses in my rise interrupt, because when my program calculates and writes the spwm, it leave to read pulses. My solution probably is change this read method. You can help me?

I am finding another way to get this pulses, because the wait time of your program is bad for me. I have to write a spwm and then just get the pulses of the rotor.

My MBED is F401.

12 Jul 2018

I have to use Timer 2 channel 3, so what I need to change in specific code: Frequecy_Counter

Please log in to post comments.