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

ADC of PIC18F8720

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







ADC of PIC18F8720
PostPosted: Wed Mar 16, 2005 12:13 pm     Reply with quote

Hi,
I have a doubt about the ADC of a PIC18F8720. There are a little offset between the real signal and the value measured, for example if the voltage at input is 1.414V, the measure is 1.504. The precision is 1/2 bit = 4/1024/2=2mV.
The configuration is: Vref+ = external ref = 4V (from a zener); Vref- = internal ref = VSS. Also, the micro have VDD = 5V, but the ICD2 only delivery 4.74V. If I change the configuration and the references are internal (VSS and VDD) the results are worse.

My code is:
Code:
#define ANALOG_AN0_TO_AN5   0x09
#define VSS_VDD         0x00
#define VSS_VREF         0x10
#define ADC_CLOCK_DIV_32   0x102

#include <18f8720.h>
#device *=16 ADC=10
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#ID CHECKSUM
#ZERO_RAM
#use DELAY(CLOCK=20000000)
#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
void main (void){
   int16 val;
   �
   set_tris_a(0xFF);
   setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VREF);
//   setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VDD);
   setup_adc( ADC_CLOCK_DIV_32 );
   �
   while(1){
      set_adc_channel( 4 );
      delay_ms(10);
      val=read_adc();
      delay_ms(10);
      printf(displays,"%Lx",val);
      printf("%2.3f",(float)val*3.99/1024);
//      printf("%2.3f",(float)val*4.74/1024);

   }
}


Some idea???
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

printf("%2.3f",(float)val*3.99/1024);
PostPosted: Wed Mar 16, 2005 1:15 pm     Reply with quote

There have been some post earlier that claim problems with floating points with prontf(); look in some recent posts.

http://www.ccsinfo.com/forum/viewtopic.php?t=22210

If this is how you are reading your answer, beware.
_________________
-Matt
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 4:22 pm     Reply with quote

What is the int16 val when you have 1.414v input? Is it what you expect? With a 4v reference, I think you should read 362. I guess I don't exactly understand why your resolution ("precision") isn't 4/1024 or 3.9mV.

Verify this before you worry about the (potential) printf/float issue....
rafa2
Guest







PostPosted: Wed Mar 16, 2005 4:29 pm     Reply with quote

I think that the problem is the converter. In the code, I can see the measure directly from a converter (printf("%Lx",val); ), and for 1.4V it should be: 1.414*1023/4=361=169h, and I read 182h.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 4:40 pm     Reply with quote

Quote:
external ref = 4V (from a zener)


You are trying to get 4 digits of precision in your result, but your
posted zener voltage only has one digit.

Also if I go to http://www.digikey.com and type in Zener Diode
and look at the available voltages, I see 3.9v and 4.3v, but no 4.0v.
In addition to that problem, the typical tolerance is 5%.

What is your true Vref voltage, as measured with a voltmeter ?
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 4:41 pm     Reply with quote

Good info... now you might look at the input and your supplies with a 'scope to make sure they're steady and noise free, and make sure you're driving the input with an impedance that's < 2.5k ohms...

Adding:

PCM is probably on it... with a 3.9V zener you'll read 371, if it's exactly 3.9V... the tolerance is probably the rest of the error.....


Last edited by bluetooth on Wed Mar 16, 2005 4:47 pm; edited 1 time in total
rafa2
Guest







PostPosted: Wed Mar 16, 2005 4:46 pm     Reply with quote

Perdon, it is a regulator not a zener, with a voltmeter 3.99V.
rafa2
Guest







PostPosted: Wed Mar 16, 2005 4:50 pm     Reply with quote

And the input have a op-amp...
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 5:01 pm     Reply with quote

Rafa2:

You're killing all the theories!!!!!

OK - silly question, but are AVss and AVdd hooked up via a low impedance path? And are all signals stable and quiet? It starts to sound more like a power/ground problem....

Happy hunting....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 5:09 pm     Reply with quote

What's your version of the compiler ?

Post the portion of the .LST file that shows the ASM code for the lines
given below. It's possible that the ASM code for the A/D functions is
incorrect. If you post it, maybe we can see the problem.

set_tris_a(0xFF);
setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VREF);
setup_adc( ADC_CLOCK_DIV_32 );

while(1){
set_adc_channel( 4 );
delay_ms(10);
val=read_adc();
rafa2
Guest







PostPosted: Wed Mar 16, 2005 5:23 pm     Reply with quote

I am sorry for your theories, bluetooth... Embarassed
About the power supply, unless the ICD2 only delivery 4.7V

The version of the compiler is 3.180

LST:
Code:
....................       set_tris_c(0x10); 
0702:  MOVLW  10
0704:  MOVWF  F94
....................       set_tris_a(0xFF);   
0706:  MOVLW  FF
0708:  MOVWF  F92
....................    setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VREF); 
070A:  MOVF   FC1,W
070C:  ANDLW  C0
070E:  IORLW  19
0710:  MOVWF  FC1
.................... //   setup_port_a( ANALOG_AN0_TO_AN5 | VSS_VDD); 
....................    setup_adc( ADC_CLOCK_DIV_32 ); 
0712:  BCF    FC0.0
0714:  BSF    FC0.1
0716:  BCF    FC0.2
0718:  BSF    FC0.7
071A:  BSF    FC2.0
.................... //   ADCON0 = 0x11; // set up adc, timer/32, and adc on   
.................... //   ADCON1 = 0x00; // right justified result, a0,1,4 are analog, a2,3 are references, e0,e1,e2 are digital   
.................... //   ADCON2 = 0x82; 
....................     
....................    set_adc_channel( 4 ); 
071C:  MOVLW  10
071E:  MOVWF  01
0720:  MOVF   FC2,W
0722:  ANDLW  C3
0724:  IORWF  01,W
0726:  MOVWF  FC2
....................    LCD_E = 1;                  // enable LCD   
0728:  BSF    F82.2
....................    disp_lcd = TRUE; 
072A:  BSF    05.0
....................    disp_serial = false;   
072C:  BCF    05.1
....................    init_lcd(); 
072E:  BRA    007C
....................    while(1){ 
....................       set_adc_channel( 4 ); 
0730:  MOVLW  10
0732:  MOVWF  01
0734:  MOVF   FC2,W
0736:  ANDLW  C3
0738:  IORWF  01,W
073A:  MOVWF  FC2
....................       delay_ms(10); 
073C:  MOVLW  0A
073E:  MOVWF  28
0740:  RCALL  0004
....................       val=read_adc(); 
0742:  BSF    FC2.1
0744:  BTFSC  FC2.1
0746:  BRA    0744
0748:  MOVFF  FC3,06
074C:  MOVFF  FC4,07
....................       delay_ms(10); 
0750:  MOVLW  0A
0752:  MOVWF  28
0754:  RCALL  0004


Rafa
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 5:36 pm     Reply with quote

Rafa2:

Looks like those setups are good - and since you're using an external VREF, the ICD power shouldn't matter.... so, back to my original questions: are AVss and AVdd connected via low impedance paths, and are all the signals stable and quiet when looked at on a 'scope?
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