Hello Amrish, On Mon, 24 Nov 2008 00:54:37 +1300, apptech wrote: > We are using the following code to read the adc value from the PIC using > > Internal clock frequency. > > for(i=0;i<50000;i++) > { > a = read_adc(); > printf("%lu",a); > } > > The above code snippet takes > 200s to execute >and I am unable to acheive > the sampling rate of around 10,000 samples/s. No big surprise there, allthough it is a bit hard to judge without seeing all the code, I am pretty sure the read_adc() and even more the printf() functions takes WAY to much instruction cycles to get 10,000 samples/sec. To achieve that, you would need 1 ADC conversion every 100 microseconds. The ADC can probably do that, depending on clock-speed and settings for your ADC aquisition and bit-sampling timing. I assume the read_adc() is some (Microchip ?) library function that starts a conversion and then does a busy-wait for completion of the conversion. The busy-wait is wasting cycles in that case, that could be used to process the (previous) sample. >Is this the right way to > sample analog signals using PIC? If you leave out the printf(), perhaps, but it is impossible to say without more details ... Assuming the printf() goes to a UART, say at 115200 baud, you almost need that 100 microseconds just to output a single character there ... You are not specifying WHICH PIC you are using either, it makes quite a difference if using a low-end PIC18 (or 16) or a much faster PIC24/32 for example ... As a reference, I have been able to do back-to-back ADC conversions in a little less than 40 microseconds per conversion with a PIC18F4520 clocked at 13.56 MHz , but just in short bursts, if you need significant processing of the data in between samples, it will be much slower ... Regards, Jan van Wijk Jan van Wijk, author of DFSee; http://www.dfsee.com ------------------------------------------------------------------------------- -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist