CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

FAST A/D CONVERSION

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
levettp



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

FAST A/D CONVERSION
PostPosted: Fri Oct 22, 2010 2:43 am     Reply with quote

I'm using a 16F887 with 20MHz crystal in an application where I need maximum A/D conversion sampling rate for approximately 30 micro seconds. After sampling I then process the readings for which processing time is not of importance.

My code is as follows (I use pin AN1 for A/D):
Code:

void main()
{
   unsigned int16 Vd0, Vd1, Vd2, Vd3, Vd4, Vd5;

   setup_port_a( sAN1 );
   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(1);
   delay_ms(250);

do {
   Vd0=read_adc();
   Vd1=read_adc();
   Vd2=read_adc(); 
   Vd3=read_adc();
   Vd4=read_adc();
   Vd5=read_adc();

   //I then process Vd0 to Vd5
} while(true);

}

Any advice on how I can speed up the sampling rate will be greatly appreciated.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Oct 22, 2010 9:18 am     Reply with quote

You must carefully read the section in the PIC Datasheet covering the A/D's conversion times.

There's input capacitance and then the max conversion rate to contend with.

Your 30uS conversion time comes to very roughly 33Ks/s (rounding down). Will your PIC do that?

(All PIC's have various rates of conversion. I didn't look at the datasheet for your particular PIC, but I have run the game of running a PIC ADC near max in the past)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Fri Oct 22, 2010 2:36 pm     Reply with quote

In fact, what you show won't work, since the adc capacitor needs to recharge between readings. This is the '10uSec', needed on most of the older chips after you select a channel, and the same time is needed between each reading and the next, or what you read won't reflect the external voltage at all. On your chip, the time needed for this, is 5uSec.

For the 16F887, with a 20Mhz crystal, the fastest ADC clock you can use, is Fosc/32, giving 1.6uSec Tad. The actual reading takes 11 cycles of this (17.6uSec), so the maximum repeated sample rate (for 10bit accuracy) is (17.6+5 = 22.6uSec).

However, unfortunately, the adc reading is stored as 8 bits in one register, and 2 more bits rather inconveniently placed in another register, requiring several instructions to re-assemble to get the 10bit value, significantly slowing this. _If_ you can accept 8bit values, the reading only takes a couple of instructions. At this lower rate, you can also fractionally reduce the charging time. So:

1) Select the adc clock as Fosc/32
2) Add 4uSec delays between each reading.
3) Set the adc to return 8 bit values (ADC=8 in the device statement).

This would then give the best achievable, which will about 22uSec/sample.

Best Wishes
levettp



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

PostPosted: Sat Oct 23, 2010 4:48 am     Reply with quote

Thank you bkamen and Ttelmah.

@Ttelmah: I need at least 3 readings during the 30 micro seconds sampling period. Further, 8 bit resolution will unfortunately not be adequate accuracy.

It appears that I only have the following options:

i) Run 3 x PIC16F887's with a synchronisation signal between them and let each do 1 A/D conversion 10 micro seconds appart.

OR

ii) Change to a faster chip e.g. a dsPIC ... never used these chips before so not sure about their performance.

OR

iii) Try to find a PIC that perhaps have separate registers in which A/D conversion results are stored.

Which route will you suggest?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 23, 2010 6:40 am     Reply with quote

A 16-Bit PIC would provide a considerably higher performance, also in data processing. But there are also 8-Bit PICs with fast ADC, e.g. 18F4331.
levettp



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

PostPosted: Sun Oct 24, 2010 9:22 am     Reply with quote

Thank you for everyones inputs.

I'm going the route of using a PC sound card for A/D conversion.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Oct 24, 2010 2:58 pm     Reply with quote

Um.
Most sound cards on normal PC's, won't do the sample rates you are requiring. Fastest sampling, is normally 44.1KHz, or 48KHz, (though two channels at this speed, which might _just_ be stretched to do what you want), and the ADC's on a PC sound card, are audio ADC's, which doesn't imply great linearity. The 'resolution' may be many bits, but you need to study about the difference between these and instrumentation ADC's. Remember also the frequency response limits of the circuitry feeding the on-board chip...
Many people have used sound card ADC's for things like simple oscilloscopes, but the results are usually very poor, and will vary from machine to machine....
Get a proprietary PC analog I/O board, if you want results that are worth having.

Best Wishes
levettp



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

dsPIC30F2020
PostPosted: Thu Nov 11, 2010 1:34 am     Reply with quote

I got the sound card running but now I want to move to faster sampling.

dsPIC30F2020 can apparently do 2MS/s but I scanned this message board and it appears that 30F2020.h is either not properly completed or have errors.

Does anyone use this type of dsPIC successfully with CCS or is it better to use another compiler?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Nov 11, 2010 7:17 am     Reply with quote

the ad 8371 can do this externally
i've done it with an 18F4620 @ 16 mhz
in response to an int trigger on B
BUT had to dedicate the entire D port and E port 3 lines
to get 64 reading bursts into an array - with a reading every
10 usec -

ultimately memory to hold the results is an issue in the pic u know
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Thu Nov 11, 2010 1:18 pm     Reply with quote

you could use an external adc, if you can get it with serial interface (SPI/Microwire) probably easier. Linear Tech has some pretty nice ones (e.g. LTC2362).

A few things to consider:
  • Sample Rate: > 100ksps?
  • Interface: Serial?
  • Resolution: > 8-bits?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group