Hello, My name is Guu.
I recently created a program for lighting LEDs using microcontroller timer interrupts in a training session.
I would like to introduce " frequency divider " which I struggled with.
First of all
Frequency division is a method of obtaining a desired frequency by dividing a frequency.
I knew what dividing meant, but I did not know what value to use to divide the frequency well, so I went to my seniors to ask questions.
Assignment
Using a 20 MHz frequency clock, generate 10 ms.
By how many divisions do you divide the clock to get the desired frequency?
Guu "I don't know how to divide the frequency..."
Senior "..."
Senior "Do you know what Hz is 10 ms?"
Guu "1 / 10 ms = 100, so 100 Hz."
Senior "Then, how many divisions of 20 MHz will give 100 Hz?"
Guu "20 MHz / 100 Hz = 200000 divisions!"
Senior "That's right. Do you know what we need to use to divide by 200000?"
Guu "I found a "count source" in the microcontroller. I think I can divide the frequency by this!
A count source is a frequency divider of the main clock.
In this case, we could choose from 1 division (no frequency division), 2 divisions, 8 divisions, and 32 divisions.
Senior "Try dividing the frequency using the divide-by-8 count source."
Guu "Yes!"
Tried dividing the circumference using the source for the count source for dividing by 8!
Try dividing by 8 using a divide-by-8 counting source...
20 MHz / 8 = 2500000 Hz
It does not become 100 Hz at all!
Guu "Senior..., the frequency divider is not enough at all (; O ;)"
Senior "Right... (Laughs) Wasn't there anything else we could use for frequency division?"
I open the datasheet and search for "frequency division"...
Guu "There was! I found something called frequency divider ratio 1 / ( n + 1 ) ( m + 1 ) !"
*This is a method of dividing by using a timer prescaler.
Prescaler: A counter is used to divide the input frequency by an integer fraction.
Try dividing the frequency using the frequency division ratio formula as well!
Senior "Yes, this is what we use to divide the rest of the frequency. Put appropriate values for m and n and do the math."
Calculating...
Since we have just divided up to 2500000 Hz with the counting source, we need to divide the remaining 25000 divisions.
n = 24999 , m = 0?
Senior "Oh, by the way, n and m have a range that can be set, so be careful."
Guu " ! ? "
I checked the data sheet and found the following.
The setting range of n and m: 00 h ~ FF h (0 ~ 255 in decimal)
In other words, n = 24999, m = 0 cannot be set,
I re-calculated...
Guu "250 × 100 = 25000, so if we apply this to the division ratio formula...
n = 249, m = 99!"
Senior "OK!"
We were able to successfully divide the frequency using the following equation.
(target frequency) = (original frequency) x 1 / (count source) × 1 / ( n + 1 ) ( m + 1 )
100 Hz = 20 MHz × 1 / 8 × 1 / ( 249 + 1 ) ( 99 + 1 )
Notes
In this case, the count source and division ratio were set using the above combination, but these values will vary depending on how many frequencies are desired.
For example, if the clock source is set to divide by 2 in this case , the frequency divider ratio must be used to divide the clock by
100000 division by the frequency divider ratio.
However, n and m can only be set up to 255, and even if each is set to 255
( 255 + 1 ) ( 255 + 1 ) = 65536.
The counting source must be selected so that this does not happen.
When performing frequency division, please take care of the above points and try to generate the desired frequency accurately.
Conclusion
Frequency division is used to generate the desired frequency from the original frequency.
In this case, the following equation was used for frequency division.
(target frequency) = (original frequency) × 1 / (count source) × 1 / ( n + 1 ) ( m + 1 )
Setting range of n , m : 00 h ~ FF h (0 ~ 255 in decimal)
Guu's tweet
I need to be a little careful when setting the division ratio n and m.
Be careful not to set out-of-range values by accident (>_<)
New Engineer's Blush Blog Article List