Timer1.attachInterrupt( timerIsr ) problem


hi,
i'm working arduino mega calculate harmoic of signal don't know why result not correct  ( not same every time "c" ) , counter stopping in 21 due him increase every time 50  please me.

that's program :



code: [select]

void setup()
{
 serial.begin(57600);
 pinmode(a0,input);
timer1.initialize(400);
timer1.attachinterrupt( timerisr );
}
void timerisr()
{
x=analogread(a0);
var[n]=x;
n=n+1;
serial.println(n);
if(n==50) {
interrupts();
}
}

firstly hanging system calling serial in isr:

code: [select]

void timerisr()
{
  x=analogread(a0);
  var[n]=x;
  n=n+1;
  serial.println(n);  // must not call serial methods in isr!!!!!!!
  if(n==50) {
    interrupts();    // pointless, interrupts re-enabled on exiting isr
  }
}



secondly confuse == = here:

code: [select]
(i ==1;i<51;i++)


thirdly variables shared between isr , rest of code must
be declared volatile, , if more single byte in size have be
accessed within "nointerrupts() ; ... ; interrupts () ;" main
body of program avoid mangling.


Arduino Forum > Using Arduino > Programming Questions > Timer1.attachInterrupt( timerIsr ) problem


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support