Pages: [1]   Go Down
Author Topic: Pulse Counting  (Read 1145 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, This is my first time here and I am fairly new, I am looking for a simple way to count pulses coming from a sensor, Any suggestions

Thanks in advance

Superedd
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am looking for a simple way to count pulses coming from a sensor, Any suggestions
1, 2, 3, ...

What kind of sensor? How long are the pulses? How frequently do they arrive? Counting 10 1 second pulses a minute is trivial. Counting 10000 pulses per millisecond is a bit more challenging.
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't count pulses coming from a sensor, but count the speed your arduino board get sensor values.
What's your arduino board ? Uno has a 16Mhz clock... it can easily make 10 000 loop if you're just reading the tension (but not using Serial.print, then you have only 300 loops  smiley-razz).
Count the number of loop for a second  e.g., comparing the time you began with millis() (returns the number of milliseconds since the board began running your current program).
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4317
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Set a counter to zero
Every time a pulse arrives from the sensor add one to the counter
That's it really

As has been suggested, more details would help.
Have you written any code to read the sensor, whatever it is ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Everyone thanks for all your posts and help, i will explain in more detail what i am trying to accomplish:

I need to count pulses coming from a Geartooth sensor, which will provide a pulse every time a "tooth" will pass it, the gear i am using have 70 teeth and its turning at 1500 rpm therefore the frequency of the pulses are at about 1750 Hz.

I intend to use another hall effect sensor to reset the counter each time the gear is making a full turn so its need to count only up to 70.

I use Arduino Mega 2560

Any suggestion commands / code will be greatly appreciated

Superedd
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To deal with 1.750 pulses per second, reliably, you probably want to use an interrupt handler. Connect the hall effect sensor to one of the external interrupt pins (there are 5 to choose from on the Mega), and attach a handler to that pin. You can use either RISING or FALLING. Don't use CHANGE or LOW, though.

In the ISR, all you do is increment a counter (volatile). In loop(), you can use that counter and millis() and an interval to calculate speed. There are any number of posts, with code, showing how to calculate RPM that should give you clues.
Logged

0
Offline Offline
Shannon Member
****
Karma: 214
Posts: 12424
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have details of the sensor - some generate clean logic pulses with a single transition are switching (the sensor has
some hysteresis and avoids slow changing output or contact bounce).

Less well behaved sensors may need signal conditioning (hardware and/or software) in order to get a correct count.

In particular hall effect sensors can be analog or digital (logic output), and the latter are usually fine (they have enough
hysteresis to give clean pulses).

Sometimes noise can be picked up from the nearby electrical equipment to inject false noise spikes into your sensor
cable - this is particularly an issue in the "automotive environment" - signal conditioning can help here, you try to
filter out the noise and leave the pulses-of-interest intact.
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19036
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/forum/?id=11504
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All, Thanks again for your help, I am still unsuccessful in counting pulses, can anyone show an example code

Thanks

Superedd
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19036
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The link I gave above had a paragraph near the start "Counter 1 - used to count pulses".

That had example code.
Logged


East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4317
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All, Thanks again for your help, I am still unsuccessful in counting pulses, can anyone show an example code

Thanks

Superedd
Are you going to share the code that is unsuccessful in counting pulses ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Pages: [1]   Go Up
Jump to: