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

Timer0 instead of Timer2 #31

Open
frugallabs opened this issue Nov 28, 2016 · 1 comment
Open

Timer0 instead of Timer2 #31

frugallabs opened this issue Nov 28, 2016 · 1 comment

Comments

@frugallabs
Copy link

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().

@biomurph
Copy link
Contributor

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!

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

2 participants