Are these delays you used then less than the minimum?
No. The delays used are somewhat over the minimums. I’ll try the 1ms waits.
Going back to Post #7…
ET (us) = 1328
ET (us) = 4294967148
ET (us) = 4294967144
ET (us) = 4294967144
The following link explains the issue. “TIMSK0 = 0;” messes up micros(), hence the unexpected value, and commenting this line restores the timer and micros() now reads correctly.
http://forums.openmusiclabs.com/viewtopic.php?f=7&t=312
Back to FHT, Getting noisy values (but now a believable ET (us) value)…
Start: 22144 251 44 67 50 69 9 66 40 59 43 61 44 42 50 33 28 27 33 74 44 60 28 15 38 12 26 35 30 32 26 23 34 ET (us) = 10836
Start: 22400 95 48 163 115 71 81 99 25 48 17 50 29 55 58 23 61 5 4 42 54 46 42 47 20 36 68 22 27 23 31 27 14 ET (us) = 10832
Start: 22016 122 260 29 47 38 71 86 38 68 25 36 44 26 12 68 3 25 29 39 31 30 55 78 16 35 16 38 3 32 33 31 23 ET (us) = 10836
Start: 22016 251 61 27 79 88 99 150 59 77 30 44 20 57 51 41 45 12 7 55 86 40 32 31 38 44 42 32 37 63 23 45 14 ET (us) = 10832
Start: 22016 154 78 195 45 142 64 112 34 32 26 14 52 21 69 39 20 31 34 34 29 40 52 20 25 29 9 54 25 35 43 20 22 ET (us) = 10832
Start: 22272 544 122 41 61 32 94 81 36 48 21 8 34 53 21 52 41 30 34 45 4 20 29 32 22 14 29 56 16 24 32 26 32 ET (us) = 10832
Start: 22016 326 249 205 2 61 61 27 53 84 36 45 65 18 65 12 13 47 11 10 21 34 42 44 20 22 35 32 10 9 26 25 26 ET (us) = 10836
Using this code…
/*
fht_adc_serial.pde
guest openmusiclabs.com 7.7.14
example sketch for testing the fht library.
it takes in data on ADC0 (Analog0) and processes them
with the fht. the data is sent out over the serial
port at xxx.xkb.
*/
/* version 1.1
*/
#define LIN_OUT 1 // use the log output function
#define FHT_N 256 // set to N point fht, 16, 32, 64, 128, 256 (gives N/2 freq bins)
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
// Libraries in "C:\Users\rick\Documents\Arduino\libraries"
#include <FHT.h> // include the library
unsigned long StartTime = 0;
unsigned long EndTime = 0;
void setup() {
int SoftwareMajRev = 1; // Major Revision
int SoftwareMinRev = 1; // Minor Revision
// Blinks for Major Revision
for (int i = 1; i <= SoftwareMajRev; i+=1){
digitalWrite(13, HIGH); // Turn ON the "Beat Detected" LED
delay(150);
digitalWrite(13, LOW); // Turn OFF the "Beat Detected" LED
delay(150);
}
delay(500); // Wait between Major and Minor Revision blinks
// Blinks for Minor Revision
for (int i = 1; i <= SoftwareMinRev; i+=1){
digitalWrite(13, HIGH); // Turn ON the "Beat Detected" LED
delay(150);
digitalWrite(13, LOW); // Turn OFF the "Beat Detected" LED
delay(150);
}
/*
Prescale ADPS2,1,0 Clock(MHz) S.Rate(kHz) BW(kHz)
2 0 0 1 8 615 307
4 0 1 0 4 307 153
8 0 1 1 2 153 76.8
16 1 0 0 1 76.8 38.4
32 1 0 1 0.5 38.4 19.2 ADCSRA = 0xX5;
64 1 1 0 0.25 19.2 9.6 ADCSRA = 0xX6;
128 1 1 1 0.125 9.6 4.8 ADCSRA = 0xX7;
#Bins BW(Hz) Res.(Hz/bin)
FHT_N 128 64 19,200 300.0 ADCSRA = 0xX5;
FHT_N 64 32 4,800 150.0 ADCSRA = 0xX7; Global variables use 430 bytes (20%) of dynamic memory
FHT_N 128 64 9,600 150.0 ADCSRA = 0xX6;
FHT_N 128 64 4,800 75.0 ADCSRA = 0xX7; Global variables use 622 bytes (30%) of dynamic memory
FHT_N 256 128 4,800 37.5 ADCSRA = 0xX7; Global variables use 1,006 bytes (49%) of dynamic memory,
*/
Serial.begin(38400); // use the serial port
// TIMSK0 = 0; // turn off timer0 for lower jitter, but delay() and micros() WILL NOT WORK.
ADCSRA = 0xe5; // set the adc to free running mode, and set Prescaler
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
} // end Setup
void loop() {
while(1) { // reduces jitter
StartTime = micros();
// cli(); // UDRE interrupt slows this way down on arduino1.0. This also seems to disrupt the timer.
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc, and set Prescaler
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fht_input[i] = k; // put real data into bins
}
// fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_lin(); // take the output of the fht
// sei(); // This also seems to disrupt the timer.
//StartTime = micros();
//delayMicroseconds(2000);
EndTime = micros();
Serial.print("Start: ");
// for (byte i = 0 ; i < FHT_N/2 ; i++) {
for (byte i = 0 ; i < 33 ; i++) { // Just print the first 32 bins.
static char stmp[16];
sprintf(stmp,"%3d ",fht_lin_out[i]); // send out the data
Serial.print(stmp);
}
Serial.print(" ET (us) = ");
Serial.print(EndTime - StartTime);
Serial.println();
}
}
Which performs a 256 point FHT at a 38.4kHz sample rate.
Thought the noisy readings might be due to having no antialiasing filter but the mic preamp is spec’d at 20 - 20kHz, so should already in a sense be limiting the audio input to 1/2 the sample rate or 19.2kHz.
Read that this code scales the input to 512 to account for + & - readings (don’t know where in the code though), but the mic preamp output is already at V+/2 or 2.5V. Could that be causing the noisy readings?
Any idea why the noisy readings?