[time-nuts] Frequency Counter using OCXO and MCU

d0ct0r time at patoka.org
Tue Mar 11 23:24:23 EDT 2014


Hello,

I am experimenting to build frequency counter using external OCXO and 
ST32 MCU. The OCXO is external DATUM 2750013-1 device which produce 
10Mhz sine wave. I connected its output to OC_IN on MCU. I have few 
challenges now.

First, looks like I need to create some delay to turn on MCU _after_ 
OCXO. If I try to start both devices simultaneously, I got following 
result for 10 kHz TTL measurement:


System Core Clock: 168000000 Hz
SYSCLK_Frequency PCLK1_Frequency PCLK2_Frequency
16000000         16000000        16000000

# Starting SuperLoop...
FREQ: 105197
FREQ: 105263
FREQ: 105263
FREQ: 105263


As soon as I push reset button on MCU, I got correct results for its 
clocks and correct value for the counter:


System Core Clock: 168000000 Hz
SYSCLK_Frequency PCLK1_Frequency PCLK2_Frequency
168000000        42000000        84000000

# Starting SuperLoop...
FREQ: 10019
FREQ: 10019
FREQ: 10019
FREQ: 10019
FREQ: 10018
FREQ: 10019


Another challenge is the fact, that if I increase the input signal 
frequency, then performance of the MCU decreased. In the other word, I 
need to wait much more time to have a result. Probably MCU is super busy 
to handle the interrupt. Say for 10 kHz range its pretty fast. Then for 
1 mHz its much slower.

Here is main loop:

while (1) {
         if(j++ < 0xF00000) {
             accum += deltaREF; // Moving Average
             accum = (accum >> 1);
         } else {
             uwTIM1Freq = (uint32_t) SystemCoreClock / accum;
             printf("FREQ: %ul\n\r", uwTIM1Freq);
             accum = j = 0;
         }
     }

The counter is based on timer in "input capture" mode and driven by 
interrupt:
[ See STM32F4xx_StdPeriph_Examples\TIM\TIM_InputCapture ]

Also this counter shows incorrect results for low frequency. For 
example, for 100 Hz:

FREQ: 4968
FREQ: 5030
FREQ: 5056
FREQ: 4916

I would be interesting to hear any advise how to improve it.

And another question is: what will be "pros" and "cons" to transform 
10Mhz sine to square to feed MCU ? I tried it, but didn't catch any 
difference.

Here is schema
http://www.qsl.net/va3iul/Homebrew_RF_Circuit_Design_Ideas/Sine-to-Square_Wave_BJT_Converter_Wenzel.gif


-- 
WBW,

V.P.


More information about the time-nuts mailing list