Setting the frequency of microcontroller

Thread Starter

hc8th

Joined Jul 14, 2009
4
Hi all, need some help here, as i'm new to uc i have a few problems of how to use it properly, i'm capturing som signal using uc, the signal is 135Hz max, how i can set the prescaler of the uc to match the capture signal so that i could take som measurement? the signal is a digital pulse (50-50 duty cycle)
thanks to all.....
 

kkazem

Joined Jul 23, 2009
160
HI hc8th,

The answer to your question is that you wouldn't. In other words, capturing a 135 Hz 50% duty cycle digital signal with your uC depends very little on the uC clock frequency. It depends on what your trying to capture also. Are you trying to measure the digital input's frequency or it's duty cycle, or it's pulse-width? for some of those, depending on the uC you use, if the clock is fairly slow, like 1 MHz, then the accuracy of your measured digital signal will degrade a bit versus using a 100MHz clocked uC.

There are two main ways of doing what you want. First, use a uC that has a built-in peripheral circuitry for measuring digital inputs, like the TI, TMS320F2812. For a basic, non DSP uC, like an 8048 or similar, you would use the digital input to drive one of the interrupt inputs on the uC, you may even need to use two interrupt lines, one for the rising edge and the other for the falling edge, then, using your software (firmware) interrupt code, you can start a counter or something with the rising edge, then either read the counter with the falling edge interrupt or stop the counter then read it. There is another way, but it's more complicated. It uses a digital phase comparator IC with your digital input signal on one input and the uC divided-down clock as the other input. Using the phase comparator IC output thru a low-pass filter, then into a comparator IC with the reference set as your digital input voltage level divided by two, and the comparator output as an input to an interrupt line to the uC. It works like this: if the interrupt is low (for example), then the divided clock output of the uC is at a lower frequency than the digital input. your code would sequentially increase the uC divided down clock frequency until the comparator output goes high, triggering an interrupt. Then from the uC clock speed and the divider ratio that produced the interrupt, you can calculate the digital input's frequency.
There are I'm sure many other ways, but since you weren't too specific on exactly what you're trying to measure from the digital input to the uC, I can't be any more specific.

Good luck,
Kamran Kazem
 
Top