Hello everybody,
i'm having troubles using an AVR PIC KY-037 to acquire analog signal to be processed using the FHT library.
I first made a test, serial printing the signal get from the module. I read a base value i can change using the built in potentiometer from 0 to 1023 and a small signal over it. If i scream at the microphone i can have a +-100cnt, that should be enough for a preliminary test.
I used the library as shown:
#define LOG_OUT 0 // use the log output function
#define LIN_OUT 0
#define LIN_OUT8 0
#define OCTAVE 1
#define FHT_N 256
#define SCALE 1
#define OCT_NORM 1
#include <FHT.h>
void setup() {
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
while(1) { // reduces jitter
cli();
for (int i = 0 ; i < FHT_N ; i++) {
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
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();
fht_reorder();
fht_run();
fht_mag_octave();
sei();
Serial.print(fht_oct_out[0]);
Serial.print(", ");
Serial.print(fht_oct_out[1]);
Serial.print(", ");
Serial.print(fht_oct_out[2]);
Serial.print(", ");
Serial.print(fht_oct_out[3]);
Serial.print(", ");
Serial.print(fht_oct_out[4]);
Serial.print(", ");
Serial.print(fht_oct_out[5]);
Serial.print(", ");
Serial.print(fht_oct_out[6]);
Serial.print(", ");
Serial.println(fht_oct_out[7]);
}
}
Here a typical result without OCT_NORM
218, 203, 70, 52, 56, 59, 59, 56
218, 203, 68, 49, 53, 53, 59, 61
218, 203, 70, 49, 50, 56, 56, 60
218, 203, 68, 50, 52, 55, 57, 59
218, 203, 70, 55, 59, 59, 56, 58
218, 203, 71, 53, 61, 62, 58, 58
218, 203, 71, 56, 60, 57, 55, 59
218, 203, 70, 53, 61, 62, 58, 58
218, 203, 70, 49, 59, 58, 60, 59
218, 203, 69, 55, 54, 59, 59, 59
218, 203, 69, 51, 52, 53, 57, 58
218, 203, 74, 55, 57, 57, 55, 61
218, 203, 71, 49, 51, 51, 57, 56
218, 203, 70, 57, 54, 55, 55, 57
218, 203, 70, 53, 56, 56, 56, 58
and here with OCT_NORM
218, 203, 62, 34, 30, 21, 13, 8
218, 203, 61, 37, 25, 19, 16, 8
218, 203, 62, 35, 27, 21, 13, 8
218, 203, 62, 35, 27, 21, 13, 8
218, 203, 63, 30, 25, 16, 13, 8
218, 203, 62, 34, 29, 21, 16, 13
218, 203, 60, 37, 25, 22, 16, 8
218, 203, 63, 35, 29, 21, 13, 8
218, 203, 61, 34, 27, 22, 13, 8
218, 203, 63, 37, 27, 21, 16, 8
218, 203, 61, 33, 27, 22, 16, 8
218, 203, 62, 36, 27, 19, 16, 13
218, 203, 62, 33, 24, 21, 16, 8
218, 203, 61, 33, 28, 21, 13, 0
218, 203, 63, 33, 25, 19, 16, 8
218, 203, 62, 37, 25, 24, 19, 8
I thought i should have small signals (all near 0) because i'm not screaming at the microphone. Why do i have always big numbers?
Thanks
PS: The FHT somehow works: if i remove the offset i can see differences when i Whistle but i have a very noisy signal. Making a frequency test with headset i realized that first two channels doesn't change at all (maybe they are saturated) and other changes but with a lot of noise. I'll try to amplify the signal, or is it better to forget the AVR PIC KY-037 and to make a direct amplification circuit for a jack signal?

