hi
i'm using the fht library ArduinoFHT - Open Music Labs Wiki for analysing an audio signal with my arduino mega.
in addition i'd like to analyse the signal send through a lowpass filter by using analogread().
after setting the adc to free running mode analogread() causes a crash.
setting back ADCSRA bevore analogread() dosen't help.
has anybody an idea? i don't like to have to use a second arduino only for reading the signal.
Please post your code. How are we supposed to help without it? Guess?
crash at: analogRead(A11)
if i move analogRead(A11) in front of ADCSRA = 0xe7, then the arduino crashes at ADCSRA = 0xe7.
#include <FHT.h>
void setup() {
ADCSRA = 0xe7; // set the adc to free running mode
ADMUX = 0x45; // use adc5
DIDR0 = 0x20; // turn off the digital input for adc5
}
void loop() {
sampleInput();
pinMode(A11, INPUT);
analogWrite(45,analogRead(A11));
}
void sampleInput() {
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int x=0; x<FHT_N; x++) {
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
ADMUX = 0x45; // use adc5
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[x] = k; // put real data into bins
}
sei();
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();
}
com_:
crash at: analogRead(A11)if i move analogRead(A11) in front of ADCSRA = 0xe7, then the arduino crashes at ADCSRA = 0xe7.
Could you define "crashes" for us? Did you get the Blue Screen of Death?
when it crashes the execution of the code stops. you only can push the reset button or connect the arduino via usb to the pc
Why are you trying to do an analogRead and use free-running mode? Aren't they mutually exclusive?
i do not exactly know, what the free-running mode does, but i need it for using hfl. and i'd like to read an analog signal.
when i toggle free-running mode, analogread() dosen't cause a crash, but the hfl library dosen't work correctly.
if it's mutually exclusive, is there an equivalent way to read an analog input in free-running mode?
Free running mode means the ADC is constantly taking readings, and calling an interrupt routine to handle them. Do you have such an interrupt routine?
i think this is handled by sampleInput() and not by an interrupt.
i've tried to take over some code to replace analogread(), but i read a constant 2,5V at pin 3, even if i connect it to ground or 5V.
cli(); // UDRE interrupt slows this way down on arduino1.0
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
ADMUX = 0x43; // use adc3
delayMicroseconds(200);
byte m = ADCL; // fetch adc data
byte j = ADCH;
int output = (j << 8) | m; // form into an int
sei();
no, now it works
the cable was broken
thanks for the help ![]()
The broken cable crashed the Arduino? OK.
no no
the analogread() while free-running mode crashed it. the constant 2,5V at pin 3 were caused by the broken cable. i solved the problem by replacing analogread() with the code from my last post