In the picture we can not say how well implemented frequency counter. Please specify how peripheral initialization and measurement procedure.
Following the 2. link, you will see the source-code of 'f_mess.c'. This is the very first implementation of reciprocal counter on STM32F407 and shows the basic operation only.
https://www.mikrocontroller.net/attachment/158664/f_mess.c16 bit counter TIM9 is used as reference counter running at 168 MHz. Once initialised TIM9 is never stopped again!
Each event on PE5 (TIM9-capture input) increments a 32 bit software-counter and gives an exact time-stamp with 5,95 ns (1/168 MHz) resolution. Overuns of TIM9 are counted as well and are always taken into account, resulting in 32 bit time-stamps synchronously to the input event.
LOOP:
Starting measurement synchronously with the first input event, after some time (arround 0.5 s for 8 digits) you can take the last time-stamp (end_zeit -> end_time), substract the first time-stamp (start_zeit -> start_time) and you’ll get the actual time (mess_zeit -> act_time):
act_time = end_time – start_time;
Doing the same thing with counted input pulses you will get the number of events (mess_ereignisse -> act_count) as the difference of last count (end_ereignis -> end_count) and first count (start_ereignis -> start_count):
act_count = end_count – start_count;
To prepare next calculation simply update start_time and start_count:
start_time = end_time;
start_count = end_count;
Finally we want to see the result of frequency:
frequency = act_count * 168e6 / act_time;
Convert and display frequency and
goto LOOP:
Looking at the photo of TFT-display act_count is displayed as 'Nin' and act_time as 'Nref'.
During measurement there is no stop (no missing input event). That is why you will get one reading/s @ 1 Hz input signal. For faster results with less digits needed, you can reduce measurement time to 1 ms and will get 1000 readings/s @ 5 digits resolution.