[time-nuts] Frequency Counter using OCXO and MCU

d0ct0r time at patoka.org
Wed Mar 12 15:38:33 UTC 2014


I am using old Wavetek 180 signal generator for the tests. I just hooked 
its TTL output directly to the pin of MCU. The STM32F4xx has core clock 
168 mHz and its inputs capable to handle pretty wide range of frequency. 
I don't think 1-2 mHz connected to the pin should be a problem. At least 
in my setup it shows me adequate result for that frequency. But its 
slows done the "main loop" a lot because its interrupting million time 
per second. For 2 mHz input, I'll need to wait several seconds to see 
the result. Of course I could remove averaging or decrease number of 
samples to improve that time.
I am still thinking why I have incorrect results for low frequency. May 
be counter overflows could impact the result.
The counter for my timer is 16 bit. That means it will generate overflow 
after 65535 counts. The timer frequency is 168 mHz. Then it will 
overflows around every 400 uS (or 2563.5 Hz). Probably any frequency 
which is lower than 2.5 kHz will shows me incorrect results. Probably 
I'll need to think how to handle that.

Regards,

V.P.

On 2014-03-12 10:18, Chris Albertson wrote:
> Are you putting the "unknown signal" to be measured on an interrupt
> pin?  that will work for low enough frequencies but most uPs have a
> built-in counter.   It is a hardware register on the uP chip that
> will increment for each pulse on a pin.  then you read that number
> and divide by the gate time.   At some point the frequency will be to
> high for the counter pin so then you switch in a hardware frequency
> diver as a pre-scaler.
> 
> On Tue, Mar 11, 2014 at 8:24 PM, d0ct0r <time at patoka.org> wrote:
> 
>> 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: %ulnr", uwTIM1Freq);
>>             accum = j = 0;
>>         }
>>     }
>> 
>> The counter is based on timer in "input capture" mode and driven by
>> interrupt:
>> [ See STM32F4xx_StdPeriph_ExamplesTIMTIM_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
>> [1]
>> 
>> --
>> WBW,
>> 
>> V.P.
>> _______________________________________________
>> time-nuts mailing list -- time-nuts at febo.com
>> To unsubscribe, go to
>> https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts [2]
>> and follow the instructions there.
> 
> --
> 
> Chris Albertson
> Redondo Beach, California
> 
> Links:
> ------
> [1]
> http://www.qsl.net/va3iul/Homebrew_RF_Circuit_Design_Ideas/Sine-to-Square_Wave_BJT_Converter_Wenzel.gif
> [2] https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts

-- 
WBW,

V.P.



More information about the Time-nuts_lists.febo.com mailing list