Previous in Forum: Cheap Data Acquisition Card and Software   Next in Forum: max current of capacitor
Close
Close
Close
12 comments
Rate Comments: Nested
Active Contributor

Join Date: Jul 2008
Posts: 10

adconvert pic

09/02/2008 9:28 AM

hi all,
in need some hope(oriontatin) in my application.
my application consist in;
i have 3 analog input (3 sinusoidal tensions),then i neeed a/d converter
an0,an1,an3 (10bit conversion) and the 3 result of conversion will be used in calcul(var =fonction(read(1),read(2),read(3...) fonction is(arctan..) )
i use the pic 18f458(with picc compiler) and i want to obtain a hightspeed intern (40MHZ)
,for this i have used 10MHZ with pll enabled

my progam;
#include<18f458.h>
#device adc=10
#fuses hs, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay (clock=40000000)
double result;
float v1,v2,v3;

void main(void)
{
ld:
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32); // utilisation de l'horloge interne pour l'ADC
set_adc_channel(0); // Lecture sur le canal 0 du port
result=(double)(read_adc());
v1 = ( 5.0 * result ) / 1024;
set_adc_channel(1); // Lecture sur le canal 1 du portA
delay_us(10);
result=(double)(read_adc());
v2 = (5.01 * result) / 1024;
delay_us(10);
result=(double)(read_adc());
v3 = (5.01 * result) / 1024;
goto ld;
}


my questions;
1.how much time to the ad convertion (convert 3analog input to digital)
2.what is the faster a/d convertion 8bit or 10bit.and how much for difference.
3.what the declaration can i use to obtain max internal execution speed (40Mhz)(i use 10MHZ with pll enabled)
(1).#fuses hs, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay (clock=40000000)

or:
(2).#fuses hs, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay (clock=10000000)
4.is it necessary to do delay time; (delay_us(10);)

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Anonymous Poster
#1

Re: adconvert pic

09/02/2008 11:46 PM

I can't answer all of your questions as I'm not familiar with their compiler, but the maximum conversion rate of the internal ADC will be about 52kHz (the manual says minimum Tad is 1.6us and needs 12 cycles per ADC). There doesn't seem to be an 8 bit mode, if there was I doubt it would be much faster than 10 bit.

Why do you use floating point in your calculations? The PIC doesn't have a FPU so that will eat up a fair bit of CPU. But that might not matter if the ADC is the only thing you're doing. Personally though I would try to do the scaling calculation using integer math only. The PIC does have an 8*8 multiplier. Try to use multiplies rather than divides and it will be faster.

Register to Reply
Active Contributor

Join Date: Jul 2008
Posts: 10
#2

Re: adconvert pic

09/03/2008 9:50 AM

hi all,thank you Guest for your anser. the maximum conversion rate of adc=52khz means(19.2us) for all conversion total=19.2*3=57.6us. isit necessary to add [delay_us(10);]??

the total=57.6+10*3=87.3us

*if i use adc=8bit theconvertion will be faster then 10bit???

* so i will use integer variable ;i supose 1.5or 0.23 is integer ,is this right ,what is thedifference between integer and float ?

*but what is the manner to declare in the program to use the 8*8 multiplier??(is it otomaticaly)?

*whats the compiler can you suggere to me to use .

hi thank you

best regards

Register to Reply
Power-User

Join Date: Jun 2008
Location: TR
Posts: 142
Good Answers: 1
#3
In reply to #2

Re: adconvert pic

09/06/2008 12:57 PM

hi kaci,

The conversion time of AD converter of pic devices is 1,6 μsec per bit minimally And they waist 12 ad-clock per conversion, means 20μseconds per conversion.

You must add -at least- 13 μsec for acquisition per channel, means you must supply at least 33 μseconds per channel. This is the maximum conversion speed u can get.

(with a 40 Mhz xtal u must configure ad clock (TAD) for 64Tosc)

If you did use OPAs for signal conditioning, u must use more time (say 1 msec) for acquisition time.

If you did use analog switches for channel selection then u must use more time (say 10 msec) for acquisition time.

"*if i use adc=8bit theconvertion will be faster then 10bit???"

No. Why u can not select for a 8 bit or 10 bit conversion. On the other hand u could use the high byte of result configuring adresult left justified.

"* so i will use integer variable ;i supose 1.5or 0.23 is integer ,is this right ,what is thedifference between integer and float ? "

1.5 or 0.23 are float numbers not integers! If u will use integer math then u can multiply these values with "10" (or "100") initially, do the math with 15 or 23 and then divide the result with "100" (or 10000), 2 or 4 times dividing the result with "10".

Integer numbers are always "1" or "multiple of 1", like numbers -1, -10 (signed), 1,2,5,10 (unsigned) etc. Floats are numbers those have fractions of "1", like nubers -1.5, -0.23, 1.5, 0.23, 10.32 etc.

" *but what is the manner to declare in the program to use the 8*8 multiplier??(is it otomaticaly)? "

It is automatically done by hardware multiplier provided that u use MULxx command.

" *whats the compiler can you suggere to me to use . "

No problem with picc i've generally used assembler though.

good luck

Register to Reply
Active Contributor

Join Date: Jul 2008
Posts: 10
#4

Re: adconvert pic

09/08/2008 12:29 PM

hi all,

thanks feridun for your answer.but can you explain me more some things you have said;

**(with a 40 Mhz xtal u must configure ad clock (TAD) for 64Tosc)**

-with ccs ,whats the manner to declare (ad clock (TAD) for 64Tosc)???.

i work with pic 18f458 and iwant that the pic operates at 40MHZ .In pic 18f458 datasheet ,it is realisable only when use 10mhz with PLL actived.(-with ccs ,whats the manner to declare? ??).

Register to Reply
Active Contributor

Join Date: Jul 2008
Posts: 10
#5
In reply to #4

Re: adconvert pic

09/08/2008 12:43 PM

**It is automatically done by hardware multiplier provided that u use MULxx command.**

-can you explain me more

thanks

Register to Reply
Power-User

Join Date: Jun 2008
Location: TR
Posts: 142
Good Answers: 1
#6
In reply to #4

Re: adconvert pic

09/08/2008 8:14 PM

hello again kaci,

It is the same what i've said about xtal using 10Mhz xtal with PLL. Means u will use a 40Mhz clock (If u don't use PLL then use 40Mhz X-tal directly instead of 10Mhz , both the same but more EMI with 40Mhz Xtal).

There is a register called ADCON0 with f458 you know. Bits 7 and 6 of this register are used with the purpose of adjusting AD clock (FAD = 1/TAD).

If bits <7,6> = <1,0> then ADclock (FAD) = Fosc /64 → TAD = 64*Tosc.

Now the 2nd question.

There are two commands in the instruction set for 8*8 (hardware) multiply:

MULLW (Multiply Literal with W register) and MULWF ( Multiply W reg with F reg).

I've used MULxx for both of these two.

Of course these are the instructions for assembler but when u write " 5 * result " that means that u have already employed MULLW (i'm assuming result is also in W reg).

Using PICC do think about the limitations of device, that has no math processor as that of a pentium except a 8bit by 8bit multiplier.

i hope i can explain

regards

Register to Reply
Power-User

Join Date: Jun 2008
Location: TR
Posts: 142
Good Answers: 1
#7
In reply to #6

Re: adconvert pic

09/08/2008 9:08 PM

me pardon, i've had jumped...

" with ccs ,whats the manner to declare (ad clock (TAD) for 64Tosc)???."

You 've already done it for 32Tosc: " setup_adc(ADC_CLOCK_DIV_32); "

Change it as " setup_adc(ADC_CLOCK_DIV_64); "

regards

Register to Reply
Active Contributor

Join Date: Jul 2008
Posts: 10
#8

Re: adconvert pic

09/14/2008 11:32 AM

hi all,

thanks feridun for your answers ,you have take me important informations (notes),so:

*for 40Mhz X-tal , (FAD) = Fosc /64 → TAD =1.6us =64*Tosc

*but for 10Mhz X-tal. ,with PLL actived ;

(1). Tosc =???

(2).pratiquelly (in the program pic c) , what is the difference between oscillator 10Mhz X-tal. ,with PLL actived and oscillator 10Mhz X-tal. ,with PLL not actived .???

(3).you have said : (If u don't use PLL then use 40Mhz X-tal directly instead of 10Mhz , both the same but more EMI with 40Mhz Xtal).

EMI ??
THANKS

Register to Reply
Power-User

Join Date: Jun 2008
Location: TR
Posts: 142
Good Answers: 1
#9
In reply to #8

Re: adconvert pic

09/14/2008 12:31 PM

Hi kaci,

1-Both are the same if u are used 40Mhz X-tal without PLL or 10Mhz X-tal with PLL, i mean Fosc = 40Mhz and the FAD = Fosc / 64 in both manner.

2- You already have setup for PLL (and 10Mhz X-tal) with this line:

" #fuses hs, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP "

(if you select " hs " for oscillator option, the PLL activated automatically).

3- EMI is short for Electro Magnetic Interference (and must be avoided ). This means that it is better to use PLL.

Register to Reply
Anonymous Poster
#10

Re: adconvert pic

09/15/2008 9:48 AM

hi all,

thanks feridun .

Ok, for 10Mhz X-tal with PLL active,i will declare ;

#fuses hs, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP

#use delay (clock=40000000)

* what does means the two words "PUT" and "BROWNOUT"???

ok, in the " hs " mode(type) the PLL is activated automatically.

if we refere to the pic18f458 datasheet , the X-tal =4Mhz -10Mhz when using PLL.

** if i use X-tal >10Mhz(example 40Mhz) ,what mode i will use??? hs???

**in the "hs" mode, is the PLL automatically activated for some value only??

thanks .

Register to Reply
Power-User

Join Date: Jun 2008
Location: TR
Posts: 142
Good Answers: 1
#12
In reply to #10

Re: adconvert pic

09/15/2008 3:04 PM

Dear kaci,

PUT is short for Power Up Timer. (You've had activated it, this is OK).

BROWNOUT is the supply voltage dedector that resets device if supply gets lower than approx 2..4V (You've also had activated it and it's better to disable it with "NOBROWNOUT").

You can use "hs" (PLL) mode with any X-tal between 4 - 10 Mhz. PLL makes the clock 4*fXtal so if u want 40Mhz then u must use a 10Mhz Xtal. If u would use a 4Mhz Xtal then the clock would be 16 MHz and you sets up the oscillator still as "hs".

PLL activation is not depends on Xtal value but setup.

I think you've pasted the program from somewhere? Don't be lazy to read the datasheet carefully, you will find many info about your questions and more...

Okay?

Register to Reply
Active Contributor

Join Date: Jul 2008
Posts: 10
#11

Re: adconvert pic

09/15/2008 10:00 AM

hi all ;

excuse me i have missed

the second guest its me ( kaci)

thanks

Register to Reply
Register to Reply 12 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (2); feridun (5); kaci (5)

Previous in Forum: Cheap Data Acquisition Card and Software   Next in Forum: max current of capacitor

Advertisement