How can i count the no. of pulses that comes into pin of microcontroller 89s52?

I am using a microcontroller 89S52 in my small project...My project is
to display ration of the amount of air exhaled in the 1st second and
also at the end of the forced expiration(normally 6 seconds ).For that
im using a small fan.. in one end there is an IR LED source and in the
other end there is an IR when the fan rotates due to the
air blown it cuts the IR light to the detector and hence we get pulses
as trying to count that pulses using a counter of the
microcontroller..and for counting the pulses at the end of the 1st
second i have used a timer...How can i count the pulses at the end of
the 6th second of expiration?please explain...
Reply to
Muhammed Shafi
Loading thread data ...
Muhammed Shafi a écrit :
Sorry, I'm not sure to understaind.
A person starts blowing. Second 0 to 1 : You count the rotation of fan (for 1 second) Second 1 to 5 : You do nothing Second 5 to 6 : You count the rotation of fan (for 1 second)
It's that you want ?
débutant inside(c)
Reply to
Warning: I'm a software developer who dabbles in microcontrollers as a hobby, not a pro as far as microcontrollers are concerned.
What you could do (if your hardware supports it) is set up an interrupt that gets triggered by signal level or status change on your pulse input. In that interrupt, increment the n-th location of an array of ints. Increment the index n every second (starting with n=0), using e.g. your timer.
That's the basic idea - you'll have to make sure your counting is correct, you initialize your array with all zeroes before counting, your integer type can handle the maximum number of pulses per second, your array is large enough to handle the maximum expected expiration time (and you do something sensible if that is the case nevertheless) but basically, you'd end up with
int pulses[MAX_SECONDS];
pulses[0] is the number of pulses in the first second, pulses[1] is the number of pulses in the second second, ... pulses[n] is the number of pulses in the last second
You could stop measuring once there's a couple seconds with 0 pulses. (If that is your problem - you really need to explain more about what you intend to measure exactly)
Regards, Gilles.
Reply to
Gilles Kohl

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.