|
|
View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
How to turn on the fast adc of 30F5015 |
Posted: Wed Jun 12, 2013 8:07 am |
|
|
Greetings! The datasheet of 30F5015 says it has fast adc! So I want to use it!
I wrote a simple program:
Code: |
#include <30F5015.h>
#include <math.h>
#FUSES HS2_PLL16,NOWDT,NOPUT
#use delay(clock=80 000 000)
void main()
{
int voltValue;
setup_adc_ports( sAN0 );
setup_adc(ADC_CLOCK);
set_adc_channel( 0 );
while(1)
{
voltValue=read_adc();
}
}
|
In this case it takes above 2ms to adc to be done! How to turn on the fast adc? I tried to add #device adc=10 in case I`m not using 10 bit adc mode - no effect!
Help! |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Wed Jun 12, 2013 8:10 am |
|
|
The speed of the ADC will be determined by ADC_CLOCK. What value do you have? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jun 12, 2013 8:58 am |
|
|
Stoyanof,
By now you should know always to post your compiler version number! Especially with the new v5 compiler out now. Knowing CCS from the previous major releases we can expect a lot of strange bugs for the next half year.
Code: | #use delay(clock=80 000 000) | What kind of fancy notation is this? No programming language I've ever seen allows you to have spaces inside a number!
Alternatives: Code: | #use delay(clock=80000000)
#use delay(clock=80,000000MHz)
#use delay(clock=80MHZ)
#use delay(clock=80M) |
|
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Wed Jun 12, 2013 10:42 pm |
|
|
Excuse me! I`m using CCS v4.134. I have 10MHz quartz! I`m using HS2_PPL16. This means 80M delay clock.
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Thu Jun 13, 2013 2:33 am |
|
|
First as has already been pointed out, 80 000 000, is not really a legitimate way of expressing 80million. The compiler does actually accept it, but many others don't. A quick test, inputting this into four other compilers, had three treating it as 80 only, and throwing away everything after the space. It is bad practice. If you want to split the number, use the standard separator ','. 80,000,000 (or '.', if your decimal separator is '.').
However the big problem is your setup of the ADC. You have selected 'ADC_CLOCK'.
Now, you can't just select a clock, you also have to select a divisor. For 80Mhz (20MIPS), at 500Ms/sec, you need ADC_CLOCK_DIV_4 (example 20-1 for how to calculate this).
You can't go faster than this, without changing to sampling two channels (even if the two channels are the same input).
Look at table 20-1 in the data sheet. Note how everything above 500Ksps, requires external Vref, and use of the channel multiplexing. As currently setup, you are clocking the ADC above the maximum supported for any mode. Also note how low the source impedance has to go for the higher rates....
Then, as shown, you read the number an immediately loop to read again. You have to allow Tacq, between samples. Only a moment, but it is needed. You can program the ADC to automatically add this (ADC_TAD_MUL_2 is the minimum), but it is needed. If you don't use this, you need to ensure your code pauses for the same sort of time period.
Now, this then gives a sample rate of 360K/second.
Code: |
#include <30F5015.h>
#include <math.h>
#FUSES HS2_PLL16,NOWDT,NOPUT
#use delay(clock=80MHz)
void main(void)
{
int voltValue;
setup_adc_ports( sAN0 );
setup_adc(ADC_CLOCK_DIV_4 | ADC_TAD_MUL_2);
set_adc_channel( 0 );
while(1)
{
voltValue=read_adc();
}
}
|
Best Wishes |
|
|
|
|
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
|