1

I am trying to read an analog input (A0) with a speed of 10KHz, using the library Due Timer, but, when I increase the value of the vector it crashs, the goal is to use the vector in a FFT analysis with a 5000 size vector. I have tried to work directly with SAM3X83 Timers but I get the same problema. and this prolem is driving me craaaazy!!

Pls, I would appreciate any help. Thx.

#include <DueTimer.h>

int v[5000];

void setup(){ 

  Serial.begin(9600);

  Timer3.attachInterrupt(Read);

  Timer3.start(100); 

  analogReadResolution(12);

}

void loop(){}

void display(){  

  for(int j=0; j<5000; j++){ 

  Serial.println(v[j]); 

  }

}

int i=0;

void Read(){ 

  v[i]=analogRead(A0);

  i++;

  if (i>=5000){

    i=0;

    Timer3.stop();     

    }
}
John
  • 11
  • 1
  • What is "the value of the vector" in this code? – MikeCAT Nov 15 '15 at 02:08
  • Where your code crashs ? – Ôrel Nov 15 '15 at 11:00
  • Hi, I couldnt sleep after receiving your answers so I started coding again, I got it solved. Although I forgot add the call to the display function, it didnt work because it was Out the loop "loop", this is what I did and Works perfectly: – John Nov 16 '15 at 05:10
  • int i=0; void Read(){ v[i]=analogRead(A0); state = !state; digitalWrite(led, state); i++; if (i>5000){ Timer3.stop(); i=0; flag = 1; } } – John Nov 16 '15 at 05:15
  • I had to call the displaying function from the loop loop, that is the only way it worked, the led pin was for measure the frecuency and be sure the frecuency was the correct using a usb data analyzer – John Nov 16 '15 at 05:17

1 Answers1

0

if you use DutTimer you have to use volatile variables

volatile is a keyword known as a variable qualifier, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable.

Declaring a variable volatile is a directive to the compiler. The compiler is software which translates your C/C++ code into the machine code, which are the real instructions for the Atmega chip in the Arduino. Link

A.M.Saheb
  • 1
  • 1