From f26c24f83eba172804efbdf506cf18d19f48b176 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 17 Apr 2015 11:09:45 +0200 Subject: Import project --- arduino/fht_test.ino | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 arduino/fht_test.ino (limited to 'arduino') diff --git a/arduino/fht_test.ino b/arduino/fht_test.ino new file mode 100644 index 0000000..0e2f83c --- /dev/null +++ b/arduino/fht_test.ino @@ -0,0 +1,68 @@ + +// FHT Options +#define FHT_N 256 +#define SCALE 256 +#define WINDOW 1 +#define REORDER 1 +#define LOG_OUT 1 +#define LIN_OUT 0 +#define LIN_OUT8 0 +#define OCTAVE 0 +#define OCT_NORM 0 + +#define BINS 128 + +#include + +void aquire_data() { + noInterrupts(); + + 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 + } + + interrupts(); +} + +void crunch_data() { + fht_window(); + fht_reorder(); + fht_run(); + //fht_mag_octave(); + fht_mag_log(); +} + +void setup() { + + Serial.begin(115200); + + 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 + +} + +char buf[2550] = ""; + +void loop() { + aquire_data(); + crunch_data(); + + for (int i = 0; i < BINS; i++) { + Serial.print(fht_log_out[i]); + Serial.print(' '); + } + + Serial.print('\n'); + + delay(10000); +} + -- cgit v1.2.3