Pages: 1 [2]   Go Down
Author Topic: Help with a pulse detection func  (Read 982 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46219
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't use delay() in an ISR. That ISR is populating an array. In loop(), read the data in that array, and do something. Do NOT add code to a function you do not understand.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4029
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do NOT add code to a function you do not understand.

There goes 80% of all problem-with-the-code threads....

Logged

Examples can be found in your IDE.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46219
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There goes 80% of all problem-with-the-code threads....
You say that like it's a bad thing.  smiley-cool
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4029
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sven, you don't need interrupts.

Just run fast through loop() without delays and you will be plenty fast enough -- a few microseconds, maybe as fast as 1 microsecond per pass.

Before you code, make your plan. Something like this perhaps?
------------------------------------------------------------------------------------
Start loop()
Read the pin
Did the pin change state from LOW to HIGH? (or HIGH to LOW, however you count the pulse)
{
  Yes -- add 1 to pulse count
  Is pulse count > what you want?
  {
    Yes -- do whatever you do when pulse count has reached the limit
    Zero pulse count
  }
  Save the pin state so you know when it changes again.
}
else
{
  Did the pin change state from HIGH to LOW?
  {
    Yes -- save the pin state so you know when it changes again.
  }
}
End loop() -- takes you back to the Start
------------------------------------------------------------------------------------

What is missing is "whatever you do when pulse count has reached the limit".
Do that with the least steps possible. You should be able to get away with serial print given the long pulse times you first posted (longer than a second? with tight code, 10 millis is long!) and the 100-120 pulses you're counting. The great majority (over 99%) of passes through loop() would see no change in pin state at all. Count those (use an unsigned or unsigned long) and see, you will likely be surprised and maybe learn how really fast loop code is.
Logged

Examples can be found in your IDE.

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

did u solved your problem ?
because i have same project
i want to count heart beat then display it on LCD

hope u got the solution
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4029
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You know those finger-tip-clamp pulse monitors at hospitals? I wonder if they work by light reflected or light passed through the very finger tip? There is a bright red light without heat involved.

I imagine a piezo could do the job of electronic stethoscope. Biggest part of that is separating heart beat from other body noises. Piezo is sensitive enough given that they can be used to detect ants walking on them.

https://www.youtube.com/watch?v=8ZVFKvgJQtA

Logged

Examples can be found in your IDE.

Pages: 1 [2]   Go Up
Jump to: