Having spent most of the evening and a very restless night thinking about how to optimise my A to D speed on the UNO32 board, beyond the standard 1MHz sample rate, I`v finally come up A solution.
in addition to yesterdays Blog using TRISE and PORTE to address the I/O directly, you can also use LATE instead of PORTE, and that`s also perfectly acceptable in the IDE.
I`m not sure if it makes it any faster or not, but it Does work.
anyway, to get real Speed from the boards A to D convertor you need to go into the Core code, my pathway is like this:
Desktop\UNO32\hardware\pic32\cores\pic32 then look for a file called: wiring_analog.C
make a Backup copy of this file and hide it somewhere, then Open the original file into Notepad.
scroll about half way down until you see a line that says:
//Delay for a bit
delayMicroseconds(2);
the put a `//` in front of the delay to comment it out, and put this line under it instead: asm("nop\n nop\n nop\n nop\n nop\n");
this way you`re using NOPs instead of a 2uS delay, the lowest Delay is 1uS (1MHz), but using NOP`s you actually knock out single clock cycles, and at 80MHz each NOP is worth 12nS delay (Much smaller!).
I`m using 5 of them, so that should be 60nS delay, this is the Smallest (shortest) delay you can possibly use and still have your A to D work, I added them one by one until it fired up, 5 seemed to be the magic number
now Just above that original Delay line, look where it says: AD1CON3 = 0x0002; //Tad = internal 6 Tpb
this sets the prescaller for the conversion,set 0x0002 to 0x0001 instead.
this divides the clock by 2 instead of 4.
save the edited Notepad file, and then upload this massive chunk of code to your UNO32:
void setup (void) {
TRISE =B00000000;
}
void loop() {
LATE = (analogRead(0)>>1);
}
If you have a D to A built as shown a few Blogs ago, with a little audio amp, and long-wire antenna (capacitor coupled), yo might be able to pick up radio stations! I can get BBC Radio4 (198KHz) very well and can understand it word for word!
it`s not Hi-Fi quality at all, but perefctly readable, and there`s nothing really Radio-ish involved, it`s a purely Digital "radio".
I have no idea what the sample rate is at now by doing the above, but I would Guess it`s at least 4x faster, I cannot confirm this though as i`m totally out of desk space to get my Scope and Sig-gen out to try it at the moment.
I`m sure it can be optimised some more, perhaps by disabling the multiplexer for the analog pins and reading just one, using System variables like: ADC1BUF0 into LATE instead of using analogRead(0) which would probably need a lookup table, and by parsing the High and Low order data directly in the wiring library rather than using >>1; in the program.
I don`t know what I`m going to Do with it exactly yet, but it`s been loads of Fun exploring the code and getting down and dirty with some Metal
if anyone Can replicate this and confirm what the Actual A to D speed is afterwards, that would be really cool! and if it doesn`t work 1`st time add another NOP to the chain, boards and conditions may differ slighly.
also, if you Break it, use your back-up again... you Did make a the back-up didn`t you?
have Fun!
Top Comments