Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate the average of pulse #59

Open
shadowwalkersteam opened this issue Aug 31, 2017 · 7 comments
Open

Calculate the average of pulse #59

shadowwalkersteam opened this issue Aug 31, 2017 · 7 comments

Comments

@shadowwalkersteam
Copy link

shadowwalkersteam commented Aug 31, 2017

How i can calculate the average of pulse sensor? I have tried this code but it didn't worked and even the values didn't showed up in serial monitor and in processing.
`
for(int i=0; i<64; i++)

{ // Average over 16 measurements
Signal += analogRead(pulsePin);
}

Signal= Signal/64;
`

@shadowwalkersteam
Copy link
Author

I did this in interrupt.ino where it is reading from A0

@joelSensor
Copy link
Member

joelSensor commented Aug 31, 2017

Interesting.
Well, you are taking 64 readings of the ADC. It takes Arduino (ATmega) about 100uS to do an Analog read. Your loop takes ~6.4mS to complete. There's your problem right there.
You need to reduce the number of samples you are averaging. Our Arduino Code interrupts to sample every 2mS. You need to limit the amount of samples you take to >20.

Also, are you resetting the Signal variable to 0? If not, you are just adding and adding to it.

@shadowwalkersteam
Copy link
Author

Ok i'll try that... I'm using arduino pro mini and i'm using timer1 as it mentioned that is used 9 and 11 pin and my 9th and 11th pin are not free will it cause a problem or should i use timer2 for pro mini 5v version

@shadowwalkersteam
Copy link
Author

which is more stable? and what is the threshold value so that i could minimize the noise

@biomurph
Copy link
Contributor

The only thing that the Timer selection does to those pins is not allow you to use PWM.
Timer 2 breaks PWM on pins 3 and 11
Timer 1 breaks PWM on pins 9 and 10
You can use those pins for other digital things.

As for the threshold, you will have to play around with the default value of the thresh varialbe in the interrupts

@shadowwalkersteam
Copy link
Author

shadowwalkersteam commented Sep 1, 2017

Okay.. please suggest me which timer i should use for pro mini 5v 16mhz ?

@biomurph
Copy link
Contributor

biomurph commented Sep 1, 2017

You could use either one.
Depends on if you want to use PWM on any of the pins. Simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants