Created Fri, 27 May 2011 10:14:30 +0000 by Lechapelain
Fri, 27 May 2011 10:14:30 +0000
Hi,
In order to record images with arduino (by using PAL system) from an analog camera I need to call Analog Read function. A PAL line time duration is 52 micro s. How long does take the function Analog Read on your 80MHz ChipKit ? I need less than few micro s.
Thanks !
Py
Sat, 28 May 2011 14:58:14 +0000
At the moment it is the same speed as the Arduino. THis is one of the areas that needs some more work to get it sped up. The code is in arduino_analog.c, there is a delay_ms() function. You can play with that number and make it smaller. we have not had time to verify exactly what speed it can run at.
let me know any progress you make on this
Mark
Sun, 29 May 2011 10:33:24 +0000
Thanks for the answer, I'll try some tests !
Sun, 05 Jun 2011 08:32:39 +0000
Hi Mark, it's Phil, that dragon guy. :)
Not sure if you've been keeping abreast of the comments following the initial Hack a Day review, but the analog speed has been a topic of discussion. This includes something of a bug fix to wiring_analog.c allowing high speed sampling. Old code:
delayMicroseconds(99);
while ( ! mAD1GetIntFlag() ) { ... }
analogValue = ReadADC10(0);
mAD1ClearIntFlag();
Changed to:
delayMicroseconds(2);
mAD1ClearIntFlag();
while ( ! mAD1GetIntFlag() ) { ... }
analogValue = ReadADC10(0);
The 2 microsecond figure (ADC settling time) came from one of the Microchip datasheets...I forget exactly which one, had to dig a little to turn up this info, but it's definitely a "from the source" figure and not just empirical. Clearing the interrupt flag before the read (rather than after) turns out to be important for tight sampling loops across multiple ADC inputs, otherwise the value returned still relates to the last pin read, not the current one.
There's still the issue of whether this function should run at full tilt on the PIC32 or at Arduino-like speeds. A reasonably good case could be made for either behavior, and I understand the choice, but this does seem to negate much of the boards' performance benefit and a potentially distinguishing feature vs. a stock Arduino. If it's put to a vote I'd opt for the faster behavior. :D
Sun, 05 Jun 2011 13:50:18 +0000
Phil
Thanks for the update, I will get this in the code. Can you provide me with the link from where this came from so I can give proper credit.
Mark
Tue, 07 Jun 2011 06:32:48 +0000
Hey Mark,
Not sure which link you mean. If you're referring to the fix, I came up with that over the course of the discussion on Hack a Day (sorry, can't include link as a new user, it says my post "looks too spammy").
If you mean the datasheet link (for the 2 uS figure), that would be Microchip document DS61143G, "PIC32MX3XX/4XX Family Data Sheet," footnote under Table 29-36.
Tue, 07 Jun 2011 16:23:20 +0000
No doubt some code depends on slow ADC timing, but in my opinion, when you buy a faster computer, you should expect code to run faster. At the very least, there should be some switch setting to enable the faster ADC speed.
If I wanted an exact Arduino clone with all of the original limitations, I would have bought one, there are many of those... The Uno32 is different and I'd think Microchip would want to show off their hardware to best advantage.
Tue, 07 Jun 2011 22:31:00 +0000
I might also note that the PIC32MX3xx/4xx data sheet at http://ww1.microchip.com/downloads/en/DeviceDoc/61143H.pdf shows in Section 22.0 10-bit Analog-to-Digital Converter: "Up to 1000 kilo samples per second (ksps) conversion speed" so it would be nice to see an example of how to achieve that rate (1 sample every microsecond).
I speculate that the 2 us delay in the code example above may be intended for settling with higher input impedance sources, or after switching between ADC channels (?)
Mon, 21 Nov 2011 08:12:54 +0000
i really need a fast analog read so hopefully there has been some progress on this. also i can not find the referenced code hack in wiring_analog.c my IDE download has three copies of the file but nothing like this in any of them. what am i missing?
any updates on improved analog read?
Fri, 10 Feb 2012 20:49:03 +0000
Hello Spencoid,
If you download the newest version of the MPIDE the wiring_analog.c has already been modified to reflect the delay change in analog read. It is found in hardware/pic32/cores/pic32 and in the analogRead function.
Best Regards, Ryan