How to find the pulse width of unknown frequency using 8051 microcontroller

Started by September 8, 2005
Respected Experts,
                  I am Ravikumar.N, working on 8051 microcontroller. I
have an issue regarding the pulses of unknown frequency.

I am equipped with the following things:
        1) I have an 8051 based development baord.
        2)I have an unknown frequency source.

My Purpose:
       I want to measure the pulse width of the unknown frequency that
will be fed to 8051.

My queries:

     1) I dont know to which pin of 8051, these unknown frequency
pulses has to be fed inorder to measure the pulse width.

    2) Please let me know what logic has to be used to calculate the
pulse width after these pulses(unknown frequenc pulses) are fed to an
appropriate pin of 8051 microcontroller.


Thanks In Advance,
             Ravikumar.N

ravikumar.n@sunlux-india.com wrote:
> Respected Experts, > I am Ravikumar.N, working on 8051 microcontroller. I > have an issue regarding the pulses of unknown frequency. > > I am equipped with the following things: > 1) I have an 8051 based development baord. > 2)I have an unknown frequency source.
Which 8051/80c51? Different 8051 based devices offer different peripherals. You could use I/O pin level transition interrupts or timers.
> My Purpose: > I want to measure the pulse width of the unknown frequency that > will be fed to 8051.
You might find something in the http://www.8052.com/ code library. A frequency counter would use one of the Timer pins. For pulse width measurement, you could configure the internal timer as a timer to count at certain speed, and put it into gated mode. Signal to INTx/P3.2 and c.f. the GATE bit(s) in TMOD or TCON. With the gating, you can then read the counter value, from which you can determine the pulse width (ON-time, and OFF-time you get with some small calculations from the ON-time and the frequency). For details how to config the timer(s) I think you should check the datasheet and programming reference for your particular 8051. - Jan
Thanks Jan,
                            I am using ATMEL based AT89c52
microcontroller.

ravikumar.n@sunlux-india.com wrote:
> Thanks Jan, > I am using ATMEL based AT89c52 > microcontroller.
Ok then this one http://www.keil.com/download/docs/189.asp should work for you. In the .zip, main.lst contains assembler that you can use for your reference if you don't have a the Keil C compiler. - Jan
ravikumar.n@sunlux-india.com wrote:

> Thanks Jan, > I am using ATMEL based AT89c52 microcontroller.
Get the manual, and search for the word Capture. Microcontrollers do not measure frequency, they measure time, and can count internal or external clock edges, and capture. The approach you use will depend very much on the "unknown Frequency", relative to the CPU clock, and how many digits of precision you want on the result. -jg
"Jim Granville" <no.spam@designtools.co.nz> wrote in message
news:4320962b$1@clear.net.nz...
> ravikumar.n@sunlux-india.com wrote: > > > Thanks Jan, > > I am using ATMEL based AT89c52 microcontroller. > > Get the manual, and search for the word Capture. > > Microcontrollers do not measure frequency, they measure time, > and can count internal or external clock edges, and capture.
Oh? If I apply my signal to the counter input, the micro measures frequency. If I apply the signal to a capture input, the micro measures time. IMHO. Meindert
Meindert Sprang wrote:

> "Jim Granville" <no.spam@designtools.co.nz> wrote in message > news:4320962b$1@clear.net.nz... > >>ravikumar.n@sunlux-india.com wrote: >> >> >>>Thanks Jan, >>> I am using ATMEL based AT89c52 microcontroller. >> >>Get the manual, and search for the word Capture. >> >>Microcontrollers do not measure frequency, they measure time, >>and can count internal or external clock edges, and capture. > > > Oh? > > If I apply my signal to the counter input, the micro measures frequency.
Nearly; it actually simply counts edges. (as I said above) If you want Frequency, you need to capture that count result, at accurate time intervals, and do some maths. Hz = Cycles/Time ie to get Frequency, you need two counters, one for the timebase, and one for the Fu, and ideally, the Fu counter clears-on-capture, from the period signal of the timebase. With this HW, when you read, you read Frequency. Such HW can be created in CPLDs, and FPGAs, but is very rare in uC. Most uC lack the "Timer1 triggers capture of Timer2" etc HW paths, but in the 89C52, you could externally wire a HW output pin ( like TXD ) to the Capture T2EX IP pin. Pulse WIDTH is also non trivial; in pure HW - Capture gives pulse PERIOD ( which may be what that OP actually meant? ) In the C52, you CAN apply an external gate, to the T0,T1 counters, so it only INC's when gate is HIGH, but there is no HW capture, thus you have to react in SW, to grab the result while the IP is low, and that imposes a time limit. If the OP uses a 89C51RD2, with the PCA, then it is possible to capture both edges, and derive Period and PW. This also has upper and lower Frequency/period limits. -jg
Meindert Sprang wrote:

> "Jim Granville" <no.spam@designtools.co.nz> wrote in message > news:4320962b$1@clear.net.nz... > >>ravikumar.n@sunlux-india.com wrote: >> >> >>>Thanks Jan, >>> I am using ATMEL based AT89c52 microcontroller. >> >>Get the manual, and search for the word Capture. >> >>Microcontrollers do not measure frequency, they measure time, >>and can count internal or external clock edges, and capture. > > > Oh? > > If I apply my signal to the counter input, the micro measures frequency.
Nearly; it actually simply counts edges. (as I said above) If you want Frequency, you need to capture that count result, at accurate time intervals, and do some maths. Hz = Cycles/Time ie to get Frequency, you need two counters, one for the timebase, and one for the Fu, and ideally, the Fu counter clears-on-capture, from the period signal of the timebase. With this HW, when you read, you read Frequency. Such HW can be created in CPLDs, and FPGAs, but is very rare in uC. Most uC lack the "Timer1 triggers capture of Timer2" etc HW paths, but in the 89C52, you could externally wire a HW output pin ( like TXD ) to the Capture T2EX IP pin. Pulse WIDTH is also non trivial; in pure HW - Capture gives pulse PERIOD ( which may be what that OP actually meant? ) In the C52, you CAN apply an external gate, to the T0,T1 counters, so it only INC's when gate is HIGH, but there is no HW capture, thus you have to react in SW, to grab the result while the IP is low, and that imposes a time limit. If the OP uses a 89C51RD2, with the PCA, then it is possible to capture both edges, and derive Period and PW. This also has upper and lower Frequency/period limits. -jg
"Jim Granville" <no.spam@designtools.co.nz> wrote in message
news:4320962b$1@clear.net.nz...
> ravikumar.n@sunlux-india.com wrote: > > > Thanks Jan, > > I am using ATMEL based AT89c52 microcontroller. > > Get the manual, and search for the word Capture. > > Microcontrollers do not measure frequency, they measure time, > and can count internal or external clock edges, and capture.
Oh? If I apply my signal to the counter input, the micro measures frequency. If I apply the signal to a capture input, the micro measures time. IMHO. Meindert
ravikumar.n@sunlux-india.com wrote:

> Thanks Jan, > I am using ATMEL based AT89c52 microcontroller.
Get the manual, and search for the word Capture. Microcontrollers do not measure frequency, they measure time, and can count internal or external clock edges, and capture. The approach you use will depend very much on the "unknown Frequency", relative to the CPU clock, and how many digits of precision you want on the result. -jg
ravikumar.n@sunlux-india.com wrote:
> Thanks Jan, > I am using ATMEL based AT89c52 > microcontroller.
Ok then this one http://www.keil.com/download/docs/189.asp should work for you. In the .zip, main.lst contains assembler that you can use for your reference if you don't have a the Keil C compiler. - Jan
Thanks Jan,
                            I am using ATMEL based AT89c52
microcontroller.

ravikumar.n@sunlux-india.com wrote:
> Respected Experts, > I am Ravikumar.N, working on 8051 microcontroller. I > have an issue regarding the pulses of unknown frequency. > > I am equipped with the following things: > 1) I have an 8051 based development baord. > 2)I have an unknown frequency source.
Which 8051/80c51? Different 8051 based devices offer different peripherals. You could use I/O pin level transition interrupts or timers.
> My Purpose: > I want to measure the pulse width of the unknown frequency that > will be fed to 8051.
You might find something in the http://www.8052.com/ code library. A frequency counter would use one of the Timer pins. For pulse width measurement, you could configure the internal timer as a timer to count at certain speed, and put it into gated mode. Signal to INTx/P3.2 and c.f. the GATE bit(s) in TMOD or TCON. With the gating, you can then read the counter value, from which you can determine the pulse width (ON-time, and OFF-time you get with some small calculations from the ON-time and the frequency). For details how to config the timer(s) I think you should check the datasheet and programming reference for your particular 8051. - Jan
Respected Experts,
                  I am Ravikumar.N, working on 8051 microcontroller. I
have an issue regarding the pulses of unknown frequency.

I am equipped with the following things:
        1) I have an 8051 based development baord.
        2)I have an unknown frequency source.

My Purpose:
       I want to measure the pulse width of the unknown frequency that
will be fed to 8051.

My queries:

     1) I dont know to which pin of 8051, these unknown frequency
pulses has to be fed inorder to measure the pulse width.

    2) Please let me know what logic has to be used to calculate the
pulse width after these pulses(unknown frequenc pulses) are fed to an
appropriate pin of 8051 microcontroller.


Thanks In Advance,
             Ravikumar.N