Hi there! (this is my first post on this forum so please forgive me if I'm in the wrong section)
I'm currently working on a "module-led-strip-wall" controlled by sound. As of now I got 48ch pwm controlled with three TLC5940, an Arduino MEGA and the TLC5940 library. I'm planing on expanding the number of channels.
Everything works just fine beside one part. I need the program to run an cycle under 50 microseconds because I want to sample the sound up to 20kHz. The bad guy in this problem is the analogRead() function, it's takes about 110 microseconds which only gives me the ability to sample sound up to 9kHz
I've tried with an due which works really great, the analogRead() only take 5 microseconds! But... the library doesn't work with the due. I've tried another library ( this library Google Code Archive - Long-term storage for Google Code Project Hosting. ) but with no luck of getting the thing to work (I will try more when my exams are done).
I just want to check with you guys if you know anything better, etc. Do you know any better way on solving this?
I haven't done it myself, but I understand from the clever people here that it's possible to set the ADC up in a free-running mode where it will generate an interrupt as it completes each reading and then immediately start the next reading. If you can achieve that it would give you the maximum possible capture frequency and also leave the CPU free to do other things in the background.
(This sort of thing may well be processor-specific and I don't know whether it's possible with the processor you're using.)
I've tried adding the code you wrote but I get this error msg:
sketch_may18a.ino: In function 'void setup()':
sketch_may18a:3: error: 'sbi' was not declared in this scope
sketch_may18a:4: error: 'cbi' was not declared in this scope
Edit:
I found this in another thread
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// set prescale to 16
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
Now it works just as you said!
raschemmel:
Have you thought of using a SPI ADC ? (MCP3201)
SEE ATTACHED
Have you thought of using a I2C ADC ? (ADS1115)
SEE ATTACHED
this is above my understanding right now but I'll check up on it!
Wasting:
I've tried adding the code you wrote but I get this error msg:
sketch_may18a.ino: In function 'void setup()':
sketch_may18a:3: error: 'sbi' was not declared in this scope
sketch_may18a:4: error: 'cbi' was not declared in this scope
Oops my bad. Forgot the macro definitions but you seem to have found then elsewhere.