Go Down

Topic: Sampling at 8 Khz (Read 77 times) previous topic - next topic

cobmetal

Jun 29, 2015, 03:48 pm Last Edit: Jun 29, 2015, 03:49 pm by cobmetal
Hi , i'm using an DUE model and trying to sample data , using analogRead , at 8 Khz , as i read here , https://www.arduino.cc/en/Reference/AnalogRead , it takes 100 microseconds to read the port , i've added a 25 microsecond delay , and a led indicatior when my while loop is finished to sample , im sampling about 80,000 values , at 8 bit resolution .
this is my code :

yte arr[80000];
int ledPin = 22;
int sw = 24 ;
int i = 0 ;
int flag = 0 ;
int j = 0 ;
int Sw_state = 0;

void setup() {
  // put your setup code here, to run once:
  Serial1.begin(115200);
  Serial.begin(115200);
  pinMode(ledPin , OUTPUT);
  pinMode(sw , INPUT);
}


void loop() {
 
 
  if ( flag == 0 ) {
      while ( i< 80000 ){
        analogReadResolution( 8 );
        arr = analogRead(A0);
        delayMicroseconds(25);     
        i++ ;
        if ( i== 80000 ) {
           
          flag = 1 ;
        }
      }
  }
  Sw_state = digitalRead(sw) ;
  if (flag == 1) {
   digitalWrite(ledPin , HIGH);
  }
  if ((flag == 1) &&  (Sw_state == 1)) {
    digitalWrite(ledPin,LOW);
    while ( j < 80000 ) {
      Serial1.write(arr[j]) ;
      j++ ;
        if (j == 80000 ){         
          flag = 2 ;
        }
    }
  }
 
}

the problem is , that the led turns on immediately after flashing is done , and not after 10 seconds as expected. what do you think guys , what is wrong with my code ? 

charliesixpack

Try initializing the pin LOW in setup().

Go Up