HELP needed with a pulse measurement program

hey guys, i need a program for arduino uno, which can count external pulses given to an analog pin for minute.. the pulses will be given through CRO.. we need to count em in terms of BPM.. i sorta suck at programming.. so please help me! :frowning: =( :disappointed_relieved: :~

What is a CRO, there are 64 choices:-

Do you know these pulses are beats? That is the most difficult part. Once you have a pulse that is the beat then the rest is simple.

which can count external pulses given to an analog pin for minute

Why an analogue pin? A digital one is much simpler.
Detecting BPM does not mean you have to count the pulses for a minute, just measure the interval between two pulses and then do some simple maths.
Detect the rising edge of a pulse, that is when it makes a transition between zero and one. Then make a note of the time given by the millis() timer function. Repeat this for the next rising edge and the difference between the two millis() timers will give you the pulse period. Then it is simple to calculate how many of these you will get in a minute.

ummmm.. see what i need to do is give a 0.5Hz - 1 Hz square wave through a signal generator on a certain pin.. and i have to count the number of pulses that are generated for a minute .. so. i need help with that.. :frowning:

A small sketch to get started, it shows a point for every pulse

What you need to add is

  • a counter that increments after every pulse
  • code to print that counter
  • a "clock" to measure the time -> TIP: check the tutorial section for millis().
  • code to print the counter after 1 minute
  • code to calculate the frequency in Hertz
  • meaningful comments where needed
const int pulsePin = 10;

void setup()
{
  Serial.begin(115200);
  Serial.println("pulsecounter v0.0");
  pinMode(pulsePin, INPUT);
}

void loop()
{
   while (digitalRead(pulsePin) == LOW);
   while (digitalRead(pulsePin) == HIGH);
   Serial.println(".");
}

see what i need to do is give a 0.5Hz - 1 Hz square wave through a signal generator on a certain pin.

Sorry those words are far too woolly to make sens of.
The way I read that is you have to give, that is input to a, signal generator a signal generated by an arduino.
Now that does not accord with what you said earlier.
So what exactly do you want to do and what did you not understand about my explanation of how to measure the time between pulses?

As requested before please what is a CRO?

Your description is a little vague, but I think you want to count incoming pulses for some time interval. So I suggest this.

  1. Attach an interrupt to pin 2 or 3 (the external Arduino interrupts), set it to trigger on a rising edge;
    hook your external pulse generator to the relevant pin. Each rising edge you detect is a pulse.
  2. Set up one of the timers as, say, a 10 ms. clock; and set up an ISR(TIMER0_COMPA-vect) interrupt routine for it which
    advances a time variable by 1 as each 10 ms. passes.
  3. Set the clock time and the pulse count to 0, and then, in the PIN 2/3 interrupt routine, count how many rising edges you get
    before the time variable reaches 6000 (60 sec = 6000 x 10 ms.)
  4. There is a bit of jitter to this process, so it is better to collect multiple readings and average.

There are numerous good tutorials on line to explain the timer and interrupt coding, and learning use those processes gives you some powerful tools.

I've used this technique to measure variable Doppler frequencies with great success. Good luck.

John Doner

@grumpy_mike that CRO happened by mistake.. it meant the Cathode Ray Oscilloscope.. but i confused it with signal generator.
but what i need to do is... give square / sine wave generated through a function generator.. to a pin on the arduino board. and then, the program that have to write, will calculate the number of pulses generated on that pin in one minute. is the clear enough? :~

generated through a function generator.

The word is from not through.
Yes it is clear now.
Signal generators normally produce signals that go either side of ground so first of all you need a seriese diode and a pull down resistor to stop you damaging your arduino.
Then you just need to implement any one of the three techniques mentioned already in this thread.

:relaxed: ummm okay!! thanks!!! :slight_smile:

Maybe this will get you started
http://tushev.org/articles/arduino/item/51-measuring-frequency-with-arduino

hey mike! thanks... but guys i really don't understand how'd i go bout doin this because this is the first time i am programming on my own.. can any one give any further input as to how to write the program to count number of pulses generated, against time i.e. in a 60 seconds.. :frowning: :disappointed_relieved: =(

looks like its homework time...

seriously people here are super helpful. but you need to show that you are doing something to help yourself. your last post basically says 'teach me how to program'.

sorry, only you can teach yourself to program.

assuming you know nothing about Arduino, start with the blink without delay example. try to get as far as you can, and if you are stuck and have a specific question, then come back and post your code and people will help you...

yes i am trying.. now i need to know as to how to use the ICP1 pin... in the input capture mode

I don't know anything about using the ICP1 pin, however if I where to do this, I would try to follow the instructions by jrdoner. I would start out by learning how to set up the interrupts using this tutorial: Gammon Forum : Electronics : Microprocessors : Interrupts