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 support@ccsinfo.com

Sampling Frequency for PIC18f4620

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



Joined: 04 Feb 2014
Posts: 28
Location: Malaysia

View user's profile Send private message AIM Address

Sampling Frequency for PIC18f4620
PostPosted: Wed Apr 16, 2014 9:12 am     Reply with quote

Hi master,

Anyone can teach me how to calculate sampling frequency????

I akready tried to search the sampling frequency of PIC 18f4620 in datasheet.
What i found in datasheet is 100k sample in 1 second.
So, i calculated it as 100k/ (50hz) frequency of msia=2000
but after i try 2000 sample the program hang??? Crying or Very sad Crying or Very sad Crying or Very sad
So seek anyone for help!!!!!


Regards,
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Sampling Frequency for PIC18f420
PostPosted: Wed Apr 16, 2014 10:02 am     Reply with quote

low wrote:

Anyone can teach me how to calculate sampling frequency????


The PIC ADCs don't sample at regular intervals. There is no "sampling frequency". They sample when the code tells them to sample, and the time they take to convert is dependant on the clock frequency.

There's also the problem of acquisition time - Tacq, the time taken for the ADC input to accurately represent the applied voltage. That varies a lot between PICs, with newer ones being faster. Its can be a big problem where the ADC is used to sample several, widely varying, signals. It takes a relatively long time (probably about 12us with the 18F4620 if memory serves) for the AC input to settle when changing from one signal to another. Newer PICs can do this in hardware, older ones may not and rely on software to add the required delays. When sampling one continuously varying signal it may be possible to reduce the delay as the signal doesn't change all that much from one sample to the next. This allows may allow single channel to be sampled at a higher rate.

Through code, its possible to use a timer to trigger conversions at regular intervals. There is an ADC DONE interrupt that can be used to read the result when the conversion finishes. The ISR must read and do whatever it has to to the result, e.g. store it, before the next conversion finishes.

With the time taken to enter and leave an ISR, and the ISR code, that limits the rate at which conversions can be triggered to a lot less than the ADC could run if it were to do back-to-back conversions. You're NOT going to get 100k samples per second on most PICs, including your 18f4620. I assume dsPICs, which are optimised for DSP type applications have better ADC sampling arrangements than most other, general purpose, PICs.


Last edited by RF_Developer on Wed Apr 16, 2014 10:12 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 10:07 am     Reply with quote

Sampling what????.
ADC?.

If so, it can't (quite) do 100K samples per second.

The sequence is Tacq (acquisition time), followed by 11*Tad. Tacq is 2.5uSec (if your source impedance meets the spec). Tad minimum is 0.7uSec, so the fastest sampling is 11*0.7+2.5uSec 10.2uSec. 98K, and this is the absolute fastest. Unless your clock rate is specially chosen, you are unlikely to be able to get a Tad of 0.7uSec (more probably perhaps 1uSec), so won''t get to this speed....

However you then have 'what you do with the data'. It takes time to write to an array for example. Typically probably 10 instructions to read a 10bit value from the ADC (it has to be assembled from two registers, with rotations), and then perhaps another dozen to write a value to a location in an array. So you probably won't get close to 100K, unless you switch to a PIC with DMA. Then though you have the amount of RAM. 3986 bytes, so just over 1900 10bit values can be stored before you run out of memory....
Probably why the program hangs.
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