PulseSensor_Amped_Arduino icon indicating copy to clipboard operation
PulseSensor_Amped_Arduino copied to clipboard

Timer0 instead of Timer2

Open frugallabs opened this issue 9 years ago • 1 comments

Hello, Can someone help me out in implementing the interrupt on Timer0 instead of Timer1 or Timer2.

I have a WiFi module connected to pins 9,10,11 of the Arduino Nano. These pins are fixed on myt PCB and cannot be replaced.

So I am unable to use the WiFi module if I use Timer1 or Timer2 as my WiFi does not work. The WiFi module will send the pulse (BPM) to the cloud.

Can anyone help me out in implementing Timer0 for the code? I do not mind compromising on delay().

frugallabs avatar Nov 28 '16 16:11 frugallabs

It's recommended that you don't use Timer0 on the ATmega 328 boards because Timer0 is used for the delay() and delayMicroseconds() and I think the millis() and micros() as well. Try using a 'software interrupt' instead. Here's a short example:

unsigned long lastTime;
unsigned long thisTime;

setup(){
lastTime = micros();
}

loop(){
thisTime = micros();
if(thisTime - lastTime > 2000){
lastTime = thisTime;
//goto the read-sensor-and-get-pulse routine
}
// do the other stuff you want to do
} 

Hope that helps!

biomurph avatar Nov 28 '16 17:11 biomurph