10MHz Frequency Divider

Thread Starter

Jimmy Mejia

Joined Oct 13, 2019
6
Hi!
Thank you in advance. I want to design a circuit whose output will go into 16 bit ADC input. I want to divide 10MHz square wave frequency by 32. i.e. 0.3125MHz. For me to do this, I'd like to use a frequency divider. I've been finding it difficult to find a IC that can do this (not in stock). I am deciding to go with a 10-bit D flip-flop IC. This seems reasonable to do as I can just connect the output of each flip-flip to the input of another. One of my concerns doing this is any type of coupling between traces as the pins will most likely loop back into another pin on the IC. I'd like some opinion on this if possible. Thank you!
 
Last edited by a moderator:

Thread Starter

Jimmy Mejia

Joined Oct 13, 2019
6

Thread Starter

Jimmy Mejia

Joined Oct 13, 2019
6
What are you hoping to measure with the A/D?
I actually want to measure the voltage of the signal. I don't think the ADC of MCU can sample at greater than 10MHz so i'd like to "slow it down" to eventually measure the voltage. That would also allow me to ensure the frequency is some factor 10MHz.
 

Ian0

Joined Aug 7, 2020
13,097
Measure the voltage of the 312.5kHz signal coming out of the counter? Yes - the voltage will be correct - there's no reason to measure it - unless you have connected something to it that you shouldn't!
 

MrChips

Joined Oct 2, 2009
34,626
You don't measure frequency with an ADC, at least not directly. An ADC measures voltage.
You can measure 10MHz directly with STM32 using TIMER input, depending on which STM32 you are using.
 

Thread Starter

Jimmy Mejia

Joined Oct 13, 2019
6
Measure the voltage of the 312.5kHz signal coming out of the counter? Yes - the voltage will be correct - there's no reason to measure it - unless you have connected something to it that you shouldn't!
you're right. it shouldn't change the voltage. I have a signal coming in, 10MHz at say 3.3V. I want to "verify" the signal by reading the voltage level and frequency but now that I think of it I wouldn't be able to measure the frequency without an additional input to the STM32.
 

Thread Starter

Jimmy Mejia

Joined Oct 13, 2019
6
You don't measure frequency with an ADC, at least not directly. An ADC measures voltage.
You can measure 10MHz directly with STM32 using TIMER input, depending on which STM32 you are using.
yes I think i was to focused on figuring out how to measure voltage I overlooked how I was going to measure frequency. Verifying frequency is probably more important in my application after discussing some more about it using this thread.
 

Ian0

Joined Aug 7, 2020
13,097
yes I think i was to focused on figuring out how to measure voltage I overlooked how I was going to measure frequency. Verifying frequency is probably more important in my application after discussing some more about it using this thread.
I'm not familiar with STM32s, but it's a fair bet that you can configure an input to clock a counter.
Then all you have to do is read the value of the counter at a fixed interval (say every second, if it's a 32-bit counter) then the value you read from the counter is the frequency. Don't forget to reset the counter once you have read it!
 

MrChips

Joined Oct 2, 2009
34,626
You don't have to reset the counter. You take two consecutive readings of the counter and take the difference. You do not have to worry about counter overflows (up to maximum limit).

Some STM32 timers are 32-bit counters.
 

Ian0

Joined Aug 7, 2020
13,097
You don't have to reset the counter. You take two consecutive readings of the counter and take the difference. You do not have to worry about counter overflows (up to maximum limit).

Some STM32 timers are 32-bit counters.
You'll get an overflow every 429 reads - every 7 minutes - so you do have to deal with overflows. If you get negative answer when you subtract the previous read from the latest the simply add 2^32 to correct it - or reset the counter every time you read it!
 

MrChips

Joined Oct 2, 2009
34,626
You'll get an overflow every 429 reads - every 7 minutes - so you do have to deal with overflows. If you get negative answer when you subtract the previous read from the latest the simply add 2^32 to correct it - or reset the counter every time you read it!
I disagree. I have done this many times.

Let's take an example.
1st reading = 65000
overflow occurs
2nd reading = 10000

Difference = 2nd reading - 1st reading = 10000 - 65000 = $2928 in 16-bit unsigned integer arithmetic = 10536
10536 is the correct result.
 

WBahn

Joined Mar 31, 2012
32,702
You'll get an overflow every 429 reads - every 7 minutes - so you do have to deal with overflows. If you get negative answer when you subtract the previous read from the latest the simply add 2^32 to correct it - or reset the counter every time you read it!
It depends on how the processor deals with overflows (specifically, does it throw a hardware exception, does it saturate, or does it wraparound), but usually it is done via wraparound so that it doesn't matter as long as you use unsigned arithmetic in your software -- as long as there is no possibility of two overflows within the same sampling period.
 

Ian0

Joined Aug 7, 2020
13,097
I disagree. I have done this many times.

Let's take an example.
1st reading = 65000
overflow occurs
2nd reading = 10000

Difference = 2nd reading - 1st reading = 10000 - 65000 = $2928 in 16-bit unsigned integer arithmetic = 10536
10536 is the correct result.
True, provided you have the same number of bits in the arithmetic as you do in the counter (and, as @WBahn pointed out, provided that the overflow doesn't cause an error)
i.e. it works for 16-bit arithmetic and 16-bit counters, and for 32-bit arithmetic and 32-bit counters, but not for 32-bit arithmetic and 16-bit counters.
If speed is important it is quicker to reset the counter than to retrieve the previous result from RAM and perform a subtraction (with or without compensation for overflow)
 
Top