Merge pull request #21 from edgar-bonet/fix-rollover

FFT_03.ino: fix micros() rollover issue and sampling frequency
pull/22/head
Enrique Condes 2018-09-19 18:49:30 +08:00 zatwierdzone przez GitHub
commit a060c2f7d1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 3 dodań i 3 usunięć

Wyświetl plik

@ -53,15 +53,15 @@ void setup()
void loop() void loop()
{ {
/*SAMPLING*/ /*SAMPLING*/
microseconds = micros();
for(int i=0; i<samples; i++) for(int i=0; i<samples; i++)
{ {
microseconds = micros(); //Overflows after around 70 minutes!
vReal[i] = analogRead(CHANNEL); vReal[i] = analogRead(CHANNEL);
vImag[i] = 0; vImag[i] = 0;
while(micros() < (microseconds + sampling_period_us)){ while(micros() - microseconds < sampling_period_us){
//empty loop //empty loop
} }
microseconds += sampling_period_us;
} }
/* Print the results of the sampling according to time */ /* Print the results of the sampling according to time */
Serial.println("Data:"); Serial.println("Data:");