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 :
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:
secondly confuse == = here:
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.
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
Post a Comment