how to count number of pulses in a signal using 8051

Status
Not open for further replies.

navneet sngh

Junior Member level 3
Joined
Feb 13, 2011
Messages
29
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
CHANDIGARH
Activity points
1,468
hi all,i am using 36khz signal.i am making it on for 0.5 seconds and 0.75 seconds.how can i distinguish between two signals by using 8051?can i do it by using timers and counters of 8051(by making timer on for 1 second and counting pulses during that 1 second)?if yes,can someone tell me code for it in c.
 

U can use input capture, if your mcu has one. You can set it up so that one rising edge starts the timer and the next one stops it. Knowing the clock source and settings of mcu you can then calculate actual time between pulses and hence, frequency.
 

actually i want to distinguish between two switches pressed.first switch will make 555 timer (generating 36 khz )on for 0.5 seconds.second switch will make same 555 timer to on for 0.75 seconds.so how can i use my 8051 to distinguish which switch is pressed
 

Hi,

By thinking out of the box, since 36 KHz is very close to 38 KHz which is the carrier frequency of most IR receivers (3-pin transistor-like IC, found in most sets controlled by IR remote), I do the following:

I drive an IR LED with the 36 KHz (better if possible making it 38 KHz, unless the IR receiver already made for 36 KHz). There will be no need for high LED current since the LED will be placed close to its IR receiver.

The receiver has 3 pins; Vcc ground and data. Vcc is usually for 5V. The data pin is usually connected internally to the collector of an npn transistor. So a resistor as 4K7 is likely needed between the data pin and Vcc. The IR LED and receiver are placed facing each other.

When the receiver detects the presence of the carrier (here 36 KHz or 38 KHz) the data pin voltage becomes close to zero (ground), otherwise it is close to Vcc. So for the project here, at the receiver data we get one of two low pulses; 0.5 sec or 0.75 sec.

In this case, the MCU code needs to start a timer (in mode 1; 2 8-bit counter) at the falling edge (an edge INT could be used) then stop it at the rising edge. Since the time is relatively long a third 8-bit register should be added and be incremented at each timer interrupt. For 8 MHZ and AT89C2051, the timer interrupt occurs every 100ms (actually 98.304ms) so during the timer interrupt one can also check if the data pin returned to high or not. For the 0.5 sec, the 6th interrupt entry signals the end of the pulse and the 8th one signals the end of 0.75 sec.
This method is good when we have a simple low-cost MCU that needs doing other jobs while detecting the signal.

Please note that this method is just one solution among many others. I mentioned it just to give its possibility for this specific project,

Kerim
 

thanx kerimf.i want these two different pulses of 0.5 seconds and 0.75 seconds to switch on two different devices.by using timers and counters we can count pulses of these signals.i do not know anything about the use of timers.can u tell me code in c for timers
 

Hi,

When I started working with CPUs (as Z80) I had neither a complier nor an assembler. Then I was lucky and I got an assembler (on DOS). Later I shifted to ATMEL MCUs like AT89C2051, AT8C51, AT89S8252 and AT89S8253 (last year SST89E58RDA from SST). I write a program (firmware) for any of them by using a text editor and a DOS assembler (it also runs on Windows 7). This direct practice helped me make my programs exactly the way I like (some are rather very complex) by being able to use any feature of the MCU to its greatest speed and/or strength. Although I also write some software in C (for PC) by using a DOS compiler (old BORLANDC), I couldn't get a C compiler/simulator for C51 MCUs.

I meant by this long introductory, I am not sure how I can help you because I am not familiar writing code in C.

For instance, which MCU you look to use for this project?

Kerim
 

First I will download its datasheet and see if it is compatible with mine at least in what concern your project.
For instance, is it a homework?

Added:
What is the crystal frequency?

Yours (64K) seems much like the one I have SST89E58RDA (40K).

Getting the code, Is it urgent?

Added:
I am waiting your three answers... ok?
 
Last edited:

its not homework...i am trying some projects to increase knowledge in microcontrollers
crystal frequency is 11.0592 mhz.
and code requirement is urgent because my hardware part is ready,just this part is left
 

Hi,

You know, to write a working code, the hardware should be well defined first. Let us see what we have:

Crystal 11.0592 MHz (I wished it were 12 MHz so that the MCU cycle unit would be exactly 1us, 12/12MHz)
I don't think you got the IR LED and receiver... right? So we have no choice but to count the pulses.
Since we will count the pulses, what is the idle state of the signal (when no pulses exist)? Is it high or low?
Do you think during the idle periods, the signal could have also random pulses (due to noise as it is the case with IR/RF receivers)?
Are there some MCU I/O pins that the new code shouldn't use, likely because they are already used for other jobs?

I think for the time being knowing these points is enough to start writing the code

Kerim
 
Reactions: Din0

    Din0

    Points: 2
    Helpful Answer Positive Rating
navneet sngh
I have some lab sheets for use of timer and counting of pulses with examples in assembly, If this could interest you I will post those !
A Raoof Khan
 

what did u make on for 0.5 sec and 0.75 sec.....which is duration for which u r making the thing ON?
 

hi milind,
i am making a 36 khz generating 555 timer on for 0.5 and 0.75 seconds.i want my microcontroller to differentiate between two signals
 

So you mean to say that 36Khz signal is avalible on micro controller pin for 0.5 sec and 0.75sec.....did I catch u r problem correctly ?
 

yes milind .you are right.i am giving these signals to T0 (p3.4)pin of microcontroller.so that i can count the pulses in 1 second and distinguish between two signals.can u tell me the how to do this.and please tell me code in c also,if u can.
is there any other way also to do this?

---------- Post added at 17:51 ---------- Previous post was at 17:50 ----------

yes milind .you are right.i am giving these signals to T0 (p3.4)pin of microcontroller.so that i can count the pulses in 1 second and distinguish between two signals.can u tell me the how to do this.and please tell me code in c also,if u can.
is there any other way also to do this?
 

I am attaching a lab sheet giving all the details you need for practical implementation of counting of pulses in one second.
The only difference is that here Port pin P 3.5 is used where as you are using P3.4 and the other difference is that the code is in assembly so more easy to understand the logic. You can implement it in C by suitable modification.
Please let me know if it serves your purpose !



Regards
A Raoof Khan
 

Attachments

  • Experiment Timer counter.doc
    30.5 KB · Views: 222
Hi Navneet,

Get the look at these two method on web-

8051 Pulse Width Measurement Example
**broken link removed**

I think you will get the idea how to implement it.....

There are C codes there just try to put your case there....

Good Luck
 
There is one more easier way of distinguishing between two type of inputs.
The pulse duration !!
if there are pulses coming from two different sources or from the same source with different time dutation then these can be discriminated by measuring the time duration of the pulse.
This is a better solution for the application like the one you are looking for.
A similar worksheet for duration of pulse is readily available if needed
A Raoof Khan
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…