Having done a few blogs about A to D, D to A conversions, but focused mainly on the UNO32 board, I realised that I`v perhaps alienated a large chunk of people (very Naughty of me!), and so I`v turned my attention to the Arduino and it`s A to D audio capacities (or lack of without modification).
turns out it`s really quite simple as there`s no delay to mess about with unlike the UNO32 IDE.
for the Arduino it`s simply a case of altering the sample Prescaler, it`s default is set to 128, this is really rubbish! sorry and all that, but it is
oddly there`s nothing in the Wiring_Analog.C file to alter unlike the Unos.
for the Arduino it`s in (here`s my pathway): Desktop\arduino-0022\hardware\arduino\cores\arduino and then look for a file called "wiring.C"
again, as before Make a back-up of this file and hide it somewhere!
then open the original wiring.C file in Notepad, use full screen then scroll right the way down to the bottom, and look about a third of the way up and find:
#if defined(ADCSRA)
// set a2d prescale factor to 128
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
// XXX: this will not work properly for other clock speeds, and
// this code should use F_CPU to determine the prescale factor.
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);
this little bit of code sets your prescaler, change the last 2 lines to:
sbi(ADCSRA, ADPS2);
cbi(ADCSRA, ADPS1);
cbi(ADCSRA, ADPS0);
yeah, you turn the `s` to a `c`, then save the file. and that`s it, you now have a prescaler of only 32 (4X faster).
this will work perfectly for simple Audio work with an R2R ladder D to A convertor, I use this Huge peice of code on my Arduino Nano as a simple pass-through:
void setup() |
{
DDRD = B11111111;
}
void loop() {
PORTD = (analogRead(0)>>1);
}
digital pins D0 to D7 are used, LSB to MSB respectively.
although it is possible to take it faster, the results are likely to be flaky at best, I have yet to try this prog in ZED, where the 328p chips are running 25MHz (yes a genuine Atmel chip will go this fast, but you can forget serial coms etc...).
I`v also not tried this with PWM D to A either, in fact I`v never even tried PWM for anything yet other than servos.
also don`t panic about the fact that pins D0 and D1 (rx-tx) are used, if you built the R2R D to A with the 74HCT245 buffer chip as I did in mine a few blogs ago, the input impedance is so high, it`s completely ignored! and the fact your hitting PORT D will make no difference either, you can still upload and alter your programs via USB without having to pull 2 wires out every time
so I hope I`m forgiven now for overlooking the Arduino community, I just get a bit carried away sometimes.
(Wife`s thinking; `I wish someone Would carry him away!`)