Go Down

### Topic: Pulse Counting (Read 2904 times)previous topic - next topic

#### superedd

##### Feb 26, 2013, 08:53 pm
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

Superedd

#### PaulS

#1
##### Feb 26, 2013, 08:58 pm
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.
The art of getting good answers lies in asking good questions.

#### Darwoon

#2
##### Feb 26, 2013, 09:13 pm
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  ).
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).

#### UKHeliBob

#3
##### Feb 26, 2013, 09:18 pm
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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

#### superedd

#4
##### Feb 27, 2013, 12:22 am
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

#### PaulS

#5
##### Feb 27, 2013, 12:26 am
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.
The art of getting good answers lies in asking good questions.

#### MarkT

#6
##### Feb 27, 2013, 12:59 am
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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### nickgammon

#7
##### Feb 27, 2013, 07:18 am
http://www.gammon.com.au/forum/?id=11504
Please post technical questions on the forum, not by personal message. Thanks!

#### superedd

#8
##### Feb 27, 2013, 07:29 pm
Hi All, Thanks again for your help, I am still unsuccessful in counting pulses, can anyone show an example code

Thanks

Superedd

#### nickgammon

#9
##### Feb 27, 2013, 09:24 pm
The link I gave above had a paragraph near the start "Counter 1 - used to count pulses".

That had example code.
Please post technical questions on the forum, not by personal message. Thanks!

#### UKHeliBob

#10
##### Feb 27, 2013, 09:30 pm

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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up