Go Down

Topic: Nano timers and interrupt usage (Read 477 times) previous topic - next topic

foruonlyfrom007

Hi,
I am new to Arduino though I'd worked with PIC before.  I got the MsTimer2 working on the Mega but on the Nano, it doesn't work.  Does Nano have timer2.  As the matter of fact, where do I find out more about the resources of certain device and how to use them?  Supposed in Arduino, lots of features are written up as libs, but I've also seen people writing timers and interrupt using direct keywords just like in MCU???  Please enlighten me in this new subject.
Thanks,
The simple sketch I tried:

#include <MsTimer2.h>
boolean output = HIGH;

void flash() {
  digitalWrite(13, output);     // pin13 has an LED build on board
  output = !output;
}

void setup() {
  pinMode(13, OUTPUT); 
  MsTimer2::set(500, flash); // 500ms period
  MsTimer2::start();
}

void loop() {}

pylon

The Nano has a Timer2 and the new version of the library should support it too.

Your code is missing a "volatile":

Code: [Select]
volatile boolean output = HIGH;

That's because you're changing the value in an interrupt routine and without the "volatile" the compiler may optimize the variable away because it's not used in active code. The "volatile" is a hint to the compiler that the variable is used in a way not transparent to the compiler.

CrossRoads

Quote

As the matter of fact, where do I find out more about the resources of certain device and how to use them?

Best source for resources is the Atmel datasheet on the part.
Often times there are assembler and C code examples too.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up